Mobios v0.91

mobios.util
Class LargeDenseDoubleMatrix2D

java.lang.Object
  extended by cern.colt.PersistentObject
      extended by cern.colt.matrix.impl.AbstractMatrix
          extended by cern.colt.matrix.impl.AbstractMatrix2D
              extended by cern.colt.matrix.DoubleMatrix2D
                  extended by mobios.util.LargeDenseDoubleMatrix2D
All Implemented Interfaces:
Serializable, Cloneable

public class LargeDenseDoubleMatrix2D
extends cern.colt.matrix.DoubleMatrix2D

Large Dense 2-d matrix holding double elements. It aims at huge matrix whose elements can not be stored in a single array. For matrices that are not that large, consider DenseDoubleMatrix2D.

Implementation:

Internally holds a two-dimensional double array, consistent to the topology of the matrix . Note that this implementation is not synchronized.

Version:
2006.06.15
Author:
Rui Mao
See Also:
Serialized Form

Field Summary
static long sizeGate
           
 
Constructor Summary
LargeDenseDoubleMatrix2D(double[][] values)
          Constructs a matrix with a copy of the given values.
LargeDenseDoubleMatrix2D(int rows, int columns)
          Constructs a matrix with a given number of rows and columns.
 
Method Summary
 double aggregate(cern.colt.function.DoubleDoubleFunction aggr, cern.colt.function.DoubleFunction f)
           
 double aggregate(cern.colt.matrix.DoubleMatrix2D other, cern.colt.function.DoubleDoubleFunction aggr, cern.colt.function.DoubleDoubleFunction f)
           
 cern.colt.matrix.DoubleMatrix2D assign(double value)
          Sets all cells to the state specified by value.
 cern.colt.matrix.DoubleMatrix2D assign(double[][] values)
          Sets all cells to the state specified by values.
 cern.colt.matrix.DoubleMatrix2D assign(cern.colt.function.DoubleFunction function)
          Assigns the result of a function to each cell; x[row,col] = function(x[row,col]).
 cern.colt.matrix.DoubleMatrix2D assign(cern.colt.matrix.DoubleMatrix2D source)
          Replaces all cell values of the receiver with the values of another matrix.
 cern.colt.matrix.DoubleMatrix2D assign(cern.colt.matrix.DoubleMatrix2D y, cern.colt.function.DoubleDoubleFunction function)
          Assigns the result of a function to each cell; x[row,col] = function(x[row,col],y[row,col]).
 int cardinality()
           
 void checkShape(cern.colt.matrix.impl.AbstractMatrix2D B)
           
 void checkShape(cern.colt.matrix.impl.AbstractMatrix2D B, cern.colt.matrix.impl.AbstractMatrix2D C)
           
 int columns()
           
 cern.colt.matrix.DoubleMatrix2D copy()
           
static cern.colt.matrix.DoubleMatrix2D covariance(cern.colt.matrix.DoubleMatrix2D matrix, boolean trans)
          Constructs and returns the covariance matrix of the given matrix.
static cern.colt.matrix.DoubleMatrix2D createDoubleMatrix2D(int row, int column)
          Create a DoubleMatrix2D of the given size.
static cern.colt.matrix.DoubleMatrix2D distance(cern.colt.matrix.DoubleMatrix2D matrix, boolean trans, cern.colt.matrix.doublealgo.Statistic.VectorVectorFunction distanceFunction)
          Constructs and returns the distance matrix of the given matrix.
 void ensureCapacity(int minNonZeros)
           
 boolean equals(double value)
           
 boolean equals(Object obj)
           
 cern.colt.matrix.DoubleMatrix2D forEachNonZero(cern.colt.function.IntIntDoubleFunction function)
           
 double get(int row, int column)
           
 void getNonZeros(cern.colt.list.IntArrayList rowList, cern.colt.list.IntArrayList columnList, cern.colt.list.DoubleArrayList valueList)
           
 double getQuick(int row, int column)
          Returns the matrix cell value at coordinate [row,column].
