dragon.matrix
Class AbstractSuperSparseMatrix

java.lang.Object
  |
  +--dragon.matrix.AbstractMatrix
        |
        +--dragon.matrix.AbstractSparseMatrix
              |
              +--dragon.matrix.AbstractSuperSparseMatrix
All Implemented Interfaces:
Matrix, java.io.Serializable, SparseMatrix
Direct Known Subclasses:
DoubleSuperSparseMatrix, IntSuperSparseMatrix

public abstract class AbstractSuperSparseMatrix
extends AbstractSparseMatrix

Abstract super sparse matrix is designed for large sparse matrix which first caches data and then processes data and write data to disk when it's over flush interval

Copyright: Copyright (c) 2005

Company: IST, Drexel University

Version:
1.0
Author:
Davis Zhou
See Also:
Serialized Form

Field Summary
protected  Row[] arrCachedRow
           
protected  float[] arrRowLoadFactor
           
protected  int[] arrRowPosInCache
           
protected  long[] arrRowPosInFile
           
protected  int[] arrRowStart
           
protected  AbstractFlatSparseMatrix cacheMatrix
           
protected  int cacheSize
           
protected  int firstEmpty
           
protected  int flushInterval
           
protected  java.lang.String indexFilename
           
protected  java.io.RandomAccessFile matrix
           
protected  SparseMatrixFactory matrixFactory
           
protected  java.lang.String matrixFilename
           
protected  int totalCell
           
 
Fields inherited from class dragon.matrix.AbstractSparseMatrix
isFinalized, mergeMode, miniMode
 
Fields inherited from class dragon.matrix.AbstractMatrix
cellDataLength, columnBase, columns, rowBase, rows, transposeMatrix
 
Constructor Summary
AbstractSuperSparseMatrix(java.lang.String indexFilename, java.lang.String matrixFilename, int cellDataLength)
           
AbstractSuperSparseMatrix(java.lang.String indexFilename, java.lang.String matrixFilename, int cellDataLength, boolean mergeMode, boolean miniMode)
           
 
Method Summary
 boolean add(Cell cell)
          Add a cell to the sparse matrix.
 void close()
          Close the matrix and release all resources.
protected abstract  AbstractFlatSparseMatrix createFlatSparseMatrix(boolean mergeMode, boolean miniMode)
           
protected abstract  Row createRow(int row, int columns, byte[] data)
           
 boolean finalizeData(boolean sorting)
          Any sparse matrix has two possible modes, writing mode and reading mode.
 void flush()
          Many implementations of sparse matrix cache cells in memory.
 Cell getCell(int row, int col)
          If the specified cell doesn't exist, this method will return null.
 java.lang.String getIndexFilename()
           
 java.lang.String getMatrixFilename()
           
 Cell getNonZeroCellInRow(int row, int index)
          This method returns the index-th non-zero cell in the given column.
 int getNonZeroColumnInRow(int row, int index)
          This method returns the column index of the index-th non-zero cell in the given row.
 int[] getNonZeroColumnsInRow(int row)
          If the given row has n non-zero cells, this method returns a n-length integer array.
 int getNonZeroNum()
           
 int getNonZeroNumInRow(int row)
           
protected  Row getRow(int index)
           
 void setCache(int cacheSize)
           
 void setFlushInterval(int interval)
           
 
Methods inherited from class dragon.matrix.AbstractSparseMatrix
cosine, finalizeData, genCooccurrenceMatrix, genCooccurrenceMatrix, genCooccurrenceMatrix, genTranslationMatrix, getCooccurrenceCount, getDouble, getInt, getNonZeroCellInColumn, getNonZeroDoubleScoreInColumn, getNonZeroDoubleScoreInRow, getNonZeroDoubleScoresInColumn, getNonZeroDoubleScoresInRow, getNonZeroIntScoreInColumn, getNonZeroIntScoreInRow, getNonZeroIntScoresInColumn, getNonZeroIntScoresInRow, getNonZeroNumInColumn, getNonZeroRowInColumn, getNonZeroRowsInColumn, isFinalized, transpose
 
Methods inherited from class dragon.matrix.AbstractMatrix
columns, getBaseColumn, getBaseRow, getCellDataLength, getTranspose, rows, setTranspose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface dragon.matrix.SparseMatrix
createCell, createCell, createSparseMatrix
 
Methods inherited from interface dragon.matrix.Matrix
columns, getBaseColumn, getBaseRow, getCellDataLength, getTranspose, rows, setTranspose
 

