dragon.matrix
Class AbstractSparseMatrix

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

public abstract class AbstractSparseMatrix
extends AbstractMatrix
implements SparseMatrix, java.io.Serializable

Abstract Sparse matrix implements the interface of sparse matrix which can be called by any data type's sparse matrix such as double and integer

Copyright: Copyright (c) 2005

Company: IST, Drexel University

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

Field Summary
protected  boolean isFinalized
           
protected  boolean mergeMode
           
protected  boolean miniMode
           
 
Fields inherited from class dragon.matrix.AbstractMatrix
cellDataLength, columnBase, columns, rowBase, rows, transposeMatrix
 
Constructor Summary
AbstractSparseMatrix(boolean mergeMode, boolean miniMode, int cellDataLength)
           
 
Method Summary
 double cosine(int rowA, int rowB)
          This method treats each row a vector and return the cosine similarity of two rows.
 boolean finalizeData()
          It is equal to calling finalizeData(true)
 boolean genCooccurrenceMatrix(IntSparseMatrix outputCooccurMatrix)
          The cell (i,j) in the output cooccurrence matrix stores the cooccurrence count of the i-th row and the j-th row.
 boolean genCooccurrenceMatrix(SparseMatrix matrixY, int minOccurrence, IntSparseMatrix outputCooccurMatrix)
          The cell (i,j) in the output cooccurrence matrix stores the cooccurrence count of the i-th row in the current matrix and the j-th row in the matrixY.
 boolean genCooccurrenceMatrix(SparseMatrix matrixY, IntSparseMatrix outputCooccurMatrix)
          The cell (i,j) in the output cooccurrence matrix stores the cooccurrence count of the i-th row in the current matrix and the j-th row in the matrixY.
static boolean genTranslationMatrix(IntSparseMatrix inputCooccurMatrix, DoubleSparseMatrix outputTransMatrix)
           
 int getCooccurrenceCount(int rowA, int rowB)
          If two cells in the same column have non-zero scores, they will be counted as co-occurred.
 double getDouble(int row, int column)
          Return the score stored in the specified cell.
 int getInt(int row, int column)
          Return the score stored in the specified cell.
 Cell getNonZeroCellInColumn(int column, int index)
          This method returns the index-th non-zero cell in the given row.
 double getNonZeroDoubleScoreInColumn(int column, int index)
          This method returns the double score of the index-th non-zero cell in the given column.
 double getNonZeroDoubleScoreInRow(int row, int index)
          This method returns the double score of the index-th non-zero cell in the given row.
 double[] getNonZeroDoubleScoresInColumn(int column)
          If the given column has n non-zero cells, this method returns a n-length double array.
 double[] getNonZeroDoubleScoresInRow(int row)
          If the given row has n non-zero cells, this method returns a n-length double array.
 int getNonZeroIntScoreInColumn(int column, int index)
          This method returns the integer score of the index-th non-zero cell in the given column.
 int getNonZeroIntScoreInRow(int row, int index)
          This method returns the integer score of the index-th non-zero cell in the given row.
 int[] getNonZeroIntScoresInColumn(int column)
          If the given column has n non-zero cells, this method returns a n-length integer array.
 int[] getNonZeroIntScoresInRow(int row)
          If the given row has n non-zero cells, this method returns a n-length integer array.
 int getNonZeroNumInColumn(int column)
          If the transposed matrix is not set yet, this method will automatically generate the transposed matrix.
 int getNonZeroRowInColumn(int column, int index)
          This method returns the row index of the index-th non-zero cell in the given column.
 int[] getNonZeroRowsInColumn(int column)
          If the given column has n non-zero cells, this method returns a n-length integer array.
 boolean isFinalized()
          If this method returns true, one can not add data to the sparse matrix any more.
 Matrix transpose()
          if one has set the transposed matrix by calling the method setTranspose, this method simply return that transposed matrix.
 
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
add, createCell, createCell, createSparseMatrix, finalizeData, flush, getCell, getNonZeroCellInRow, getNonZeroColumnInRow, getNonZeroColumnsInRow, getNonZeroNum, getNonZeroNumInRow
 
Methods inherited from interface dragon.matrix.Matrix
close, columns, getBaseColumn, getBaseRow, getCellDataLength, getTranspose, rows, setTranspose
 

Field Detail

isFinalized

protected boolean isFinalized

mergeMode

