spis.Util.Matrix
Class SparseMatrix

java.lang.Object
  extended byspis.Util.Matrix.Matrix
      extended byspis.Util.Matrix.SparseMatrix
All Implemented Interfaces:
java.io.Serializable

public class SparseMatrix
extends Matrix
implements java.io.Serializable

Class Name : SparseMatrix
Project ref : SPIS project
File name : SparseMatrix.java
File type : class
Copyright : ONERA, 2 Av. E. Belin, 31055 Toulouse cedex, France http://www.onecert.fr
Status : under development
Creation : 25/08/2003
Modification :

Description : Sparse Matrix class

Versions and anomalies correction :

Version numberAuthor (name, e-mail) Corrections/Modifications
0.1 JF Roussel, roussel@onecert.frCreation


Version:
0.1
Author:
JF Roussel
See Also:
Serialized Form

Field Summary
private  int[] col
          column index of non zero values
private  int[] p
          pointer to each row start: val[p[i]] is the first value of row i and col[p[i]] is its column index.
private  float[] val
          non zero values of the matrix
 
Fields inherited from class spis.Util.Matrix.Matrix
 
Constructor Summary
private SparseMatrix()
          Constructor without real initialisation (hence private).
  SparseMatrix(float[][] values)
          Constructor with data, which must be a rectangular matrix i.e.values[i].length identical for all i (not checked).
  SparseMatrix(float[][] values, int d1, int d2)
          Constructor with data and size.
private SparseMatrix(int dim1, int dim2, int[] pointers, int[] column, float[] values)
          Constructor from already-computed condensed tables (hence private).
 
Method Summary
 Matrix buildLineNormalised()
          Generates and returns a matrix built from this matrix by normalising each of its lines: Mij -> Mij / (sum_k Mik).
 Matrix buildTranspose()
          Generates and returns the transpose of this matrix
 float[][] getValues()
          Returns a 2D array representing the matrix
 void incrementValue(int i, int j, float incr)
          Increments the element (i,j) of the matrix of the value incr.
 Matrix matMult(Matrix m)
          Multyplies by another matrix m and returns this_matrix . m in result.
private  float[][] matMult(Matrix m, int notUsedInteger)
          Multiplies by another matrix m and returns this_matrix . m as a float[][].
 void matMult(Matrix m, Matrix result)
          Multyplies by another matrix m and returns this_matrix . m in result.
 void setValue(int i, int j, float val)
          Sets the element (i,j) of the matrix to the value val.
 void setValues(float[][] values)
          Builds this sparse-storage matrix from a direct-array-storage (an array of float value).
 void setValues(float[][] values, int d1, int d2)
          Builds this sparse-storage matrix from a direct-array-storage (an array of float value).
 void vectMult(FloatScalTable x, FloatScalTable y)
          Multyplies by a vector (x) and returns y = matrix x.
 
Methods inherited from class spis.Util.Matrix.Matrix
doubleVectMult, getDim1, getDim2, linearSystemSolve, setDim1, setDim2
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

val

private float[] val
non zero values of the matrix


col

private int[] col
column index of non zero values


p

private int[] p
pointer to each row start: val[p[i]] is the first value of row i and col[p[i]] is its column index.

Constructor Detail

SparseMatrix

public SparseMatrix(float[][] values)
Constructor with data, which must be a rectangular matrix i.e.values[i].length identical for all i (not checked).
Does not keep the array "values" as an instance variable, contrarily to other constructors.


SparseMatrix

public SparseMatrix(float[][] values,
                    int d1,
                    int d2)
Constructor with data and size.
Does not keep the array "values" as an instance variable, contrarily to other constructors.


SparseMatrix

private SparseMatrix(int dim1,
                     int dim2,
                     int[] pointers,
                     int[] column,
                     float[] values)
Constructor from already-computed condensed tables (hence private).


SparseMatrix

private SparseMatrix()
Constructor without real initialisation (hence private).

Method Detail

setValues

public void setValues(float[][] values)
Builds this sparse-storage matrix from a direct-array-storage (an array of float value). The matrix dimensions are defined as the ones of the float array (values.length and values[0].length).

Parameters:
values -

setValues

public void setValues(float[][] values,
                      int d1,
                      int d2)
Builds this sparse-storage matrix from a direct-array-storage (an array of float value). The matrix dimensions are defined as d1 x d2, hence values must be at least [d1][d2] (extra vaules ignored).

Parameters:
values -
d1 -
d2 -

vectMult

public void vectMult(FloatScalTable x,
                     FloatScalTable y)
Multyplies by a vector (x) and returns y = matrix x.

Specified by:
vectMult in class Matrix

matMult

public void matMult(Matrix m,
                    Matrix result)
Multyplies by another matrix m and returns this_matrix . m in result. NB: current coding not optimal: involves memory allocation/deallocation (optimal on the loop number but not on memory).

Specified by:
matMult in class Matrix
Parameters:
m -
result - this . m, as a matrix of predefined subtype (if possible)

matMult

public Matrix matMult(Matrix m)
Multyplies by another matrix m and returns this_matrix . m in result. NB: current coding not optimal: involves memory allocation/deallocation (optimal on the loop number but not on memory).

Specified by:
matMult in class Matrix
Parameters:
m -
Returns:
this . m, as a SparseMatrix

matMult

private float[][] matMult(Matrix m,
                          int notUsedInteger)
Multiplies by another matrix m and returns this_matrix . m as a float[][].

Parameters:
m -
notUsedInteger - spurious integer, only here to distinguish this method interface from Matrix matMult(Matrix)
Returns:
this_matrix multiplied by m matrix, as a float[][] array

buildTranspose

public Matrix buildTranspose()
Generates and returns the transpose of this matrix

Specified by:
buildTranspose in class Matrix

getValues

public float[][] getValues()
Returns a 2D array representing the matrix

Specified by:
getValues in class Matrix

buildLineNormalised

public Matrix buildLineNormalised()
Generates and returns a matrix built from this matrix by normalising each of its lines: Mij -> Mij / (sum_k Mik). Returns a SparseMatrix.

Specified by:
buildLineNormalised in class Matrix

setValue

public void setValue(int i,
                     int j,
                     float val)
Description copied from class: Matrix
Sets the element (i,j) of the matrix to the value val. Only partially supported by derived classes: only diagonal term for a DiagMatrix, and only values already present in the matrix structure for a SparseMatrix

Specified by:
setValue in class Matrix
Parameters:
i -
j -
val -
See Also:
Matrix.setValue(int, int, float)

incrementValue

public void incrementValue(int i,
                           int j,
                           float incr)
Description copied from class: Matrix
Increments the element (i,j) of the matrix of the value incr. Only partially supported by derived classes: only diagonal term for a DiagMatrix, and only values already present in the matrix structure for a SparseMatrix

Specified by:
incrementValue in class Matrix
Parameters:
i -
j -
See Also:
Matrix.incrementValue(int, int, float)