LinAlg
Class ColtMatrix

java.lang.Object
  extended bycern.colt.PersistentObject
      extended bycern.colt.matrix.impl.AbstractMatrix
          extended bycern.colt.matrix.impl.AbstractMatrix2D
              extended bycern.colt.matrix.DoubleMatrix2D
                  extended bycern.colt.matrix.impl.DenseDoubleMatrix2D
                      extended byLinAlg.ColtMatrix
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class ColtMatrix
extends cern.colt.matrix.impl.DenseDoubleMatrix2D

Wrapper for cern.colt.matrix.impl.DenseDoubleMatrix2D and cern.colt.matrix.linalg.(Blas,Algebra,CholeskyDecomposition). Rewrites the Blas operations in programming notation plusEquals (+=) and timesEquals (*=) (from left and right) to maintain familiar coding syntax.

Only atomic operations fromm the Blas are wrapped. See ExtendedColtMatrix for the whole bewildering array.

See Also:
Serialized Form

Field Summary
static cern.colt.matrix.linalg.Blas blas
          cern.colt.matrix.linalg.SeqBlas (non mulTithreaded) Blas object.
static cern.colt.matrix.linalg.Algebra linAlg
          cern.colt.matrix.linalg.Algebra object with default tolerances.
 
Fields inherited from class cern.colt.matrix.impl.DenseDoubleMatrix2D
elements
 
Fields inherited from class cern.colt.matrix.impl.AbstractMatrix2D
columns, columnStride, columnZero, rows, rowStride, rowZero
 
Fields inherited from class cern.colt.matrix.impl.AbstractMatrix
isNoView
 
Constructor Summary
ColtMatrix(double[][] entries)
          Entries derived from given double[][].
ColtMatrix(int rows, int columns)
          all entries zero.
 
Method Summary
 cern.colt.matrix.linalg.CholeskyDecomposition choleskyDecomposition()
          Cholesky decomposition object arising from an attempted Cholesky decompostion of this.
 ColtMatrix choleskyRoot()
          Returns the lower triangular matrix L with A=LL' in case A is symmetric and positive definite.
 ColtVector column(int j)
          Returns the columns of this.
 ColtMatrix deepClone()
          Returns a deep copy of this.
 ColtMatrix exponential(int k)
          With A=this assumed square, computes the polyonomial
exp(A,k)=I+A+A^2/2!+...+A^{k-1}/(k-1)!,
Obviously this is the exponential of A only if A is nilpotent with A^k=0.
static ColtMatrix identityMatrix(int n)
          The identity matrix Id_n.
 ColtMatrix inverse()
          Inverse of A=this if A is square, pseudoinverse otherwise.
 boolean isDiagonal()
           
 boolean isEqual(ColtMatrix B)
          Test for equality of dimension and entry by entry equality.
 boolean isLowerTriangular()
           
 boolean isSymmetric()
           
 boolean isTriangular()
           
 boolean isUpperTriangular()
           
 void leftTimesEquals(ColtMatrix A)
          Implements the operation this=A*this.
 void leftTimesEquals(ColtMatrix A, boolean transposeA)
          Implements the operation this=A*this.
 ColtMatrix linearSystemSolution(ColtMatrix B)
          Returns the solution matrix X of the linear equation this*X=B.
 ColtVector linearSystemSolution(ColtVector y)
          Returns the solution vector x of the linear equation this*x=y.
static void main(java.lang.String[] args)
          Times the computation of nilpotent matrix exponentials.
 void plusEquals(ColtMatrix A)
          Implements the operation this+=A.
 void plusEquals(double alpha, ColtMatrix A)
          Implements the operation this+=alpha*A.
 void rightTimesEquals(ColtMatrix A)
          Implements the operation this=A*this.
 void rightTimesEquals(ColtMatrix A, boolean transposeA)
          Implements the operation this=this*A.
 ColtVector row(int i)
          Returns the rows of this.
 void scale(double alpha)
          Implements the operation this=alpha*this.
 void setFlags()
          Selfchecks for symmetry, triangularity or diagonality and sets the corresponding flags.
 ColtMatrix transpose()
          Returns the transpose of this.
 void transposeSelf()
          Transposes this.
 
Methods inherited from class cern.colt.matrix.impl.DenseDoubleMatrix2D
assign, assign, assign, assign, assign, getQuick, haveSharedCellsRaw, index, like, like1D, like1D, setQuick, viewSelectionLike, zAssign8Neighbors, zMult, zMult, zSum
 
Methods inherited from class cern.colt.matrix.DoubleMatrix2D
aggregate, aggregate, cardinality, copy, equals, equals, forEachNonZero, get, getContent, getNonZeros, haveSharedCells, like, set, toArray, toString, view, viewColumn, viewColumnFlip, viewDice, viewPart, viewRow, viewRowFlip, viewSelection, viewSelection, viewSorted, viewStrides, zMult, zMult
 
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix2D
_columnOffset, _columnRank, _rowOffset, _rowRank, checkBox, checkColumn, checkColumnIndexes, checkRow, checkRowIndexes, checkShape, checkShape, columns, rows, setUp, setUp, size, toStringShort, vColumnFlip, vDice, vPart, vRowFlip, vStrides
 
