@CodeReview(reviewer="Jonathan McClain", date="2006-05-18", changesNeeded=true, comments="Comments marked throughout the file with / / / on first column.", response=@CodeReviewResponse(respondent="Kevin R. Dixon",date="2006-05-18",moreChangesNeeded=false,comments={"Added an assertion to dotTimesEquals","Commented the private classes so that they\'re up to snuff."})) @PublicationReference(author="Bjorn-Ove Heimsund", title="Matrix Toolkits for Java (MTJ)", type=WebPage, year=2006, url="http://ressim.berlios.de/", notes="All subclasses essentially wrap one of MTJ\'s matrix classes.") @SoftwareReference(name="Matrix Toolkits for Java (MTJ)", version="0.9.6", url="http://ressim.berlios.de/", license=LGPL, licenseVersion="2.1", licenseURL="http://ressim.berlios.de/") public abstract class AbstractMTJMatrix extends AbstractMatrix
Modifier | Constructor and Description |
---|---|
protected |
AbstractMTJMatrix(no.uib.cipr.matrix.Matrix internalMatrix)
Creates a new instance of AbstractMTJMatrix
|
Modifier and Type | Method and Description |
---|---|
AbstractMTJMatrix |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
void |
convertFromVector(Vector parameters)
uploads a matrix from a column-stacked vector of parameters, so that
v(k) = A(i,j) = A( k%M, k/M )
|
Vector |
convertToVector()
Creates a column-stacked version of this, so that
v(k) = A(i,j) = v(j*M+i)
|
void |
dotTimesEquals(AbstractMTJMatrix matrix)
Inline element-wise multiplication of the elements in
this
and matrix , modifies the elements of this |
void |
dotTimesEquals(Matrix other)
Inline element-wise multiplication of
this and
other |
boolean |
equals(AbstractMTJMatrix matrix,
double effectiveZero)
Determines if the matrices are effectively equal to each other
|
double |
get(int rowIndex,
int columnIndex)
Gets the value of the element of the matrix at the zero-based row and
column indices.
|
double |
getElement(int rowIndex,
int columnIndex)
Gets the Matrix element at the specified zero-based indices
throws ArrayIndexOutOfBoundsException if either rowIndex or columnIndex
are less than 0, or greater than the number of rows (columns) minus one
(0 <= index <= num-1)
|
no.uib.cipr.matrix.Matrix |
getInternalMatrix()
Gets the internal MTJ matrix that this class is wrapping.
|
int |
getNumColumns()
Returns the number of columns in the Matrix
|
int |
getNumRows()
Returns the number of rows in the Matrix
|
protected void |
getSubMatrixInto(int minRow,
int maxRow,
int minColumn,
int maxColumn,
AbstractMTJMatrix destinationMatrix)
Internal routine for storing a submatrix into and AbstractMTJMatrix.
|
void |
identity()
Formats the matrix as an identity matrix.
|
void |
increment(int row,
int column,
double value)
Increments the value at the given position by the given value.
|
Matrix |
inverse()
Computes the full-blown inverse of
this , which must be a
square matrix |
boolean |
isSquare()
Determines if the matrix is square (numRows == numColumns)
|
boolean |
isSymmetric(double effectiveZero)
Determines if the matrix is effectively symmetric
|
java.util.Iterator<MatrixEntry> |
iterator() |
ComplexNumber |
logDeterminant()
Computes the natural logarithm of the determinant of
this . |
void |
minusEquals(AbstractMTJMatrix matrix)
Subtracts the elements of
matrix from the elements of
this , modifies the elements of this |
void |
minusEquals(Matrix other)
Inline arithmetic subtraction of
other from
this |
double |
normFrobenius()
Compute the Frobenius norm of
this , which is just a fancy
way of saying that I will square each element, add those up, and square
root the result. |
double |
normFrobeniusSquared()
Compute the squared Frobenius norm of
this , which is just a
fancy way of saying that I will square each element and add those up. |
void |
plusEquals(AbstractMTJMatrix matrix)
Inline addition of
this and matrix , modifies
the elements of this |
void |
plusEquals(Matrix other)
Inline arithmetic addition of
this and other |
int |
rank(double effectiveZero)
Computes the effective rank of
this , which is the number of
linearly independent rows and columns in this . |
void |
scaledMinusEquals(double scaleFactor,
AbstractMTJMatrix other)
Subtracts from this matrix the scaled version of the other given matrix.
|
void |
scaledPlusEquals(double scaleFactor,
AbstractMTJMatrix other)
Adds to this vector the scaled version of the other given vector.
|
void |
scaledPlusEquals(double scaleFactor,
Matrix other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor . |
void |
scaleEquals(double scaleFactor)
Inline element-wise scaling of
this by
scaleFactor |
void |
set(int rowIndex,
int columnIndex,
double value)
Sets the value of the element of the matrix at the zero-based row and
column indices.
|
void |
setElement(int rowIndex,
int columnIndex,
double value)
Sets the Matrix element at the specified zero-based indices
throws ArrayIndexOutOfBoundsException if either rowIndex or columnIndex
are less than 0, or greater than the number of rows (columns) minus one
(0 <= index <= num-1)
|
protected void |
setInternalMatrix(no.uib.cipr.matrix.Matrix internalMatrix)
Setter for internalMatrix
|
Matrix |
solve(AbstractMTJMatrix B)
Solves for "X" in the equation this * X = B, where X is a DenseMatrix,
"this" and "B" will be converted to a DenseMatrix (if not already)
|
Vector |
solve(AbstractMTJVector b)
Solves for "x" in the equation: this*x = b
|
Matrix |
solve(Matrix B)
Solves for "X" in the equation: this*X = B
|
Vector |
solve(Vector b)
Solves for "x" in the equation: this*x = b
|
abstract AbstractMTJMatrix |
times(AbstractMTJMatrix matrix)
Matrix multiplication of
this and matrix ,
operates like the "* " operator in Matlab |
abstract AbstractMTJVector |
times(AbstractMTJVector vector)
Returns the column vector from the equation
return = this * vector
|
Matrix |
times(Matrix matrix)
Matrix multiplication of
this and matrix ,
operates like the "* " operator in Matlab |
Vector |
times(Vector vector)
Returns the column vector from the equation
return = this * vector
|
protected void |
timesInto(AbstractMTJMatrix multiplicationMatrix,
AbstractMTJMatrix destinationMatrix)
Internal function call that stores the result of a matrix multiply
into the given destinationMatrix.
|
protected void |
timesInto(AbstractMTJVector multiplicationVector,
AbstractMTJVector destinationVector)
Internal function call that stores the result of a matrix multiply
into the given destinationVector.
|
protected void |
transposeInto(AbstractMTJMatrix destinationMatrix)
Internal method for accessing MTJ's general transpose routine
|
void |
zero()
Zeros out all elements of
this , so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 ); |
assertMultiplicationDimensions, assertSameDimensions, checkMultiplicationDimensions, checkSameDimensions, decrement, decrement, dotDivide, dotDivideEquals, equals, equals, getColumnInto, getRowInto, hashCode, increment, isSymmetric, isZero, pseudoInverse, rank, setColumn, setRow, setSubMatrix, sumOfColumns, sumOfRows, toArray, trace, valuesAsList
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getColumn, getEntryCount, getMatrixFactory, getRow, getSubMatrix, isSparse, pseudoInverse, toString, toString, transpose
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
protected AbstractMTJMatrix(no.uib.cipr.matrix.Matrix internalMatrix)
internalMatrix
- MTJ-based matrix to store inside of thispublic AbstractMTJMatrix clone()
AbstractCloneableSerializable
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface Matrix
clone
in interface Vectorizable
clone
in interface Ring<Matrix>
clone
in interface CloneableSerializable
clone
in class AbstractRing<Matrix>
public no.uib.cipr.matrix.Matrix getInternalMatrix()
protected void setInternalMatrix(no.uib.cipr.matrix.Matrix internalMatrix)
internalMatrix
- internal MTJ-based matrixpublic int getNumRows()
Matrix
public int getNumColumns()
Matrix
public double get(int rowIndex, int columnIndex)
Matrix
getElement
.rowIndex
- The zero-based row index. Must be between 0 (inclusive) and the
number of rows (exclusive).columnIndex
- The zero-based column index. Must be between 0 (inclusive) and the
number of columns (exclusive).public void set(int rowIndex, int columnIndex, double value)
Matrix
setElement
.rowIndex
- The zero-based row index. Must be between 0 (inclusive) and the
number of rows (exclusive).columnIndex
- The zero-based column index. Must be between 0 (inclusive) and the
number of columns (exclusive).value
- The value to set at the given row and column in the matrix.public double getElement(int rowIndex, int columnIndex)
Matrix
rowIndex
- Zero-based index into the MatrixcolumnIndex
- Zero-based index into the Matrixpublic void setElement(int rowIndex, int columnIndex, double value)
Matrix
rowIndex
- Zero-based index into the rows of the MatrixcolumnIndex
- Zero-based index into the columns of the Matrixvalue
- Value to set at the specified indexpublic ComplexNumber logDeterminant()
Matrix
this
.
Very computationally intensive. Please THINK LONG AND HARD before
invoking this method on sparse matrices, as they have to be converted
to a DenseMatrix first.this
public boolean equals(AbstractMTJMatrix matrix, double effectiveZero)
matrix
- Matrix to compare this
to, must be same size as
this
effectiveZero
- tolerance to determine element-wise equalitypublic void plusEquals(Matrix other)
Ring
this
and other
plusEquals
in interface Ring<Matrix>
plusEquals
in class AbstractMatrix
other
- object to add to this
public void plusEquals(AbstractMTJMatrix matrix)
this
and matrix
, modifies
the elements of this
matrix
- Must have same dimensions this
public void minusEquals(Matrix other)
Ring
other
from
this
minusEquals
in interface Ring<Matrix>
minusEquals
in class AbstractMatrix
other
- object to subtract from this
public void minusEquals(AbstractMTJMatrix matrix)
matrix
from the elements of
this
, modifies the elements of this
matrix
- Must have same dimensions this
public Matrix times(Matrix matrix)
Matrix
this
and matrix
,
operates like the "*
" operator in Matlabtimes
in interface Matrix
times
in class AbstractMatrix
matrix
- this.getNumColumns()==matrix.getNumRows()
this
and
matrix
, will this.getNumRows()
rows and
matrix.getNumColumns()
columnspublic abstract AbstractMTJMatrix times(AbstractMTJMatrix matrix)
this
and matrix
,
operates like the "*
" operator in Matlabmatrix
- this.getNumColumns()==matrix.getNumRows()
this
and
matrix
, will this.getNumRows()
rows and
matrix.getNumColumns()
columnspublic void dotTimesEquals(Matrix other)
Ring
this
and
other
dotTimesEquals
in interface Ring<Matrix>
dotTimesEquals
in class AbstractMatrix
other
- elements of other will be multiplied to the corresponding
elements of this
public void dotTimesEquals(AbstractMTJMatrix matrix)
this
and matrix
, modifies the elements of this
matrix
- Must have same dimensions this
public void scaleEquals(double scaleFactor)
Ring
this
by
scaleFactor
scaleFactor
- amount to scale the elements of this
public void scaledPlusEquals(double scaleFactor, Matrix other)
Ring
this
and other
after
element-wise scaling of other
by scaleFactor
.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x += a * y. It is typically a more efficient way of doing
this.plusEquals(other.scale(scaleFactor))
since it can avoid
intermediate object creation.scaledPlusEquals
in interface Ring<Matrix>
scaledPlusEquals
in class AbstractMatrix
scaleFactor
- The scale factor to multiply by the elements of other before
adding to the elements of this.other
- Object to scale and then add to this.public void scaledPlusEquals(double scaleFactor, AbstractMTJMatrix other)
scaleFactor
- The scale factor to use.other
- The other vector to scale and then add to this vector.public void scaledMinusEquals(double scaleFactor, AbstractMTJMatrix other)
scaleFactor
- The scale factor to use.other
- The other matrix to scale and then subtract from this matrix.public java.util.Iterator<MatrixEntry> iterator()
public boolean isSquare()
Matrix
isSquare
in interface Matrix
isSquare
in class AbstractMatrix
public Vector times(Vector vector)
Matrix
times
in interface Matrix
times
in class AbstractMatrix
vector
- Vector by which to post-multiply this, must have the
same number of rows as thispublic abstract AbstractMTJVector times(AbstractMTJVector vector)
vector
- Vector by which to post-multiply this, must have the
same number of rows as thispublic void identity()
Matrix
public Matrix solve(Matrix B)
Matrix
B
- Must satisfy this.getNumColumns() == B.getNumRows();public Vector solve(Vector b)
Matrix
b
- must satisfy this.getNumColumns() == b.getDimensionality()public final Matrix solve(AbstractMTJMatrix B)
B
- AbstractMTJMatrix, will be converted to a DenseMatrixpublic Vector solve(AbstractMTJVector b)
b
- must satisfy this.getNumColumns() == b.getDimensionality()public Matrix inverse()
Matrix
this
, which must be a
square matrixthis
, such that
this.times(this.inverse()) == this.inverse().times(this)
==
identity matrixpublic double normFrobenius()
Matrix
this
, which is just a fancy
way of saying that I will square each element, add those up, and square
root the result. This is probably the most intuitive of the matrix normsthis
public double normFrobeniusSquared()
Matrix
this
, which is just a
fancy way of saying that I will square each element and add those up.this
public boolean isSymmetric(double effectiveZero)
Matrix
effectiveZero
- tolerance to determine symmetrypublic void zero()
Ring
this
, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 );public int rank(double effectiveZero)
Matrix
this
, which is the number of
linearly independent rows and columns in this
. Rank is
typically based on the SVD, which is a fairly computationally expensive
procedure and should be used carefullyeffectiveZero
- parameter to pass along to SVD to determine linear dependencethis
, equivalent to the number of linearly
indepenedent rows and columns in this
protected void transposeInto(AbstractMTJMatrix destinationMatrix)
destinationMatrix
- matrix into which to store the resultprotected void getSubMatrixInto(int minRow, int maxRow, int minColumn, int maxColumn, AbstractMTJMatrix destinationMatrix)
minRow
- Zero-based index into the rows of the Matrix, must be less than
or equal to maxRowmaxRow
- Zero-based index into the rows of the Matrix, must be greater
than or equal to minRowminColumn
- Zero-based index into the rows of the Matrix, must be less than
or equal to maxColumnmaxColumn
- Zero-based index into the rows of the Matrix, must be greater
than or equal to minColumndestinationMatrix
- the destination submatrix of dimension
(maxRow-minRow+1)x(maxColumn-minColumn+1)protected void timesInto(AbstractMTJMatrix multiplicationMatrix, AbstractMTJMatrix destinationMatrix)
multiplicationMatrix
- matrix to postmultiply this bydestinationMatrix
- matrix to store the matrix multiplication result, must have
rows == this.getNumRows and columns ==
multiplicationMatrix.getNumColumnsprotected void timesInto(AbstractMTJVector multiplicationVector, AbstractMTJVector destinationVector)
multiplicationVector
- vector to postmultiply this bydestinationVector
- vector to store the matrix multiplication result, must have
dimensionality == this.getNumRowspublic void increment(int row, int column, double value)
Matrix
increment
in interface Matrix
increment
in class AbstractMatrix
row
- The zero-based row index.column
- The zero-based column index.value
- The value to add.public void convertFromVector(Vector parameters)
Matrix
parameters
- column-stacked version of this