@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-26",changesNeeded=false,comments={"Minor changes to the formatting","Otherwise, looks good."}) @CodeReview(reviewer="Jonathan McClain",date="2006-05-16",changesNeeded=false,comments="Interface looks ok. Made a few minor changes.") public interface Matrix extends java.lang.Iterable<MatrixEntry>, Ring<Matrix>, Vectorizable
Modifier and Type | Method and Description |
---|---|
void |
assertMultiplicationDimensions(Matrix postMultiplicationMatrix)
Checks to see if the dimensions are appropriate for:
this.times(postMultiplicationMatrix) . |
void |
assertSameDimensions(Matrix otherMatrix)
Throws a DimensionalityMismatchException if dimensions between this
and otherMatrix aren't the same
|
boolean |
checkMultiplicationDimensions(Matrix postMultiplicationMatrix)
Checks to see if the dimensions are appropriate for:
this.times( postMultiplicationMatrix ) |
boolean |
checkSameDimensions(Matrix otherMatrix)
Checks to see if the dimensions are the same between
this
and otherMatrix |
Matrix |
clone()
Returns a smart copy of
this , such that changing the values
of the return class will not effect this |
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 |
decrement(int row,
int column)
Decrements the value at the given position by 1.
|
void |
decrement(int row,
int column,
double value)
Decrements the value at the given position by the given value.
|
Matrix |
dotDivide(Matrix other)
Element-wise division of
this by other . |
void |
dotDivideEquals(Matrix other)
Inline element-wise division of
this by other . |
double |
get(int rowIndex,
int columnIndex)
Gets the value of the element of the matrix at the zero-based row and
column indices.
|
Vector |
getColumn(int columnIndex)
Gets the specified column from the zero-based index and returns a
vector that corresponds to that column.
|
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)
|
int |
getEntryCount()
Gets the number of active entries in the matrix.
|
MatrixFactory<?> |
getMatrixFactory()
Gets a matrix factory, typically one associated with this type of matrix.
|
int |
getNumColumns()
Returns the number of columns in the Matrix
|
int |
getNumRows()
Returns the number of rows in the Matrix
|
Vector |
getRow(int rowIndex)
Gets the specified row from the zero-based index and returns a vector
that corresponds to that column
|
Matrix |
getSubMatrix(int minRow,
int maxRow,
int minColumn,
int maxColumn)
Gets the embedded submatrix inside of the Matrix, specified by the
inclusive, zero-based indices such that the result matrix will have size
(maxRow-minRow+1) x (maxColum-minCcolumn+1)
|
void |
identity()
Formats the matrix as an identity matrix.
|
void |
increment(int row,
int column)
Increments the value at the given position by 1.
|
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 |
isSparse()
Returns true if this matrix has a potentially sparse underlying
structure.
|
boolean |
isSquare()
Determines if the matrix is square (numRows == numColumns)
|
boolean |
isSymmetric()
Determines if the matrix is symmetric.
|
boolean |
isSymmetric(double effectiveZero)
Determines if the matrix is effectively symmetric
|
ComplexNumber |
logDeterminant()
Computes the natural logarithm of the determinant of
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. |
Matrix |
pseudoInverse()
Computes the effective pseudo-inverse of
this , using a
rather expensive procedure (SVD) |
Matrix |
pseudoInverse(double effectiveZero)
Computes the effective pseudo-inverse of
this , using a
rather expensive procedure (SVD) |
int |
rank()
Computes the rank of
this , which is the number of
linearly independent rows and columns in this . |
int |
rank(double effectiveZero)
Computes the effective rank of
this , which is the number of
linearly independent rows and columns in this . |
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 |
setColumn(int columnIndex,
Vector columnVector)
Sets the specified column from the given columnVector
|
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)
|
void |
setRow(int rowIndex,
Vector rowVector)
Sets the specified row from the given rowVector
|
void |
setSubMatrix(int minRow,
int minColumn,
Matrix submatrix)
Sets the submatrix inside of the Matrix, specified by the zero-based
indices.
|
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
|
Vector |
sumOfColumns()
Returns a new vector containing the sum across the columns.
|
Vector |
sumOfRows()
Returns a new vector containing the sum across the rows.
|
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
|
double[][] |
toArray()
Converts this matrix to a new array of array of doubles, in the same
order as they are in the matrix.
|
java.lang.String |
toString() |
java.lang.String |
toString(java.text.NumberFormat format)
Converts the vector to a
String , using the given formatter. |
double |
trace()
Computes the trace of
this , which is the sum of the diagonal
elements. |
Matrix |
transpose()
Returns the transpose of
this |
java.util.List<java.lang.Double> |
valuesAsList()
Returns a column-stacked view of this matrix as a list.
|
dotTimes, dotTimesEquals, equals, equals, isZero, isZero, minus, minusEquals, negative, negativeEquals, plus, plusEquals, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaledPlusEquals, scaleEquals, zero
Matrix clone()
Ring
this
, such that changing the values
of the return class will not effect this
clone
in interface CloneableSerializable
clone
in interface Ring<Matrix>
clone
in interface Vectorizable
this
int getNumRows()
int getNumColumns()
double get(int rowIndex, int columnIndex)
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).void set(int rowIndex, int columnIndex, double value)
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.double getElement(int rowIndex, int columnIndex)
rowIndex
- Zero-based index into the MatrixcolumnIndex
- Zero-based index into the Matrixvoid setElement(int rowIndex, int columnIndex, double value)
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 indexMatrix getSubMatrix(int minRow, int maxRow, int minColumn, int maxColumn)
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 minColumnvoid setSubMatrix(int minRow, int minColumn, Matrix submatrix)
minRow
- Zero-based index into the rows of the Matrix, must be less
than or equal to maxRowminColumn
- Zero-based index into the rows of the Matrix, must be
less than or equal to maxColumnsubmatrix
- Matrix containing the values to set at the specified
indicesboolean isSymmetric()
boolean isSymmetric(double effectiveZero)
effectiveZero
- tolerance to determine symmetryboolean checkSameDimensions(Matrix otherMatrix)
this
and otherMatrix
otherMatrix
- matrix against which to checkthis.getNumRows() == otherMatrix.getNumRows()
and
this.getNumColumns() == otherMatrix.getNumColumns()
void assertSameDimensions(Matrix otherMatrix)
otherMatrix
- Matrix dimensions to compare to thisboolean checkMultiplicationDimensions(Matrix postMultiplicationMatrix)
this.times( postMultiplicationMatrix )
postMultiplicationMatrix
- matrix by which this
is to be multipliedthis.getNumColumns() ==
postMultlicationMatrix.getNumColumns()
, false otherwisevoid assertMultiplicationDimensions(Matrix postMultiplicationMatrix)
this.times(postMultiplicationMatrix)
.postMultiplicationMatrix
- Matrix by which this is to be multiplied.Matrix times(Matrix matrix)
this
and matrix
,
operates like the "*
" operator in Matlabmatrix
- this.getNumColumns()==matrix.getNumRows()
this
and
matrix
, will this.getNumRows()
rows and
matrix.getNumColumns()
columnsMatrix transpose()
this
this.getElement(i, j) == this.transpose().getElement(j, i)
for any valid i, j
.Matrix inverse()
this
, which must be a
square matrixthis
, such that
this.times(this.inverse()) == this.inverse().times(this)
==
identity matrixMatrix pseudoInverse()
this
, using a
rather expensive procedure (SVD)this
Matrix pseudoInverse(double effectiveZero)
this
, using a
rather expensive procedure (SVD)effectiveZero
- effective zero to pass along to the SVDthis
Matrix dotDivide(Matrix other)
this
by other
. Note that if
other
has zero elements the result will contain NaN
values.other
- The other ring whose elements will divide into this one.this
divided by the element in
other
.void dotDivideEquals(Matrix other)
this
by other
. Note
that if other
has zero elements this will contain NaN
values.other
- The other vector whose elements will divide into this one.ComplexNumber logDeterminant()
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
double trace()
this
, which is the sum of the diagonal
elements. It is equivalent to the sum of the eigenvalues (which
is probably the most interesting result in all of algebra!).this
int rank()
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 carefullythis
, equivalent to the number of linearly
independent rows and columns in this
int rank(double effectiveZero)
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
double normFrobenius()
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
double normFrobeniusSquared()
this
, which is just a
fancy way of saying that I will square each element and add those up.this
boolean isSquare()
Matrix solve(Matrix B)
B
- Must satisfy this.getNumColumns() == B.getNumRows();Vector solve(Vector b)
b
- must satisfy this.getNumColumns() == b.getDimensionality()void identity()
Vector times(Vector vector)
vector
- Vector by which to post-multiply this, must have the
same number of rows as thisboolean isSparse()
int getEntryCount()
Vector getColumn(int columnIndex)
columnIndex
- zero-based index into the matrixVector getRow(int rowIndex)
rowIndex
- zero-based index into the matrixvoid setColumn(int columnIndex, Vector columnVector)
columnIndex
- zero-based index into the matrixcolumnVector
- vector to replace in this, must have same number of elements
as this has rowsvoid setRow(int rowIndex, Vector rowVector)
rowIndex
- zero-based index into the matrixrowVector
- vector to replace in this, must have the same number of elements
as this has columnsVector sumOfRows()
Vector sumOfColumns()
void increment(int row, int column)
row
- The zero-based row index.column
- The zero-based column index.void increment(int row, int column, double value)
row
- The zero-based row index.column
- The zero-based column index.value
- The value to add.void decrement(int row, int column)
row
- The zero-based row index.column
- The zero-based column index.void decrement(int row, int column, double value)
row
- The zero-based row index.column
- The zero-based column index.value
- The value to subtract.void convertFromVector(Vector parameters)
convertFromVector
in interface Vectorizable
parameters
- column-stacked version of thisVector convertToVector()
convertToVector
in interface Vectorizable
double[][] toArray()
java.util.List<java.lang.Double> valuesAsList()
java.lang.String toString()
toString
in class java.lang.Object
java.lang.String toString(java.text.NumberFormat format)
String
, using the given formatter.format
- The number format to use.MatrixFactory<?> getMatrixFactory()