static boolean isLarge(int row, int column)
           
 cern.colt.matrix.DoubleMatrix2D like()
           
 cern.colt.matrix.DoubleMatrix2D like(int rows, int columns)
          Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified number of rows and columns.
 cern.colt.matrix.DoubleMatrix1D like1D(int size)
          Construct and returns a new 1-d matrix of the corresponding dynamic type, entirelly independent of the receiver.
static cern.colt.matrix.DoubleMatrix2D mult(cern.colt.matrix.DoubleMatrix2D a, boolean aTrans, cern.colt.matrix.DoubleMatrix2D b, boolean bTrans)
          return the matrix production of two matrix.
 int rows()
           
 void set(int row, int column, double value)
           
 void setQuick(int row, int column, double value)
          Sets the matrix cell at coordinate [row,column] to the specified value.
 int size()
           
 double[][] toArray()
           
 String toString()
           
 String toStringShort()
           
 void trimToSize()
           
 cern.colt.matrix.DoubleMatrix1D viewColumn(int column)
           
 cern.colt.matrix.DoubleMatrix2D viewColumnFlip()
           
 cern.colt.matrix.DoubleMatrix2D viewDice()
           
 cern.colt.matrix.DoubleMatrix2D viewPart(int row, int column, int height, int width)
           
 cern.colt.matrix.DoubleMatrix1D viewRow(int row)
           
 cern.colt.matrix.DoubleMatrix2D viewRowFlip()
           
 cern.colt.matrix.DoubleMatrix2D viewSelection(cern.colt.matrix.DoubleMatrix1DProcedure condition)
           
 cern.colt.matrix.DoubleMatrix2D viewSelection(int[] rowIndexes, int[] columnIndexes)
           
 cern.colt.matrix.DoubleMatrix2D viewSorted(int column)
           
 cern.colt.matrix.DoubleMatrix2D viewStrides(int rowStride, int columnStride)
           
 void zAssign8Neighbors(cern.colt.matrix.DoubleMatrix2D B, cern.colt.function.Double9Function function)
          8 neighbor stencil transformation.
 cern.colt.matrix.DoubleMatrix1D zMult(cern.colt.matrix.DoubleMatrix1D y, cern.colt.matrix.DoubleMatrix1D z)
           
 cern.colt.matrix.DoubleMatrix1D zMult(cern.colt.matrix.DoubleMatrix1D y, cern.colt.matrix.DoubleMatrix1D z, double alpha, double beta, boolean transposeA)
           
 cern.colt.matrix.DoubleMatrix2D zMult(cern.colt.matrix.DoubleMatrix2D B, cern.colt.matrix.DoubleMatrix2D C)
           
 cern.colt.matrix.DoubleMatrix2D zMult(cern.colt.matrix.DoubleMatrix2D B, cern.colt.matrix.DoubleMatrix2D C, double alpha, double beta, boolean transposeA, boolean transposeB)
           
 double zSum()
          Returns the sum of all cells; Sum( x[i,j] ).
 
Methods inherited from class cern.colt.PersistentObject
clone
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sizeGate

public static final long sizeGate
See Also:
Constant Field Values
Constructor Detail

LargeDenseDoubleMatrix2D

public LargeDenseDoubleMatrix2D(double[][] values)
Constructs a matrix with a copy of the given values. values is required to have the form values[row][column] and have exactly the same number of columns in every row.

The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.

Parameters:
values - The values to be filled into the new matrix.
Throws:
IllegalArgumentException - if for any 1 <= row < values.length: values[row].length != values[row-1].length.

LargeDenseDoubleMatrix2D

public LargeDenseDoubleMatrix2D(int rows,
                                int columns)
Constructs a matrix with a given number of rows and columns. All entries are initially 0.

Parameters:
rows - the number of rows the matrix shall have.
columns - the number of columns the matrix shall have.
Throws:
IllegalArgumentException - if rows<0 || columns<0 || (double)columns*rows > Integer.MAX_VALUE.
Method Detail

assign

public cern.colt.matrix.DoubleMatrix2D assign(double[][] values)
Sets all cells to the state specified by values. values is required to have the form values[row][column] and have exactly the same number of rows and columns as the receiver.

The values are copied. So subsequent changes in values are not reflected in the matrix, and vice-versa.

