@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-26",changesNeeded=false,comments={"Minor changes to formatting and documentation for equals().","Otherwise, looks good."}) @CodeReview(reviewer="Jonathan McClain",date="2006-05-16",changesNeeded=true,comments="A few minor changes.",response=@CodeReviewResponse(respondent="Justin Basilico",date="2006-05-16",moreChangesNeeded=false,comments="Added a line to the class documentation that says that setElement is used extensively in the abstract implementation.")) public abstract class AbstractMatrix extends AbstractRing<Matrix> implements Matrix
| Constructor and Description |
|---|
AbstractMatrix()
Creates a new instance of AbstractMatrix.
|
| 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 other)
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 |
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. |
void |
dotTimesEquals(Matrix other)
Inline element-wise multiplication of
this and
other |
boolean |
equals(Matrix other,
double effectiveZero)
Determines if two RingType objects are effectively equal
|
boolean |
equals(java.lang.Object other)
Determines if two RingType objects are equal
|
protected void |
getColumnInto(int columnIndex,
Vector destinationVector)
Internal function that writes the column onto the destinationVector.
|
protected void |
getRowInto(int rowIndex,
Vector destinationVector)
Internal function that writes the row onto the destinationVector.
|
int |
hashCode() |
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.
|
boolean |
isSquare()
Determines if the matrix is square (numRows == numColumns)
|
boolean |
isSymmetric()
Determines if the matrix is symmetric.
|
boolean |
isZero(double effectiveZero)
Determines if this ring is equal to zero using the element-wise effective
zero value.
|
void |
minusEquals(Matrix other)
Inline arithmetic subtraction of
other from
this |
void |
plusEquals(Matrix other)
Inline arithmetic addition of
this and other |
Matrix |
pseudoInverse()
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. |
void |
scaledPlusEquals(double scaleFactor,
Matrix other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
setColumn(int columnIndex,
Vector columnVector)
Sets the specified column from the given columnVector
|
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.
|
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 other)
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.
|
double |
trace()
Computes the trace of
this, which is the sum of the diagonal
elements. |
java.util.List<java.lang.Double> |
valuesAsList()
Returns a column-stacked view of this matrix as a list.
|
clone, dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zerofinalize, getClass, notify, notifyAll, toString, wait, wait, waitclone, convertFromVector, convertToVector, get, getColumn, getElement, getEntryCount, getMatrixFactory, getNumColumns, getNumRows, getRow, getSubMatrix, identity, inverse, isSparse, isSymmetric, logDeterminant, normFrobenius, normFrobeniusSquared, pseudoInverse, rank, set, setElement, solve, solve, toString, toString, transposedotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaleEquals, zeropublic boolean equals(java.lang.Object other)
Ringpublic boolean equals(Matrix other, double effectiveZero)
Ringpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean isSymmetric()
MatrixisSymmetric in interface Matrixpublic boolean checkSameDimensions(Matrix otherMatrix)
Matrixthis
and otherMatrixcheckSameDimensions in interface MatrixotherMatrix - matrix against which to checkthis.getNumRows() == otherMatrix.getNumRows() and
this.getNumColumns() == otherMatrix.getNumColumns()public void assertSameDimensions(Matrix other)
MatrixassertSameDimensions in interface Matrixother - Matrix dimensions to compare to thispublic boolean checkMultiplicationDimensions(Matrix postMultiplicationMatrix)
Matrixthis.times( postMultiplicationMatrix )checkMultiplicationDimensions in interface MatrixpostMultiplicationMatrix - matrix by which this is to be multipliedthis.getNumColumns() ==
postMultlicationMatrix.getNumColumns(), false otherwisepublic void assertMultiplicationDimensions(Matrix postMultiplicationMatrix)
Matrixthis.times(postMultiplicationMatrix).assertMultiplicationDimensions in interface MatrixpostMultiplicationMatrix - Matrix by which this is to be multiplied.public void plusEquals(Matrix other)
Ringthis and otherplusEquals in interface Ring<Matrix>other - object to add to thispublic void minusEquals(Matrix other)
Ringother from
thisminusEquals in interface Ring<Matrix>other - object to subtract from thispublic void dotTimesEquals(Matrix other)
Ringthis and
otherdotTimesEquals in interface Ring<Matrix>other - elements of other will be multiplied to the corresponding
elements of thispublic void scaledPlusEquals(double scaleFactor,
Matrix other)
Ringthis 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>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 Matrix dotDivide(Matrix other)
Matrixthis by other. Note that if
other has zero elements the result will contain NaN
values.public void dotDivideEquals(Matrix other)
Matrixthis by other. Note
that if other has zero elements this will contain NaN
values.dotDivideEquals in interface Matrixother - The other vector whose elements will divide into this one.public Matrix times(Matrix other)
Matrixthis and matrix,
operates like the "*" operator in Matlabpublic Vector times(Vector vector)
Matrixpublic double trace()
Matrixthis, 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!).public void setSubMatrix(int minRow,
int minColumn,
Matrix submatrix)
MatrixsetSubMatrix in interface MatrixminRow - 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
indicespublic int rank()
Matrixthis, 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 carefullypublic Matrix pseudoInverse()
Matrixthis, using a
rather expensive procedure (SVD)pseudoInverse in interface Matrixthispublic void setColumn(int columnIndex,
Vector columnVector)
Matrixpublic void setRow(int rowIndex,
Vector rowVector)
Matrixprotected void getColumnInto(int columnIndex,
Vector destinationVector)
columnIndex - zero-based index into the matrixdestinationVector - Vector with elements equal to the number of rows in thisprotected void getRowInto(int rowIndex,
Vector destinationVector)
rowIndex - zero-based index into the matrixdestinationVector - Vector with elements equal to the number of columns in thispublic Vector sumOfRows()
Matrixpublic Vector sumOfColumns()
MatrixsumOfColumns in interface Matrixpublic boolean isZero(double effectiveZero)
Ringpublic boolean isSquare()
Matrixpublic void increment(int row,
int column)
Matrixpublic void increment(int row,
int column,
double value)
Matrixpublic void decrement(int row,
int column)
Matrixpublic void decrement(int row,
int column,
double value)
Matrixpublic double[][] toArray()
Matrixpublic java.util.List<java.lang.Double> valuesAsList()
MatrixvaluesAsList in interface Matrix