gov.sandia.cognition.math.matrix.mtj
Class AbstractSparseMatrix

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.AbstractRing<Matrix>
          extended by gov.sandia.cognition.math.matrix.AbstractMatrix
              extended by gov.sandia.cognition.math.matrix.mtj.AbstractMTJMatrix
                  extended by gov.sandia.cognition.math.matrix.mtj.AbstractSparseMatrix
All Implemented Interfaces:
Matrix, Vectorizable, Ring<Matrix>, CloneableSerializable, Serializable, Cloneable, Iterable<MatrixEntry>
Direct Known Subclasses:
SparseColumnMatrix, SparseRowMatrix

@CodeReview(reviewer="Jonathan McClain",
            date="2006-05-19",
            changesNeeded=false,
            comments="Looks fine.")
public abstract class AbstractSparseMatrix
extends AbstractMTJMatrix

Implements some generic operations that any sparse-matrix representation must do.

Since:
1.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
protected AbstractSparseMatrix(no.uib.cipr.matrix.Matrix internalMatrix)
          Creates a new instance of AbstractSparseMatrix using the given MTJ matrix
 
Method Summary
abstract  void compact()
          Compact the memory used by the matrix, getting rid of any zero elements
 SparseVector getColumn(int columnIndex)
          Gets the specified column from the zero-based index and returns a vector that corresponds to that column.
 SparseVector getRow(int rowIndex)
          Gets the specified row from the zero-based index and returns a vector that corresponds to that column
 boolean isSparse()
          Returns true if this matrix has a potentially sparse underlying structure.
 DenseMatrix pseudoInverse(double effectiveZero)
          Computes the effective pseudo-inverse of this, using a rather expensive procedure (SVD)
 void setElement(int rowIndex, int columnIndex, double value)
          Sets the Matrix element at the specified zero-based indices throws ArrayIndexOutOfBoundsException if either rowIndex or columnIndex are less than 0, or greater than the number of rows (columns) minus one (0 <= index <= num-1)
 SparseVector solve(AbstractMTJVector b)
          This sparse-vector solver performs iterative solving for "x" in the equation: this*x = b, and the AbstractSparseMatrix "this" can be unstructured (e.g., asymmetric, indefinite, etc.)
 SparseVector times(AbstractMTJVector vector)
          Returns the column vector from the equation return = this * vector
 String toString()
          Creates a string in the "(Row,Column): value" for the nonzero elements
 String toString(NumberFormat format)
          Converts the vector to a String, using the given formatter.
 
Methods inherited from class gov.sandia.cognition.math.matrix.mtj.AbstractMTJMatrix
clone, convertFromVector, convertToVector, dotTimesEquals, dotTimesEquals, equals, getElement, getInternalMatrix, getNumColumns, getNumRows, getSubMatrixInto, identity, inverse, isSquare, isSymmetric, iterator, logDeterminant, minusEquals, minusEquals, normFrobenius, plusEquals, plusEquals, rank, scaledMinusEquals, scaledPlusEquals, scaledPlusEquals, scaleEquals, setInternalMatrix, solve, solve, solve, times, times, times, timesInto, timesInto, transposeInto, zero
 
Methods inherited from class gov.sandia.cognition.math.matrix.AbstractMatrix
assertSameDimensions, checkMultiplicationDimensions, checkSameDimensions, dotDivide, dotDivideEquals, equals, equals, getColumnInto, getRowInto, hashCode, isSymmetric, isZero, pseudoInverse, rank, setColumn, setRow, setSubMatrix, sumOfColumns, sumOfRows, toArray, trace
 
Methods inherited from class gov.sandia.cognition.math.AbstractRing
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.math.matrix.Matrix
getSubMatrix, transpose
 
Methods inherited from interface gov.sandia.cognition.math.Ring
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
 

Constructor Detail

AbstractSparseMatrix

protected AbstractSparseMatrix(no.uib.cipr.matrix.Matrix internalMatrix)
Creates a new instance of AbstractSparseMatrix using the given MTJ matrix

Parameters:
internalMatrix - internal MTJ matrix to base this on
Method Detail

compact

public abstract void compact()
Compact the memory used by the matrix, getting rid of any zero elements


times

public SparseVector times(AbstractMTJVector vector)
Description copied from class: AbstractMTJMatrix
Returns the column vector from the equation return = this * vector

Specified by:
times in class AbstractMTJMatrix
Parameters:
vector - Vector by which to post-multiply this, must have the same number of rows as this
Returns:
Vector with the same dimensionality as the number of rows as this and vector

setElement

public void setElement(int rowIndex,
                       int columnIndex,
                       double value)
Description copied from interface: Matrix
Sets the Matrix element at the specified zero-based indices throws ArrayIndexOutOfBoundsException if either rowIndex or columnIndex are less than 0, or greater than the number of rows (columns) minus one (0 <= index <= num-1)

Specified by:
setElement in interface Matrix
Overrides:
setElement in class AbstractMTJMatrix
Parameters:
rowIndex - Zero-based index into the rows of the Matrix
columnIndex - Zero-based index into the columns of the Matrix
value - Value to set at the specified index

solve

public SparseVector solve(AbstractMTJVector b)
This sparse-vector solver performs iterative solving for "x" in the equation: this*x = b, and the AbstractSparseMatrix "this" can be unstructured (e.g., asymmetric, indefinite, etc.)

Overrides:
solve in class AbstractMTJMatrix
Parameters:
b - must satisfy this.getNumColumns() == b.getDimensionality()
Returns:
x Vector with dimensions (this.getNumRows())

pseudoInverse

public DenseMatrix pseudoInverse(double effectiveZero)
Description copied from interface: Matrix
Computes the effective pseudo-inverse of this, using a rather expensive procedure (SVD)

Parameters:
effectiveZero - effective zero to pass along to the SVD
Returns:
effective pseudo-inverse of this

toString

public String toString()
Creates a string in the "(Row,Column): value" for the nonzero elements

Specified by:
toString in interface Matrix
Overrides:
toString in class Object
Returns:
String representing the sparse matrix

toString

public String toString(NumberFormat format)
Description copied from interface: Matrix
Converts the vector to a String, using the given formatter.

Parameters:
format - The number format to use.
Returns:
The String representation of the Matrix.

getColumn

public SparseVector getColumn(int columnIndex)
Description copied from interface: Matrix
Gets the specified column from the zero-based index and returns a vector that corresponds to that column.

Parameters:
columnIndex - zero-based index into the matrix
Returns:
Vector with elements equal to the number of rows in this

getRow

public SparseVector getRow(int rowIndex)
Description copied from interface: Matrix
Gets the specified row from the zero-based index and returns a vector that corresponds to that column

Parameters:
rowIndex - zero-based index into the matrix
Returns:
Vector with elements equal to the number of columns in this

isSparse

public boolean isSparse()
Description copied from interface: Matrix
Returns true if this matrix has a potentially sparse underlying structure. This can indicate that it is faster to only process the non-zero elements rather than to do dense operations on it. Of course, even with a sparse structure, there may be no zero elements or conversely even with a non-sparse (dense) structure there may be many zero elements.

Returns:
True if the matrix has a potentially sparse structure. Otherwise, false.