Overrides:
assign in class cern.colt.matrix.DoubleMatrix2D
Parameters:
values - the values to be filled into the cells.
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if values.length != rows() || for any 0 <= row < rows(): values[row].length != columns().

assign

public cern.colt.matrix.DoubleMatrix2D assign(double value)
Sets all cells to the state specified by value.

Overrides:
assign in class cern.colt.matrix.DoubleMatrix2D
Parameters:
value - the value to be filled into the cells.
Returns:
this (for convenience only).

assign

public cern.colt.matrix.DoubleMatrix2D assign(cern.colt.function.DoubleFunction function)
Assigns the result of a function to each cell; x[row,col] = function(x[row,col]).

Example:

          matrix = 2 x 2 matrix
          0.5 1.5      
          2.5 3.5
     
          // change each cell to its sine
          matrix.assign(cern.jet.math.Functions.sin);
          -->
          2 x 2 matrix
          0.479426  0.997495 
          0.598472 -0.350783
 
For further examples, see the package doc.

Overrides:
assign in class cern.colt.matrix.DoubleMatrix2D
Parameters:
function - a function object taking as argument the current cell's value.
Returns:
this (for convenience only).
See Also:
Functions

assign

public cern.colt.matrix.DoubleMatrix2D assign(cern.colt.matrix.DoubleMatrix2D source)
Replaces all cell values of the receiver with the values of another matrix. Both matrices must have the same number of rows and columns. If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces as if using an intermediate auxiliary deep copy of other.

Overrides:
assign in class cern.colt.matrix.DoubleMatrix2D
Parameters:
source - the source matrix to copy from (may be identical to the receiver).
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if columns() != source.columns() || rows() != source.rows()

assign

public cern.colt.matrix.DoubleMatrix2D assign(cern.colt.matrix.DoubleMatrix2D y,
                                              cern.colt.function.DoubleDoubleFunction function)
Assigns the result of a function to each cell; x[row,col] = function(x[row,col],y[row,col]).

Example:

          // assign x[row,col] = x[row,col]<sup>y[row,col]</sup>
          m1 = 2 x 2 matrix 
          0 1 
          2 3
     
          m2 = 2 x 2 matrix 
          0 2 
          4 6
     
          m1.assign(m2, cern.jet.math.Functions.pow);
          -->
          m1 == 2 x 2 matrix
          1   1 
          16 729
 
For further examples, see the package doc.

Overrides:
assign in class cern.colt.matrix.DoubleMatrix2D
Parameters:
y - the secondary matrix to operate on.
function - a function object taking as first argument the current cell's value of this, and as second argument the current cell's value of y,
Returns:
this (for convenience only).
Throws:
IllegalArgumentException - if columns() != other.columns() || rows() != other.rows()
See Also:
Functions

getQuick

public double getQuick(int row,
                       int column)
Returns the matrix cell value at coordinate [row,column].

Provided with invalid parameters this method may return invalid objects without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): 0 <= column < columns() && 0 <= row < rows().

Specified by:
getQuick in class cern.colt.matrix.DoubleMatrix2D
Parameters:
row - the index of the row-coordinate.
column - the index of the column-coordinate.
Returns:
the value at the specified coordinate.

like

public cern.colt.matrix.DoubleMatrix2D like(int rows,
                                            int columns)
Construct and returns a new empty matrix of the same dynamic type as the receiver, having the specified number of rows and columns. For example, if the receiver is an instance of type DenseDoubleMatrix2D the new matrix must also be of type DenseDoubleMatrix2D, if the receiver is an instance of type SparseDoubleMatrix2D the new matrix must also be of type SparseDoubleMatrix2D, etc. In general, the new matrix should have internal parametrization as similar as possible.

Specified by:
like in class cern.colt.matrix.DoubleMatrix2D
Parameters:
rows - the number of rows the matrix shall have.
columns - the number of columns the matrix shall have.
Returns:
a new empty matrix of the same dynamic type.

like1D

public cern.colt.matrix.DoubleMatrix1D like1D(int size)
Construct and returns a new 1-d matrix of the corresponding dynamic type, entirelly independent of the receiver. For example, if the receiver is an instance of type DenseDoubleMatrix2D the new matrix must be of type DenseDoubleMatrix1D, if the receiver is an instance of type SparseDoubleMatrix2D the new matrix must be of type SparseDoubleMatrix1D, etc.

