edu.stanford.nlp.linalg
Class AbstractMatrix

java.lang.Object
  |
  +--edu.stanford.nlp.linalg.AbstractMatrix
All Implemented Interfaces:
Cloneable, Matrix
Direct Known Subclasses:
ArrayListMatrix, ColtDenseMatrix, ColtSparseMatrix

public abstract class AbstractMatrix
extends Object
implements Matrix

Abstract Matrix class


Field Summary
protected  int nc
           
protected  int nnz
           
protected  int nr
           
 
Constructor Summary
AbstractMatrix()
          default constructor.
AbstractMatrix(int num_rows, int num_columns)
          constructs Matrix of given size
AbstractMatrix(int num_rows, int num_columns, int cardinality)
          constructs matrix of given size and cardinality
AbstractMatrix(String filename)
          constructs Matrix and sets values according to ASCII file of form: num_rows num_columns cardinality followed by triplets row, column, value
 
Method Summary
abstract  void allocate(int num_rows, int num_columns)
          allocates memory for matrix of given size
abstract  void allocate(int num_rows, int num_columns, int cardinality)
          allocates memory for matrix of given size and cardinality
 int cardinality()
          Returns the number of cells having non-zero values; ignores tolerance.
abstract  Object clone()
           
 Iterator columnIterator()
          iterates through all Array columns in the Matrix
 int columns()
          returns number of columns in matrix
 Iterator entryIterator()
          returns iterator over all Entries in matrix.
 Set entrySet()
          returns Set of all entries in matrix for sparse matrices, returns set of all nonzero entries in matrix
 Matrix normalizeColumns(Metric metric)
          returns Matrix whose columns are normalized to 1 does not change receiver
 int rows()
          returns number of rows in matrix
 void setColumn(int index, Array column)
          sets column with index index = column
 Matrix tfidf()
           
 String toDenseString()
          Returns a dense string representation of matrix.
 String toMatlabSparseString()
          returns sparse string representation of matrix, in Matlab-readable format, ensuring that the first matrix entry is [1,1,value] rather than [0,0,value] i.e.
 String toSparseString()
          returns sparse string representation of matrix num_rows num_columns cardinality row column value row column value ...
 String toString()
          returns bracket-delimited entrySet String representation of Matrix [[[row,column,value], [row,column,value]], [[row,column,value]...]
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.stanford.nlp.linalg.Matrix
get, getColumn, set
 

Field Detail

nr

protected int nr

nc

protected int nc

nnz

protected int nnz
Constructor Detail

AbstractMatrix

public AbstractMatrix()
default constructor. does nothing.


AbstractMatrix

public AbstractMatrix(int num_rows,
                      int num_columns)
constructs Matrix of given size


AbstractMatrix

public AbstractMatrix(int num_rows,
                      int num_columns,
                      int cardinality)
constructs matrix of given size and cardinality


AbstractMatrix

public AbstractMatrix(String filename)
               throws FileNotFoundException,
                      IOException
constructs Matrix and sets values according to ASCII file of form: num_rows num_columns cardinality followed by triplets row, column, value

Method Detail

entrySet

public Set entrySet()
returns Set of all entries in matrix for sparse matrices, returns set of all nonzero entries in matrix

Specified by:
entrySet in interface Matrix

toString

public String toString()
returns bracket-delimited entrySet String representation of Matrix [[[row,column,value], [row,column,value]], [[row,column,value]...]

Specified by:
toString in interface Matrix
Overrides:
toString in class Object

toSparseString

public String toSparseString()
returns sparse string representation of matrix num_rows num_columns cardinality row column value row column value ...

Specified by:
toSparseString in interface Matrix

toMatlabSparseString

public String toMatlabSparseString()
returns sparse string representation of matrix, in Matlab-readable format, ensuring that the first matrix entry is [1,1,value] rather than [0,0,value] i.e. row column value row column value ...

Specified by:
toMatlabSparseString in interface Matrix

toDenseString

public String toDenseString()
Returns a dense string representation of matrix. i.e. 3 x 4 matrix
 value    value   value    value
 value    value   value    value
 value    value   value    value
 value    value   value    value
 

Specified by:
toDenseString in interface Matrix

normalizeColumns

public Matrix normalizeColumns(Metric metric)
Description copied from interface: Matrix
returns Matrix whose columns are normalized to 1 does not change receiver

Specified by:
normalizeColumns in interface Matrix

tfidf

public Matrix tfidf()

columnIterator

public Iterator columnIterator()
Description copied from interface: Matrix
iterates through all Array columns in the Matrix

Specified by:
columnIterator in interface Matrix

allocate

public abstract void allocate(int num_rows,
                              int num_columns)
allocates memory for matrix of given size


allocate

public abstract void allocate(int num_rows,
                              int num_columns,
                              int cardinality)
allocates memory for matrix of given size and cardinality


columns

public int columns()
Description copied from interface: Matrix
returns number of columns in matrix

Specified by:
columns in interface Matrix

rows

public int rows()
Description copied from interface: Matrix
returns number of rows in matrix

Specified by:
rows in interface Matrix

cardinality

public int cardinality()
Description copied from interface: Matrix
Returns the number of cells having non-zero values; ignores tolerance.

Specified by:
cardinality in interface Matrix

entryIterator

public Iterator entryIterator()
returns iterator over all Entries in matrix.

Specified by:
entryIterator in interface Matrix

clone

public abstract Object clone()
Specified by:
clone in interface Matrix
Overrides:
clone in class Object

setColumn

public void setColumn(int index,
                      Array column)
Description copied from interface: Matrix
sets column with index index = column

Specified by:
setColumn in interface Matrix


Stanford NLP Group