Field Detail

matrixFilename

protected java.lang.String matrixFilename

indexFilename

protected java.lang.String indexFilename

totalCell

protected int totalCell

matrix

protected java.io.RandomAccessFile matrix

arrRowPosInFile

protected long[] arrRowPosInFile

cacheSize

protected int cacheSize

arrCachedRow

protected Row[] arrCachedRow

arrRowLoadFactor

protected float[] arrRowLoadFactor

arrRowPosInCache

protected int[] arrRowPosInCache

arrRowStart

protected int[] arrRowStart

firstEmpty

protected int firstEmpty

cacheMatrix

protected AbstractFlatSparseMatrix cacheMatrix

flushInterval

protected int flushInterval

matrixFactory

protected SparseMatrixFactory matrixFactory
Constructor Detail

AbstractSuperSparseMatrix

public AbstractSuperSparseMatrix(java.lang.String indexFilename,
                                 java.lang.String matrixFilename,
                                 int cellDataLength,
                                 boolean mergeMode,
                                 boolean miniMode)

AbstractSuperSparseMatrix

public AbstractSuperSparseMatrix(java.lang.String indexFilename,
                                 java.lang.String matrixFilename,
                                 int cellDataLength)
Method Detail

createRow

protected abstract Row createRow(int row,
                                 int columns,
                                 byte[] data)

createFlatSparseMatrix

protected abstract AbstractFlatSparseMatrix createFlatSparseMatrix(boolean mergeMode,
                                                                   boolean miniMode)

setCache

public void setCache(int cacheSize)

setFlushInterval

public void setFlushInterval(int interval)

close

public void close()
Description copied from interface: Matrix
Close the matrix and release all resources.


add

public boolean add(Cell cell)
Description copied from interface: SparseMatrix
Add a cell to the sparse matrix. If the cell already exists in the sparse matrix, the behavior of the addition is subject to the implementations. It may simply add the score to the existing cell. It may return false. It may cause errors even if the method returns true. Thus, one should be cautious when adding possibly existing cells to the sparse matrix.

Parameters:
cell - the input cell
Returns:
true if successfully added.

flush

public void flush()
Description copied from interface: SparseMatrix
Many implementations of sparse matrix cache cells in memory. This method gives the chance to dump cells in the cache to the disk file.


finalizeData

public boolean finalizeData(boolean sorting)
Description copied from interface: SparseMatrix
Any sparse matrix has two possible modes, writing mode and reading mode. After calling this method, writing is not allowed any more. Instead, one call read out data from the sparse matrix. In most cases, one should set the sorting option to true. In one case that all cells are added to the sparse matrix in their natural order (from top to bottom, from left to right), one can set the sorting option to false for saving time.

Parameters:
sorting - if need to sort the added cells before finalization.
Returns:
true if finalizing successfully

getMatrixFilename

public java.lang.String getMatrixFilename()

getIndexFilename

public java.lang.String getIndexFilename()

getNonZeroNum

public int getNonZeroNum()
Returns:
the number of non-zero cells

getNonZeroNumInRow

public int getNonZeroNumInRow(int row)
Parameters:
row - the index of the row
Returns:
the number of non-zero cells in the given row.

getNonZeroColumnInRow

public int getNonZeroColumnInRow(int row,
                                 int index)
Description copied from interface: SparseMatrix
This method returns the column index of the index-th non-zero cell in the given row. The index starts from zero.

Parameters:
row - the index of the row
index - the index-th non-zero cell
Returns:
the column index of the specified cell

getNonZeroColumnsInRow

public int[] getNonZeroColumnsInRow(int row)
Description copied from interface: SparseMatrix
If the given row has n non-zero cells, this method returns a n-length integer array. Each element of the array stores the column index of the corresponding non-zero cell.

Parameters:
row - the index of row
Returns:
the array of non-zero columns in the given row

getCell

public Cell getCell(int row,
                    int col)
Description copied from interface: SparseMatrix
If the specified cell doesn't exist, this method will return null.

Parameters:
row - the index of row in the matrix
col - the index of column in the matrix
Returns:
the cell

getNonZeroCellInRow

public Cell getNonZeroCellInRow(int row,
                                int index)
Description copied from interface: SparseMatrix
This method returns the index-th non-zero cell in the given column. The index starts from zero.

Parameters:
row - the index of the row
index - the index-th non-zero cell
Returns:
the cell

getRow

protected Row getRow(int index)