protected boolean mergeMode

miniMode

protected boolean miniMode
Constructor Detail

AbstractSparseMatrix

public AbstractSparseMatrix(boolean mergeMode,
                            boolean miniMode,
                            int cellDataLength)
Method Detail

isFinalized

public boolean isFinalized()
Description copied from interface: SparseMatrix
If this method returns true, one can not add data to the sparse matrix any more.

Specified by:
isFinalized in interface SparseMatrix
Returns:
true if finalized

finalizeData

public boolean finalizeData()
Description copied from interface: SparseMatrix
It is equal to calling finalizeData(true)

Specified by:
finalizeData in interface SparseMatrix
Returns:
true if finalizing successfully

getNonZeroCellInColumn

public Cell getNonZeroCellInColumn(int column,
                                   int index)
Description copied from interface: SparseMatrix
This method returns the index-th non-zero cell in the given row. The index starts from zero. If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes.

Specified by:
getNonZeroCellInColumn in interface SparseMatrix
Parameters:
column - the index of the column
index - the index-th non-zero cell
Returns:
the cell

getNonZeroNumInColumn

public int getNonZeroNumInColumn(int column)
Description copied from interface: SparseMatrix
If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes for the first call.

Specified by:
getNonZeroNumInColumn in interface SparseMatrix
Parameters:
column - the index of the column
Returns:
the number of non-zero cells in the given column.

getNonZeroRowInColumn

public int getNonZeroRowInColumn(int column,
                                 int index)
Description copied from interface: SparseMatrix
This method returns the row index of the index-th non-zero cell in the given column. The index starts from zero. If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes.

Specified by:
getNonZeroRowInColumn in interface SparseMatrix
Parameters:
column - the index of the column
index - the index-th non-zero cell
Returns:
the row index of the specified cell.

getNonZeroRowsInColumn

public int[] getNonZeroRowsInColumn(int column)
Description copied from interface: SparseMatrix
If the given column has n non-zero cells, this method returns a n-length integer array. Each element of the array stores the row index of the corresponding non-zero cell. If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes.

Specified by:
getNonZeroRowsInColumn in interface SparseMatrix
Parameters:
column - the index of the column
Returns:
the array of non-zero rows in the given column.

getDouble

public double getDouble(int row,
                        int column)
Description copied from interface: Matrix
Return the score stored in the specified cell. If the score is integer-typed, it will be coverted to a double.

Specified by:
getDouble in interface Matrix
Parameters:
row - the row index of the cell
column - the column index of the cell
Returns:
the score stored in the cell

getInt

public int getInt(int row,
                  int column)
Description copied from interface: Matrix
Return the score stored in the specified cell. If the score is double-typed, it will be coverted to an integer.

Specified by:
getInt in interface Matrix
Parameters:
row - the row index of the cell
column - the column index of the cell
Returns:
the score stored in the cell

getNonZeroDoubleScoreInColumn

public double getNonZeroDoubleScoreInColumn(int column,
                                            int index)
Description copied from interface: SparseMatrix
This method returns the double score of the index-th non-zero cell in the given column. The index starts from zero. If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes.

Specified by:
getNonZeroDoubleScoreInColumn in interface SparseMatrix
Parameters:
column - the index of the column
index - the index-th non-zero cell
Returns:
the double score

getNonZeroDoubleScoresInColumn

public double[] getNonZeroDoubleScoresInColumn(int column)
Description copied from interface: SparseMatrix
If the given column has n non-zero cells, this method returns a n-length double array. Each element of the array stores the double score of the corresponding non-zero cell. If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes.

Specified by:
getNonZeroDoubleScoresInColumn in interface SparseMatrix
Parameters:
column - the index of the column
Returns:
the array of non-zero double scores in the given column.

getNonZeroIntScoreInColumn

public int getNonZeroIntScoreInColumn(int column,
                                      int index)
Description copied from interface: SparseMatrix
This method returns the integer score of the index-th non-zero cell in the given column. The index starts from zero. If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes.

Specified by:
getNonZeroIntScoreInColumn in interface SparseMatrix
Parameters:
column - the index of the column
index - the index-th non-zero cell
Returns:
the integer score

getNonZeroIntScoresInColumn

