JSci.maths.matrices
Class DoubleSparseMatrix

java.lang.Object
  extended by JSci.maths.matrices.Matrix
      extended by JSci.maths.matrices.AbstractDoubleMatrix
          extended by JSci.maths.matrices.DoubleSparseMatrix
All Implemented Interfaces:
java.io.Serializable, Algebra.Member, Module.Member, VectorSpace.Member, Ring.Member, AbelianGroup.Member, Member

public final class DoubleSparseMatrix
extends AbstractDoubleMatrix

The DoubleSparseMatrix class provides an object for encapsulating sparse matrices. Uses compressed row storage (Yale sparse matrix format).

See Also:
Serialized Form

Field Summary
 
Fields inherited from class JSci.maths.matrices.Matrix
numCols, numRows
 
Constructor Summary
DoubleSparseMatrix(double[][] array)
          Constructs a matrix from an array.
DoubleSparseMatrix(int rowCount, int colCount)
          Constructs an empty matrix.
DoubleSparseMatrix(int rowCount, int colCount, int capacityIncrement)
           
 
Method Summary
 AbstractDoubleMatrix add(AbstractDoubleMatrix m)
          Returns the addition of this matrix and another.
 DoubleMatrix add(DoubleMatrix m)
           
 DoubleSparseMatrix add(DoubleSparseMatrix m)
          Returns the addition of this matrix and another.
 int elementCount()
          Returns the number of non-zero elements.
 boolean equals(AbstractDoubleMatrix m, double tol)
          Compares two double sparse matrices for equality.
 boolean equals(DoubleSparseMatrix m)
           
 boolean equals(DoubleSparseMatrix m, double tol)
           
 double frobeniusNorm()
          Returns the Frobenius (l2) norm.
 double getElement(int i, int j)
          Returns an element of the matrix.
 double infNorm()
          Returns the linfinity-norm.
 AbstractDoubleMatrix mapElements(Mapping f)
          Applies a function on all the matrix elements.
 AbstractDoubleMatrix multiply(AbstractDoubleMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractDoubleVector multiply(AbstractDoubleVector v)
          Returns the multiplication of a vector by this matrix.
 AbstractDoubleMatrix multiply(DoubleMatrix m)
           
 AbstractDoubleMatrix multiply(DoubleSparseMatrix m)
          Returns the multiplication of this matrix and another.
 AbstractDoubleVector multiply(DoubleSparseVector v)
          Returns the multiplication of a sparse vector by this matrix.
 AbstractDoubleMatrix scalarDivide(double x)
          Returns the division of this matrix by a scalar.
 AbstractDoubleMatrix scalarMultiply(double x)
          Returns the multiplication of this matrix by a scalar.
 double scalarProduct(AbstractDoubleMatrix m)
          Returns the scalar product of this matrix and another.
 double scalarProduct(DoubleMatrix m)
           
 void setElement(int i, int j, double x)
          Sets the value of an element of the matrix.
 AbstractDoubleMatrix subtract(AbstractDoubleMatrix m)
          Returns the subtraction of this matrix and another.
 DoubleMatrix subtract(DoubleMatrix m)
           
 DoubleSparseMatrix subtract(DoubleSparseMatrix m)
          Returns the addition of this matrix and another.
 AbstractComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 AbstractIntegerMatrix toIntegerMatrix()
          Converts this matrix to an integer matrix.
 java.lang.String toString()
          Returns a string representing this matrix.
 Matrix transpose()
          Returns the transpose of this matrix.
 
Methods inherited from class JSci.maths.matrices.AbstractDoubleMatrix
add, directSum, equals, equals, getSet, hashCode, multiply, negate, scalarDivide, scalarMultiply, subtract, tensor
 
Methods inherited from class JSci.maths.matrices.Matrix
columns, getInvalidElementMsg, rows
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DoubleSparseMatrix

public DoubleSparseMatrix(int rowCount,
                          int colCount)
Constructs an empty matrix.

Parameters:
rowCount - the number of rows
colCount - the number of columns

DoubleSparseMatrix

public DoubleSparseMatrix(int rowCount,
                          int colCount,
                          int capacityIncrement)

DoubleSparseMatrix

public DoubleSparseMatrix(double[][] array)
Constructs a matrix from an array.

Parameters:
array - an assigned value
Method Detail

equals

public boolean equals(AbstractDoubleMatrix m,
                      double tol)
Compares two double sparse matrices for equality.

Overrides:
equals in class AbstractDoubleMatrix
Parameters:
m - a double matrix

equals

public final boolean equals(DoubleSparseMatrix m)

equals

public boolean equals(DoubleSparseMatrix m,
                      double tol)

toString

public java.lang.String toString()
Returns a string representing this matrix.

Overrides:
toString in class AbstractDoubleMatrix

toIntegerMatrix

public AbstractIntegerMatrix toIntegerMatrix()
Converts this matrix to an integer matrix.

Overrides:
toIntegerMatrix in class AbstractDoubleMatrix
Returns:
an integer matrix

toComplexMatrix

public AbstractComplexMatrix toComplexMatrix()
Converts this matrix to a complex matrix.

Overrides:
toComplexMatrix in class AbstractDoubleMatrix
Returns:
a complex matrix

getElement

public double getElement(int i,
                         int j)
Returns an element of the matrix.

Specified by:
getElement in class AbstractDoubleMatrix
Parameters:
i - row index of the element
j - column index of the element
Throws:
MatrixDimensionException - If attempting to access an invalid element.

setElement

public void setElement(int i,
                       int j,
                       double x)
Sets the value of an element of the matrix.

Specified by:
setElement in class AbstractDoubleMatrix
Parameters:
i - row index of the element
j - column index of the element
x - a number
Throws:
MatrixDimensionException - If attempting to access an invalid element.

elementCount

public int elementCount()
Returns the number of non-zero elements.


infNorm

public double infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class AbstractDoubleMatrix

frobeniusNorm

public double frobeniusNorm()
Returns the Frobenius (l2) norm.

Overrides:
frobeniusNorm in class AbstractDoubleMatrix

add

public AbstractDoubleMatrix add(AbstractDoubleMatrix m)
Returns the addition of this matrix and another.

Overrides:
add in class AbstractDoubleMatrix
Parameters:
m - a double matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

add

public DoubleMatrix add(DoubleMatrix m)

add

public DoubleSparseMatrix add(DoubleSparseMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a double sparse matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

public AbstractDoubleMatrix subtract(AbstractDoubleMatrix m)
Returns the subtraction of this matrix and another.

Overrides:
subtract in class AbstractDoubleMatrix
Parameters:
m - a double matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

subtract

public DoubleMatrix subtract(DoubleMatrix m)

subtract

public DoubleSparseMatrix subtract(DoubleSparseMatrix m)
Returns the addition of this matrix and another.

Parameters:
m - a double sparse matrix
Throws:
MatrixDimensionException - If the matrices are different sizes.

scalarMultiply

public AbstractDoubleMatrix scalarMultiply(double x)
Returns the multiplication of this matrix by a scalar.

Overrides:
scalarMultiply in class AbstractDoubleMatrix
Parameters:
x - a double
Returns:
a double sparse matrix

scalarDivide

public AbstractDoubleMatrix scalarDivide(double x)
Description copied from class: AbstractDoubleMatrix
Returns the division of this matrix by a scalar.

Overrides:
scalarDivide in class AbstractDoubleMatrix
Parameters:
x - a double.
Returns:
a double matrix.

scalarProduct

public double scalarProduct(AbstractDoubleMatrix m)
Returns the scalar product of this matrix and another.

Overrides:
scalarProduct in class AbstractDoubleMatrix
Parameters:
m - a double matrix.
Throws:
MatrixDimensionException - If the matrices are different sizes.

scalarProduct

public double scalarProduct(DoubleMatrix m)

multiply

public AbstractDoubleVector multiply(AbstractDoubleVector v)
Returns the multiplication of a vector by this matrix.

Overrides:
multiply in class AbstractDoubleMatrix
Parameters:
v - a double vector
Throws:
DimensionException - If the matrix and vector are incompatible.

multiply

public AbstractDoubleVector multiply(DoubleSparseVector v)
Returns the multiplication of a sparse vector by this matrix.

Parameters:
v - a double vector
Throws:
DimensionException - If the matrix and vector are incompatible.

multiply

public AbstractDoubleMatrix multiply(AbstractDoubleMatrix m)
Returns the multiplication of this matrix and another.

Overrides:
multiply in class AbstractDoubleMatrix
Parameters:
m - a double matrix
Returns:
a AbstractDoubleMatrix or a AbstractDoubleSquareMatrix as appropriate
Throws:
MatrixDimensionException - If the matrices are incompatible.

multiply

public AbstractDoubleMatrix multiply(DoubleMatrix m)

multiply

public AbstractDoubleMatrix multiply(DoubleSparseMatrix m)
Returns the multiplication of this matrix and another.

Parameters:
m - a double sparse matrix
Throws:
MatrixDimensionException - If the matrices are incompatible.

transpose

public Matrix transpose()
Returns the transpose of this matrix.

Overrides:
transpose in class AbstractDoubleMatrix
Returns:
a double sparse matrix

mapElements

public AbstractDoubleMatrix mapElements(Mapping f)
Applies a function on all the matrix elements.

Overrides:
mapElements in class AbstractDoubleMatrix
Parameters:
f - a user-defined function
Returns:
a double sparse matrix