@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, zero
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
clone, 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, transpose
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaleEquals, zero
public boolean equals(java.lang.Object other)
Ring
public boolean equals(Matrix other, double effectiveZero)
Ring
public int hashCode()
hashCode
in class java.lang.Object
public boolean isSymmetric()
Matrix
isSymmetric
in interface Matrix
public boolean checkSameDimensions(Matrix otherMatrix)
Matrix
this
and otherMatrix
checkSameDimensions
in interface Matrix
otherMatrix
- matrix against which to checkthis.getNumRows() == otherMatrix.getNumRows()
and
this.getNumColumns() == otherMatrix.getNumColumns()
public void assertSameDimensions(Matrix other)
Matrix
assertSameDimensions
in interface Matrix
other
- Matrix dimensions to compare to thispublic boolean checkMultiplicationDimensions(Matrix postMultiplicationMatrix)
Matrix
this.times( postMultiplicationMatrix )
checkMultiplicationDimensions
in interface Matrix
postMultiplicationMatrix
- matrix by which this
is to be multipliedthis.getNumColumns() ==
postMultlicationMatrix.getNumColumns()
, false otherwisepublic void assertMultiplicationDimensions(Matrix postMultiplicationMatrix)
Matrix
this.times(postMultiplicationMatrix)
.assertMultiplicationDimensions
in interface Matrix
postMultiplicationMatrix
- Matrix by which this is to be multiplied.public void plusEquals(Matrix other)
Ring
this
and other
plusEquals
in interface Ring<Matrix>
other
- object to add to this
public void minusEquals(Matrix other)
Ring
other
from
this
minusEquals
in interface Ring<Matrix>
other
- object to subtract from this
public void dotTimesEquals(Matrix other)
Ring
this
and
other
dotTimesEquals
in interface Ring<Matrix>
other
- elements of other will be multiplied to the corresponding
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>
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)
Matrix
this
by other
. Note that if
other
has zero elements the result will contain NaN
values.public void dotDivideEquals(Matrix other)
Matrix
this
by other
. Note
that if other
has zero elements this will contain NaN
values.dotDivideEquals
in interface Matrix
other
- The other vector whose elements will divide into this one.public Matrix times(Matrix other)
Matrix
this
and matrix
,
operates like the "*
" operator in Matlabpublic Vector times(Vector vector)
Matrix
public double trace()
Matrix
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!).public void setSubMatrix(int minRow, int minColumn, Matrix submatrix)
Matrix
setSubMatrix
in interface Matrix
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
indicespublic int rank()
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 carefullypublic Matrix pseudoInverse()
Matrix
this
, using a
rather expensive procedure (SVD)pseudoInverse
in interface Matrix
this
public void setColumn(int columnIndex, Vector columnVector)
Matrix
public void setRow(int rowIndex, Vector rowVector)
Matrix
protected 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()
Matrix
public Vector sumOfColumns()
Matrix
sumOfColumns
in interface Matrix
public boolean isZero(double effectiveZero)
Ring
public boolean isSquare()
Matrix
public void increment(int row, int column)
Matrix
public void increment(int row, int column, double value)
Matrix
public void decrement(int row, int column)
Matrix
public void decrement(int row, int column, double value)
Matrix
public double[][] toArray()
Matrix
public java.util.List<java.lang.Double> valuesAsList()
Matrix
valuesAsList
in interface Matrix