drasys.or.matrix
Class CompressedColumnMatrix

java.lang.Object
  |
  +--drasys.or.matrix.RealContainer
        |
        +--drasys.or.matrix.Matrix
              |
              +--drasys.or.matrix.CompressedMatrix
                    |
                    +--drasys.or.matrix.CompressedColumnMatrix

public class CompressedColumnMatrix
extends CompressedMatrix

A sparse compressed resizable column-major matrix of double values. This matrix is efficient for numerical computing, especially column-wise computations. Its also efficient for adding new columns and new elements to the last column.

The most efficient way to build this matrix is column-wise by adding elements only to the last column. This reduces the memory copying caused by adding elements at the head of the arrays. The attribute 'fillInSpace' can be used to reserve some extra elements for each column if fill-in is unavoidable. If the matrix is constructed strictly column-wise then 'fillInSpace' should be set to zero to conserve memory.

There is more detailed information available about the internal storage format.

References:

Matrix Computations (Johns Hopkins Studies in the Mathematical Sciences)
    Gene H. Golub, Charles F. Van Loan (Contributor) / Paperback / Published 1996
Numerical Recipes in C : The Art of Scientific Computing
    William H. Press, et al / Hardcover / Published 1993
Parallel Algorithms for Matrix Computations
    K.A. Gallivan / Paperback / Published 1990

See Also:
Serialized Form

Fields inherited from class drasys.or.matrix.RealContainer
_epsilon, _globalEpsilon
 
Constructor Summary
CompressedColumnMatrix(double[][] array, int fillInSpace)
          Creates a sparse matrix from the contents of 'array'.
CompressedColumnMatrix(double[][] array, int fillInSpace, double epsilon)
          Creates a sparse matrix from the contents of 'array'.
CompressedColumnMatrix(int sizeOfRows, int capacityOfColumns, int fillInSpace)
           
CompressedColumnMatrix(int sizeOfRows, int capacityOfColumns, int fillInSpace, int capacityOfElements)
           
CompressedColumnMatrix(MatrixI matrix, int fillInSpace)
           
CompressedColumnMatrix(VectorI vector, int fillInSpace)
           
 
Method Summary
 void addColumn(VectorI vector)
          Adds a new column and any non-null elements in vector to the end of the matrix .
 void addRow(VectorI vector)
          Adds a new row and any non-null elements in vector to the end of the matrix .
 void buildRowIndex()
          Build the row index structure.
 int capacityOfColumns()
          Returns the number of columns the matrix can hold without allocating more memory.
 int capacityOfRows()
          Returns the number of rows the matrix can hold without allocating more memory.
 java.util.Enumeration columnElements(int column)
          Returns an enumeration of the non-null elements in a column.
 void deleteRowIndex()
          Delete the row index structure.
 double elementAt(int row, int column)
          Gets an element's value from the matrix.
 java.util.Enumeration elements()
          Returns an enumeration of the non-null elements in the matrix.
 double[][] getArray()
          Returns a new two-dimensional array containing the values in matrix.
 int[] getColumnBeginArray()
          Return the array used to hold the index of the first element in each column.
 int[] getColumnIndexArray()
          Return the array used to hold the column indices for the row index.
 int[] getColumnSizeArray()
          Return the array used to hold the number of elements in each column.
 int[] getRowEndArray()
          Return the array used to indicate the end of each row in the row index.
 int[] getRowIndexArray()
          Return the array used to hold the row indices.
 int[] getValueIndexArray()
          Return the array used to hold the value indices for the row index.
 boolean isColumnMajor()
          Returns true if the matrix is column-major.
 boolean isNull(int row, int column)
          Returns true if an element has no value associated with it.
 boolean isRowMajor()
          Returns true if the matrix is row-major.
 java.util.Enumeration rowElements(int row)
          Returns an enumeration of the non-null elements in a row.
 void setCapacity(int capacityOfRows, int capacityOfColumns)
          Allocates memory so the matrix can hold this many rows and columns without reallocating memory.
 void setElementAt(int row, int column, double value)
          Sets an element's value in the matrix.
 void setSize(int sizeOfRows, int sizeOfColumns)
          Sets the number of rows and columns in the matrix.
 int sizeOfElements()
          Returns the number of non-null elements in the matrix.
 double sum(int rowBegin, int rowEnd, int columnBegin, int columnEnd)
          Returns the sum of all of the elements in the sub-matrix.