Specified by:
like1D in class cern.colt.matrix.DoubleMatrix2D
Parameters:
size - the number of cells the matrix shall have.
Returns:
a new matrix of the corresponding dynamic type.

setQuick

public void setQuick(int row,
                     int column,
                     double value)
Sets the matrix cell at coordinate [row,column] to the specified value.

Provided with invalid parameters this method may access illegal indexes without throwing any exception. You should only use this method when you are absolutely sure that the coordinate is within bounds. Precondition (unchecked): 0 <= column < columns() && 0 <= row < rows().

Specified by:
setQuick in class cern.colt.matrix.DoubleMatrix2D
Parameters:
row - the index of the row-coordinate.
column - the index of the column-coordinate.
value - the value to be filled into the specified cell.

zAssign8Neighbors

public void zAssign8Neighbors(cern.colt.matrix.DoubleMatrix2D B,
                              cern.colt.function.Double9Function function)
8 neighbor stencil transformation. For efficient finite difference operations. Applies a function to a moving 3 x 3 window. Does nothing if rows() < 3 || columns() < 3.
          B[i,j] = function.apply(
             A[i-1,j-1], A[i-1,j], A[i-1,j+1],
             A[i,  j-1], A[i,  j], A[i,  j+1],
             A[i+1,j-1], A[i+1,j], A[i+1,j+1]
             )
     
          x x x -     - x x x     - - - - 
          x o x -     - x o x     - - - - 
          x x x -     - x x x ... - x x x 
          - - - -     - - - -     - x o x 
          - - - -     - - - -     - x x x 
 
Make sure that cells of this and B do not overlap. In case of overlapping views, behaviour is unspecified.