Methods inherited from class cern.colt.matrix.impl.AbstractMatrix
ensureCapacity, isView, trimToSize
 
Methods inherited from class cern.colt.PersistentObject
clone
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

linAlg

public static final cern.colt.matrix.linalg.Algebra linAlg
cern.colt.matrix.linalg.Algebra object with default tolerances. Has some basic linear algreba routines.


blas

public static final cern.colt.matrix.linalg.Blas blas
cern.colt.matrix.linalg.SeqBlas (non mulTithreaded) Blas object. Has some basic linear algebra routines.

Constructor Detail

ColtMatrix

public ColtMatrix(double[][] entries)

Entries derived from given double[][].

Parameters:
entries - the matrix entries.

ColtMatrix

public ColtMatrix(int rows,
                  int columns)
all entries zero.

Method Detail

identityMatrix

public static ColtMatrix identityMatrix(int n)

The identity matrix Id_n.

Parameters:
n - dimension.

isUpperTriangular

public boolean isUpperTriangular()

isLowerTriangular

public boolean isLowerTriangular()

isTriangular

public boolean isTriangular()

isDiagonal

public boolean isDiagonal()

isSymmetric

public boolean isSymmetric()

setFlags

public void setFlags()
Selfchecks for symmetry, triangularity or diagonality and sets the corresponding flags.


deepClone

public ColtMatrix deepClone()

Returns a deep copy of this.


row

public ColtVector row(int i)

Returns the rows of this.

Parameters:
i - row index.

column

public ColtVector column(int j)

Returns the columns of this.

Parameters:
j - column index.

isEqual

public boolean isEqual(ColtMatrix B)
Test for equality of dimension and entry by entry equality.


transpose

public ColtMatrix transpose()
Returns the transpose of this.


transposeSelf

public void transposeSelf()
Transposes this. The matrix must be square. No new memory allocated.


scale

public void scale(double alpha)

Implements the operation this=alpha*this.

Parameters:
alpha - scaling factor.

inverse

public ColtMatrix inverse()
Inverse of A=this if A is square, pseudoinverse otherwise.


plusEquals

public void plusEquals(double alpha,
                       ColtMatrix A)

Implements the operation this+=alpha*A.


plusEquals

public void plusEquals(ColtMatrix A)

Implements the operation this+=A.


leftTimesEquals

public void leftTimesEquals(ColtMatrix A,
                            boolean transposeA)

Implements the operation this=A*this. A is transposed if the parameter transposeA is set to true.

Parameters:
A - multiplies this on the left.

leftTimesEquals

public void leftTimesEquals(ColtMatrix A)

Implements the operation this=A*this.

Parameters:
A - multiplies this on the left.

rightTimesEquals

public void rightTimesEquals(ColtMatrix A,
                             boolean transposeA)

Implements the operation this=this*A. A is transposed if the parameter transposeA is set to true.

Parameters:
A - multiplies this on the right.

rightTimesEquals

public void rightTimesEquals(ColtMatrix A)

Implements the operation this=A*this.

Parameters:
A - multiplies this on the left.

linearSystemSolution

public ColtMatrix linearSystemSolution(ColtMatrix B)

Returns the solution matrix X of the linear equation this*X=B. Exact solution if this is square, least squares solution otherwise. Simultaneous solution of linear systems Ax=b, where b ranges over the columns of B. The columns of X are the solution vectors.

Parameters:
B - matrix of right hand sides (columns).

linearSystemSolution

public ColtVector linearSystemSolution(ColtVector y)
Returns the solution vector x of the linear equation this*x=y. Exact solution if this is square, least squares solution otherwise.

Parameters:
y - right hand side.

choleskyDecomposition

public cern.colt.matrix.linalg.CholeskyDecomposition choleskyDecomposition()
Cholesky decomposition object arising from an attempted Cholesky decompostion of this. Has some functionality in addition to producing the lower triangular matrix L with A=LL' in case A is symmetric and positive definite. See the cern.colt.matrix.linalg.CholeskyDecomposition documentation.


choleskyRoot

public ColtMatrix choleskyRoot()
Returns the lower triangular matrix L with A=LL' in case A is symmetric and positive definite. Exits and aborts if A is not symmetric and positive definite.


exponential

public ColtMatrix exponential(int k)

With A=this assumed square, computes the polyonomial

exp(A,k)=I+A+A^2/2!+...+A^{k-1}/(k-1)!,

Obviously this is the exponential of A only if A is nilpotent with A^k=0. Suboptimal implementation because of repeated calls to atomic methods. It could be worth it to use the dgemm BLAS methods.

Parameters:
k - length of expansion of exponential series.

main

public static void main(java.lang.String[] args)
Times the computation of nilpotent matrix exponentials. 10000 exponentials of a 40 by 40 upper triangular matrix with zero diagonal take 6.25 minutes.