public int[] getNonZeroIntScoresInColumn(int column)
Description copied from interface: SparseMatrix
If the given column has n non-zero cells, this method returns a n-length integer array. Each element of the array stores the integer score of the corresponding non-zero cell. If the transposed matrix is not set yet, this method will automatically generate the transposed matrix. Thus, it may take several minutes.

Specified by:
getNonZeroIntScoresInColumn in interface SparseMatrix
Parameters:
column - the index of the column
Returns:
the array of non-zero integer scores in the given column.

getNonZeroDoubleScoreInRow

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

Specified by:
getNonZeroDoubleScoreInRow in interface SparseMatrix
Parameters:
row - the index of the row.
index - the index-th non-zero cell
Returns:
the double score

getNonZeroIntScoreInRow

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

Specified by:
getNonZeroIntScoreInRow in interface SparseMatrix
Parameters:
row - the index of the row.
index - the index-th non-zero cell
Returns:
the integer score

getNonZeroDoubleScoresInRow

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

Specified by:
getNonZeroDoubleScoresInRow in interface SparseMatrix
Parameters:
row - the index of row
Returns:
the array of non-zero double scores in the given row

getNonZeroIntScoresInRow

public int[] getNonZeroIntScoresInRow(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 integer score of the corresponding non-zero cell.

Specified by:
getNonZeroIntScoresInRow in interface SparseMatrix
Parameters:
row - the index of row
Returns:
the array of non-zero integer scores in the given row

genCooccurrenceMatrix

public boolean genCooccurrenceMatrix(IntSparseMatrix outputCooccurMatrix)
Description copied from interface: SparseMatrix
The cell (i,j) in the output cooccurrence matrix stores the cooccurrence count of the i-th row and the j-th row.

Specified by:
genCooccurrenceMatrix in interface SparseMatrix
Parameters:
outputCooccurMatrix - the output cooccurrence matrix
Returns:
true if successfully

genCooccurrenceMatrix

public boolean genCooccurrenceMatrix(SparseMatrix matrixY,
                                     IntSparseMatrix outputCooccurMatrix)
Description copied from interface: SparseMatrix
The cell (i,j) in the output cooccurrence matrix stores the cooccurrence count of the i-th row in the current matrix and the j-th row in the matrixY. The current matrix and the input matrix should have the same number of columns.

Specified by:
genCooccurrenceMatrix in interface SparseMatrix
Parameters:
matrixY - another sparse matrix
outputCooccurMatrix - the output cooccurrence matrix
Returns:
true if successfully

genCooccurrenceMatrix

public boolean genCooccurrenceMatrix(SparseMatrix matrixY,
                                     int minOccurrence,
                                     IntSparseMatrix outputCooccurMatrix)
Description copied from interface: SparseMatrix
The cell (i,j) in the output cooccurrence matrix stores the cooccurrence count of the i-th row in the current matrix and the j-th row in the matrixY. The current matrix and the input matrix should have the same number of columns. If the cooccurrence count less than the given threshold, it will be set to zero.

Specified by:
genCooccurrenceMatrix in interface SparseMatrix
Parameters:
matrixY - another sparse matrix
minOccurrence - the minimum cooccurrence count
outputCooccurMatrix - the output cooccurrence matrix
Returns:
true if successfully

getCooccurrenceCount

public int getCooccurrenceCount(int rowA,
                                int rowB)
Description copied from interface: Matrix
If two cells in the same column have non-zero scores, they will be counted as co-occurred.

Specified by:
getCooccurrenceCount in interface Matrix
Parameters:
rowA - the index of the first row
rowB - the index of the second row
Returns:
the cooccurrence count

cosine

public double cosine(int rowA,
                     int rowB)
Description copied from interface: Matrix
This method treats each row a vector and return the cosine similarity of two rows.

Specified by:
cosine in interface Matrix
Parameters:
rowA - the row index of the first vector
rowB - the row index of the second vector
Returns:
the cosine similarity of two given rows.

genTranslationMatrix

public static boolean genTranslationMatrix(IntSparseMatrix inputCooccurMatrix,
                                           DoubleSparseMatrix outputTransMatrix)

transpose

public Matrix transpose()
Description copied from interface: Matrix
if one has set the transposed matrix by calling the method setTranspose, this method simply return that transposed matrix. Otherwise, it will generate the transposed matrix online. So this method may take several minutes.

Specified by:
transpose in interface Matrix
Overrides:
transpose in class AbstractMatrix
Returns:
the transposed matrix