Computes sum(a[i][j]).
Where: i = {rowBegin,...,(rowEnd-1)}
j = {columBegin,...,(columnEnd-1)}
 double sumOfSquaredDifferences(int rowBegin, int rowEnd, int columnBegin, int columnEnd, double scaler)
          Returns the sum of the squared differences between the elements and a scaler.
Computes sum((a[i][j]-scaler)^2).
Where: i = {rowBegin,...,(rowEnd-1)}
j = {columBegin,...,(columnEnd-1)}
 double sumOfSquares(int rowBegin, int rowEnd, int columnBegin, int columnEnd)
          Returns the sum of the squares of all of the elements in the sub-matrix.
Computes sum(a[i][j]^2).
Where: i = {rowBegin,...,(rowEnd-1)}
j = {columBegin,...,(columnEnd-1)}
 
Methods inherited from class drasys.or.matrix.CompressedMatrix
getValueArray, setCapacityOfElements, setElements, sizeOfColumns, sizeOfRows
 
Methods inherited from class drasys.or.matrix.Matrix
equals, equals, setColumn, setDiagonal, setElements, setRow, sum, sum, sumOfSquaredDifferences, sumOfSquaredDifferences, sumOfSquares, sumOfSquares, toString
 
Methods inherited from class drasys.or.matrix.RealContainer
equals, getEpsilon, getGlobalEpsilon, setEpsilon, setGlobalEpsilon
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompressedColumnMatrix

public CompressedColumnMatrix(int sizeOfRows,
                              int capacityOfColumns,
                              int fillInSpace)

CompressedColumnMatrix

public CompressedColumnMatrix(int sizeOfRows,
                              int capacityOfColumns,
                              int fillInSpace,
                              int capacityOfElements)

CompressedColumnMatrix

public CompressedColumnMatrix(double[][] array,
                              int fillInSpace)
Creates a sparse matrix from the contents of 'array'. All of the elements will be added.

CompressedColumnMatrix

public CompressedColumnMatrix(double[][] array,
                              int fillInSpace,
                              double epsilon)
Creates a sparse matrix from the contents of 'array'. Elements in 'array' which equal 0.0 to within 'epsilon' will not be added. The matrix epsilon will be set to 'epsilon'.

CompressedColumnMatrix

public CompressedColumnMatrix(MatrixI matrix,
                              int fillInSpace)

CompressedColumnMatrix

public CompressedColumnMatrix(VectorI vector,
                              int fillInSpace)
Method Detail

sizeOfElements

public int sizeOfElements()
Returns the number of non-null elements in the matrix.

capacityOfColumns

public int capacityOfColumns()
Returns the number of columns the matrix can hold without allocating more memory.

capacityOfRows

public int capacityOfRows()
Returns the number of rows the matrix can hold without allocating more memory.

getRowIndexArray

public int[] getRowIndexArray()
Return the array used to hold the row indices.

getColumnSizeArray

public int[] getColumnSizeArray()
Return the array used to hold the number of elements in each column.

getColumnBeginArray

public int[] getColumnBeginArray()
Return the array used to hold the index of the first element in each column.

deleteRowIndex

public void deleteRowIndex()
Delete the row index structure.

buildRowIndex

public void buildRowIndex()
Build the row index structure.

getColumnIndexArray

public int[] getColumnIndexArray()
Return the array used to hold the column indices for the row index.
Returns:
null if the row index is not built.

