edu.northwestern.at.utils.math.matrix
Class SparseMatrix

java.lang.Object
  extended by edu.northwestern.at.utils.math.matrix.AbstractMatrix
      extended by edu.northwestern.at.utils.math.matrix.SparseMatrix
All Implemented Interfaces:
Matrix, java.io.Serializable

public class SparseMatrix
extends AbstractMatrix
implements Matrix

Implements a sparse matrix using a hash map.

See Also:
Serialized Form

Field Summary
protected  java.util.HashMap matrixData
          The matrix contents as a two-dimensional array of doubles.
 
Fields inherited from class edu.northwestern.at.utils.math.matrix.AbstractMatrix
columns, rows
 
Constructor Summary
protected SparseMatrix()
          Don't allow instantiation without size specification.
  SparseMatrix(int rows, int columns)
          Create a matrix of the specified size.
 
Method Summary
 double get(int row, int column)
          Gets value of element at given row and column.
 int getUsed()
           
 void set(int row, int column, double value)
          Set an element at the given position to a new value.
 
Methods inherited from class edu.northwestern.at.utils.math.matrix.AbstractMatrix
columns, get, getColumn, getColumnData, getColumns, getColumns, getCopy, getRow, getRowData, getRows, getRows, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, rows, set, set, setColumn, setColumnData, setColumnData, setRow, setRowData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.northwestern.at.utils.math.matrix.Matrix
columns, get, getColumn, getColumnData, getColumns, getColumns, getCopy, getRow, getRowData, getRows, getRows, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, rows, set, set, setColumn, setColumnData, setColumnData, setRow, setRowData, toString
 

Field Detail

matrixData

protected java.util.HashMap matrixData
The matrix contents as a two-dimensional array of doubles.

Constructor Detail

SparseMatrix

protected SparseMatrix()
Don't allow instantiation without size specification.


SparseMatrix

public SparseMatrix(int rows,
                    int columns)
Create a matrix of the specified size.

Parameters:
rows - Number of rows.
columns - Number of columns.

Each element of the result matrix will be set to zero.

Method Detail

set

public void set(int row,
                int column,
                double value)
Set an element at the given position to a new value.

Specified by:
set in interface Matrix
Specified by:
set in class AbstractMatrix
Parameters:
row - Row in which the element occurs.
column - Column in which the element occurs.
value - The new value to be set.

Note: only non-zero values are stored.


get

public double get(int row,
                  int column)
Gets value of element at given row and column.

Specified by:
get in interface Matrix
Specified by:
get in class AbstractMatrix
Parameters:
row - Row in which the element occurs.
column - Column in which the element occurs.
Returns:
The value at the given position.

getUsed

public int getUsed()