JSci.maths
Class DoubleSparseMatrix

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

public final class DoubleSparseMatrix
extends DoubleMatrix

The DoubleSparseMatrix class provides an object for encapsulating sparse matrices. Uses compressed row storage.

Version:
1.2
Author:
Mark Hale
See Also:
Serialized Form

Field Summary
protected static int SPARSE
          Storage format identifier.
 
Fields inherited from class JSci.maths.DoubleMatrix
ARRAY_2D, matrix
 
Fields inherited from class JSci.maths.Matrix
CLASS_SPECIFIC, numCols, numRows, storageFormat
 
Constructor Summary
DoubleSparseMatrix(double[][] array)
          Constructs a matrix from an array.
DoubleSparseMatrix(int rows, int cols)
          Constructs an empty matrix.
 
Method Summary
 DoubleMatrix add(DoubleMatrix m)
          Returns the addition of this matrix and another.
 DoubleSparseMatrix add(DoubleSparseMatrix m)
          Returns the addition of this matrix and another.
 boolean equals(java.lang.Object m)
          Compares two double sparse matrices for equality.
protected  void finalize()
          Finalize.
 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.
 DoubleMatrix mapElements(Mapping f)
          Applies a function on all the matrix elements.
 DoubleMatrix multiply(DoubleMatrix m)
          Returns the multiplication of this matrix and another.
 DoubleMatrix multiply(DoubleSparseMatrix m)
          Returns the multiplication of this matrix and another.
 DoubleVector multiply(DoubleVector v)
          Returns the multiplication of a vector by this matrix.
 DoubleMatrix scalarMultiply(double x)
          Returns the multiplication of this matrix by a scalar.
 double scalarProduct(DoubleMatrix m)
          Returns the scalar product of this matrix and another.
 double scalarProduct(DoubleSparseMatrix m)
          Returns the scalar product of this matrix and another.
 void setElement(int i, int j, double x)
          Sets the value of an element of the matrix.
 DoubleMatrix subtract(DoubleMatrix m)
          Returns the subtraction of this matrix and another.
 DoubleSparseMatrix subtract(DoubleSparseMatrix m)
          Returns the addition of this matrix and another.
 ComplexMatrix toComplexMatrix()
          Converts this matrix to a complex matrix.
 IntegerMatrix 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.DoubleMatrix
add, directSum, hashCode, multiply, negate, scalarDivide, scalarDivide, scalarMultiply, subtract, tensorProduct
 
Methods inherited from class JSci.maths.Matrix
columns, getInvalidElementMsg, rows
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SPARSE

protected static final int SPARSE
Storage format identifier.

See Also:
Constant Field Values
Constructor Detail

DoubleSparseMatrix

public DoubleSparseMatrix(int rows,
                          int cols)
Constructs an empty matrix.

Parameters:
rows - the number of rows
cols - the number of columns

DoubleSparseMatrix

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

Parameters:
array - an assigned value
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalize.

Overrides:
finalize in class DoubleMatrix
Throws:
java.lang.Throwable - Any that occur.

equals

public boolean equals(java.lang.Object m)
Compares two double sparse matrices for equality.

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

toString

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

Overrides:
toString in class DoubleMatrix

toIntegerMatrix

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

Overrides:
toIntegerMatrix in class DoubleMatrix
Returns:
an integer matrix

toComplexMatrix

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

Overrides:
toComplexMatrix in class DoubleMatrix
Returns:
a complex matrix

getElement

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

Overrides:
getElement in class DoubleMatrix
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.

Overrides:
setElement in class DoubleMatrix
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.

infNorm

public double infNorm()
Returns the linfinity-norm.

Overrides:
infNorm in class DoubleMatrix

frobeniusNorm

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

Overrides:
frobeniusNorm in class DoubleMatrix

add

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

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

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 DoubleMatrix subtract(DoubleMatrix m)
Returns the subtraction of this matrix and another.

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

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 DoubleMatrix scalarMultiply(double x)
Returns the multiplication of this matrix by a scalar.

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

scalarProduct

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

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

scalarProduct

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

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

multiply

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

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

multiply

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

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

multiply

public DoubleMatrix 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 DoubleMatrix
Returns:
a double sparse matrix

mapElements

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

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