getRowEndArray

public int[] getRowEndArray()
Return the array used to indicate the end of each row in the row index.
Returns:
null if the row index is not built.

getValueIndexArray

public int[] getValueIndexArray()
Return the array used to hold the value indices for the row index.
Returns:
null if the row index is not built.

isRowMajor

public boolean isRowMajor()
Returns true if the matrix is row-major.

isColumnMajor

public boolean isColumnMajor()
Returns true if the matrix is column-major.

addColumn

public void addColumn(VectorI vector)
Adds a new column and any non-null elements in vector to the end of the matrix . If 'vector' is null then no new elements will be changed in the new column.

addRow

public void addRow(VectorI vector)
Adds a new row and any non-null elements in vector to the end of the matrix . If 'vector' is null then no new elements will be modified in the new row.

setSize

public void setSize(int sizeOfRows,
                    int sizeOfColumns)
Sets the number of rows and columns in the matrix. If the new size is smaller than the original then the matrix will be emptied.

setCapacity

public void setCapacity(int capacityOfRows,
                        int capacityOfColumns)
Allocates memory so the matrix can hold this many rows and columns without reallocating memory.

setElementAt

public void setElementAt(int row,
                         int column,
                         double value)
Sets an element's value in the matrix.

isNull

public boolean isNull(int row,
                      int column)
Returns true if an element has no value associated with it. Elements which have no value assigned return 0.0 when accessed.

elementAt

public double elementAt(int row,
                        int column)
Gets an element's value from the matrix.
Tags copied from interface: MatrixI
Returns:
zero is the element is null

getArray

public double[][] getArray()
Returns a new two-dimensional array containing the values in matrix. The rows of the array hold the rows of the matrix.
Overrides:
getArray in class Matrix

rowElements

public java.util.Enumeration rowElements(int row)
Returns an enumeration of the non-null elements in a row. The elements are enumerated in random order. Builds the row index if it does not exist.
Overrides:
rowElements in class Matrix
Returns:
an enumeration whose elements are of type MatrixElementI

columnElements

public java.util.Enumeration columnElements(int column)
Returns an enumeration of the non-null elements in a column. The elements are enumerated in random order.
Overrides:
columnElements in class Matrix
Returns:
an enumeration whose elements are of type MatrixElementI

elements

public java.util.Enumeration elements()
Returns an enumeration of the non-null elements in the matrix. The elements are enumerated in random order.
Overrides:
elements in class Matrix
Returns:
an enumeration whose elements are of type MatrixElementI

sum

public double sum(int rowBegin,
                  int rowEnd,
                  int columnBegin,
                  int columnEnd)
Returns the sum of all of the elements in the sub-matrix.
Computes sum(a[i][j]).
Where: i = {rowBegin,...,(rowEnd-1)}
j = {columBegin,...,(columnEnd-1)}
Overrides:
sum in class Matrix

sumOfSquares

public double sumOfSquares(int rowBegin,
                           int rowEnd,
                           int columnBegin,
                           int columnEnd)
Returns the sum of the squares of all of the elements in the sub-matrix.
Computes sum(a[i][j]^2).
Where: i = {rowBegin,...,(rowEnd-1)}
j = {columBegin,...,(columnEnd-1)}
Overrides:
sumOfSquares in class Matrix

sumOfSquaredDifferences

public double sumOfSquaredDifferences(int rowBegin,
                                      int rowEnd,
                                      int columnBegin,
                                      int columnEnd,
                                      double scaler)
Returns the sum of the squared differences between the elements and a scaler.
Computes sum((a[i][j]-scaler)^2).
Where: i = {rowBegin,...,(rowEnd-1)}
j = {columBegin,...,(columnEnd-1)}
Overrides:
sumOfSquaredDifferences in class Matrix


Copyright(C)1997-2000 by DRA Systems all rights reserved. OpsResearch.com