Example:

 
 final double alpha = 0.25; final double beta = 0.75; // 8 neighbors
 cern.colt.function.Double9Function f = new cern.colt.function.Double9Function() {
    public final double apply(       double a00,
 double a01, double a02,       double a10, double a11, double
 a12,       double a20, double a21, double a22) {
          return beta*a11 + alpha*(a00+a01+a02 +
 a10+a12 + a20+a21+a22);       } }; A.zAssign8Neighbors(B,f); //
 4 neighbors cern.colt.function.Double9Function g = new cern.colt.function.Double9Function() {
    public final double apply(       double a00,
 double a01, double a02,       double a10, double a11, double
 a12,       double a20, double a21, double a22) {
       return beta*a11 + alpha*(a01+a10+a12+a21);
    } C.zAssign8Neighbors(B,g); // fast, even though it doesn't look like it };
 
 

Overrides:
zAssign8Neighbors in class cern.colt.matrix.DoubleMatrix2D
Parameters:
B - the matrix to hold the results.
function - the function to be applied to the 9 cells.
Throws:
NullPointerException - if function==null.
IllegalArgumentException - if rows() != B.rows() || columns() != B.columns().

zMult

public cern.colt.matrix.DoubleMatrix1D zMult(cern.colt.matrix.DoubleMatrix1D y,
                                             cern.colt.matrix.DoubleMatrix1D z,
                                             double alpha,
                                             double beta,
                                             boolean transposeA)
Overrides:
zMult in class cern.colt.matrix.DoubleMatrix2D

zMult

public cern.colt.matrix.DoubleMatrix2D zMult(cern.colt.matrix.DoubleMatrix2D B,
                                             cern.colt.matrix.DoubleMatrix2D C,
                                             double alpha,
                                             double beta,
                                             boolean transposeA,
                                             boolean transposeB)
Overrides:
zMult in class cern.colt.matrix.DoubleMatrix2D

zSum

public double zSum()
Returns the sum of all cells; Sum( x[i,j] ).

Overrides:
zSum in class cern.colt.matrix.DoubleMatrix2D
Returns:
the sum.

ensureCapacity

public void ensureCapacity(int minNonZeros)
Overrides:
ensureCapacity in class cern.colt.matrix.impl.AbstractMatrix

trimToSize

public void trimToSize()
Overrides:
trimToSize in class cern.colt.matrix.impl.AbstractMatrix

checkShape

public void checkShape(cern.colt.matrix.impl.AbstractMatrix2D B)
Overrides:
checkShape in class cern.colt.matrix.impl.AbstractMatrix2D

checkShape

public void checkShape(cern.colt.matrix.impl.AbstractMatrix2D B,
                       cern.colt.matrix.impl.AbstractMatrix2D C)
Overrides:
checkShape in class cern.colt.matrix.impl.AbstractMatrix2D

toStringShort

public String toStringShort()
Overrides:
toStringShort in class cern.colt.matrix.impl.AbstractMatrix2D

aggregate

public double aggregate(cern.colt.function.DoubleDoubleFunction aggr,
                        cern.colt.function.DoubleFunction f)
Overrides:
aggregate in class cern.colt.matrix.DoubleMatrix2D

aggregate

public double aggregate(cern.colt.matrix.DoubleMatrix2D other,
                        cern.colt.function.DoubleDoubleFunction aggr,
                        cern.colt.function.DoubleDoubleFunction f)
Overrides:
aggregate in class cern.colt.matrix.DoubleMatrix2D

cardinality

public int cardinality()
Overrides:
cardinality in class cern.colt.matrix.DoubleMatrix2D

copy

public cern.colt.matrix.DoubleMatrix2D copy()
Overrides:
copy in class cern.colt.matrix.DoubleMatrix2D

equals

public boolean equals(double value)
Overrides:
equals in class cern.colt.matrix.DoubleMatrix2D

equals

public boolean equals(Object obj)
Overrides:
equals in class cern.colt.matrix.DoubleMatrix2D

forEachNonZero

public cern.colt.matrix.DoubleMatrix2D forEachNonZero(cern.colt.function.IntIntDoubleFunction function)
Overrides:
forEachNonZero in class cern.colt.matrix.DoubleMatrix2D

get

public double get(int row,
                  int column)
Overrides:
get in class cern.colt.matrix.DoubleMatrix2D

getNonZeros

public void getNonZeros(cern.colt.list.IntArrayList rowList,
                        cern.colt.list.IntArrayList columnList,
                        cern.colt.list.DoubleArrayList valueList)
Overrides:
getNonZeros in class cern.colt.matrix.DoubleMatrix2D

like

public cern.colt.matrix.DoubleMatrix2D like()
Overrides:
like in class cern.colt.matrix.DoubleMatrix2D

set

public void set(int row,
                int column,
                double value)
Overrides:
set in class cern.colt.matrix.DoubleMatrix2D

toArray

public double[][] toArray()
Overrides:
toArray in class cern.colt.matrix.DoubleMatrix2D

toString

public String toString()
Overrides:
toString in class cern.colt.matrix.DoubleMatrix2D

viewColumn

public cern.colt.matrix.DoubleMatrix1D viewColumn(int column)
Overrides:
viewColumn in class cern.colt.matrix.DoubleMatrix2D

viewColumnFlip

public cern.colt.matrix.DoubleMatrix2D viewColumnFlip()
Overrides:
viewColumnFlip in class cern.colt.matrix.DoubleMatrix2D

viewDice

public cern.colt.matrix.DoubleMatrix2D viewDice()
Overrides:
viewDice in class cern.colt.matrix.DoubleMatrix2D

viewPart

public cern.colt.matrix.DoubleMatrix2D viewPart(int row,
                                                int column,
                                                int height,
                                                int width)
Overrides:
viewPart in class cern.colt.matrix.DoubleMatrix2D

viewRow

public cern.colt.matrix.DoubleMatrix1D viewRow(int row)
Overrides:
viewRow in class cern.colt.matrix.DoubleMatrix2D

viewRowFlip

public cern.colt.matrix.DoubleMatrix2D viewRowFlip()
Overrides:
viewRowFlip in class cern.colt.matrix.DoubleMatrix2D

viewSelection

public cern.colt.matrix.DoubleMatrix2D viewSelection(cern.colt.matrix.DoubleMatrix1DProcedure condition)
Overrides:
viewSelection in class cern.colt.matrix.DoubleMatrix2D

viewSelection

public cern.colt.matrix.DoubleMatrix2D viewSelection(int[] rowIndexes,
                                                     int[] columnIndexes)
Overrides:
viewSelection in class cern.colt.matrix.DoubleMatrix2D

viewSorted

public cern.colt.matrix.DoubleMatrix2D viewSorted(int column)
Overrides:
viewSorted in class cern.colt.matrix.DoubleMatrix2D

viewStrides

public cern.colt.matrix.DoubleMatrix2D viewStrides(int rowStride,
                                                   int columnStride)
Overrides:
viewStrides in class cern.colt.matrix.DoubleMatrix2D

zMult

public cern.colt.matrix.DoubleMatrix1D zMult(cern.colt.matrix.DoubleMatrix1D y,
                                             cern.colt.matrix.DoubleMatrix1D z)
Overrides:
zMult in class cern.colt.matrix.DoubleMatrix2D

zMult

public cern.colt.matrix.DoubleMatrix2D zMult(cern.colt.matrix.DoubleMatrix2D B,
                                             cern.colt.matrix.DoubleMatrix2D C)
Overrides:
zMult in class cern.colt.matrix.DoubleMatrix2D

columns

public int columns()
Overrides:
columns in class cern.colt.matrix.impl.AbstractMatrix2D

rows

public int rows()
Overrides:
rows in class cern.colt.matrix.impl.AbstractMatrix2D

size

public int size()
Overrides:
size in class cern.colt.matrix.impl.AbstractMatrix2D

createDoubleMatrix2D

public static cern.colt.matrix.DoubleMatrix2D createDoubleMatrix2D(int row,
                                                                   int column)
Create a DoubleMatrix2D of the given size. If the size is huge, create a LargeDenseDoubleMatrix2D, otherwise create a DenseDoubleMatrix2D.

Parameters:
row -
column -
Returns:

isLarge

public static boolean isLarge(int row,
                              int column)

mult

public static cern.colt.matrix.DoubleMatrix2D mult(cern.colt.matrix.DoubleMatrix2D a,
                                                   boolean aTrans,
                                                   cern.colt.matrix.DoubleMatrix2D b,
                                                   boolean bTrans)
return the matrix production of two matrix.

Parameters:
a -
aTrans - whether a's transposition should be used
b -
bTrans - whether b's transposition should be used
Returns:

covariance

public static cern.colt.matrix.DoubleMatrix2D covariance(cern.colt.matrix.DoubleMatrix2D matrix,
                                                         boolean trans)
Constructs and returns the covariance matrix of the given matrix. (covariance between columns of the given matrix) The covariance matrix is a square, symmetric matrix consisting of nothing but covariance coefficients. The rows and the columns represent the variables, the cells represent covariance coefficients. The diagonal cells (i.e. the covariance between a variable and itself) will equal the variances. The covariance of two column vectors x and y is given by cov(x,y) = (1/n) * Sum((x[i]-mean(x)) * (y[i]-mean(y))). See the math definition. Compares two column vectors at a time. Use dice views to compare two row vectors at a time.

Parameters:
matrix - any matrix; a column holds the values of a given variable.
trans - whether the matrix's transposition should be used instead of the matrix itself
Returns:
the covariance matrix (n x n, n=matrix.columns).

distance

public static cern.colt.matrix.DoubleMatrix2D distance(cern.colt.matrix.DoubleMatrix2D matrix,
                                                       boolean trans,
                                                       cern.colt.matrix.doublealgo.Statistic.VectorVectorFunction distanceFunction)
Constructs and returns the distance matrix of the given matrix. The distance matrix is a square, symmetric matrix consisting of nothing but distance coefficients. The rows and the columns represent the variables, the cells represent distance coefficients. The diagonal cells (i.e. the distance between a variable and itself) will be zero. Compares two column vectors at a time. Use dice views to compare two row vectors at a time. Note: currently, for LargeDenseDoubleMatrix2D, only support euclidean distance

Parameters:
matrix - any matrix; a column holds the values of a given variable (vector).
trans - whether the input matrix should be transposed
distanceFunction - (EUCLID, CANBERRA, ..., or any user defined distance function operating on two vectors).
Returns:
the distance matrix (n x n, n=matrix.columns).

Mobios v0.91

(C) 2002 - 2006 The MoBIoS Group