gov.sandia.cognition.math.matrix.mtj
Class DiagonalMatrixMTJ

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.math.AbstractRing<Matrix>
          extended by gov.sandia.cognition.math.matrix.AbstractMatrix
              extended by gov.sandia.cognition.math.matrix.mtj.AbstractMTJMatrix
                  extended by gov.sandia.cognition.math.matrix.mtj.DiagonalMatrixMTJ
All Implemented Interfaces:
DiagonalMatrix, Matrix, Vectorizable, Ring<Matrix>, CloneableSerializable, Serializable, Cloneable, Iterable<MatrixEntry>

@PublicationReference(author="Bjorn-Ove Heimsund",
                      title="Matrix Toolkits for Java BandMatrix",
                      type=WebPage,
                      year=2006,
                      url="http://ressim.berlios.de/doc/no/uib/cipr/matrix/BandMatrix.html",
                      notes="This class wraps the BandMatrix class from Heimsund\'s MTJ package")
public class DiagonalMatrixMTJ
extends AbstractMTJMatrix
implements DiagonalMatrix

A diagonal matrix that wraps MTJ's BandMatrix class.

Since:
2.1
Author:
Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
protected DiagonalMatrixMTJ(DiagonalMatrixMTJ other)
          Copy Constructor
protected DiagonalMatrixMTJ(double[] diagonal)
          Creates a new instance of DiagonalMatrixMTJ
protected DiagonalMatrixMTJ(int dim)
          Creates a new instance of DiagonalMatrixMTJ
 
Method Summary
 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 )
 DenseVector convertToVector()
          Creates a column-stacked version of this, so that v(k) = A(i,j) = v(j*M+i)
 DiagonalMatrixMTJ dotTimes(Matrix matrix)
          Element-wise multiplication of this and other
 void dotTimesEquals(AbstractMTJMatrix matrix)
          Inline element-wise multiplication of the elements in this and matrix, modifies the elements of this
 Vector getColumn(int columnIndex)
          Gets the specified column from the zero-based index and returns a vector that corresponds to that column.
 double[] getDiagonal()
          Gets the data along the diagonal
 int getDimensionality()
          Gets the dimensionality of this square matrix, which is equal to either the number of rows or the number of columns
 double getElement(int index)
          Gets the zero-based index diagonal element into the diagonal matrix
 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.BandMatrix getInternalMatrix()
          Gets the internal MTJ matrix that this class is wrapping.
 Vector getRow(int rowIndex)
          Gets the specified row from the zero-based index and returns a vector that corresponds to that column
 SparseMatrix 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)
 DiagonalMatrixMTJ 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.
 DiagonalMatrixMTJ pseudoInverse()
          Computes the effective pseudo-inverse of this, using a rather expensive procedure (SVD)
 DiagonalMatrixMTJ pseudoInverse(double effectiveZero)
          Computes the effective pseudo-inverse of this, using a rather expensive procedure (SVD)
 int rank(double effectiveZero)
          Computes the effective rank of this, which is the number of linearly independent rows and columns in this.
 void setElement(int index, double value)
          Sets the zero-based index diagonal element into the diagonal matrix
 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
 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
 AbstractMTJMatrix times(AbstractMTJMatrix matrix)
          Matrix multiplication of this and matrix, operates like the "*" operator in Matlab
 AbstractMTJVector times(AbstractMTJVector vector)
          Returns the column vector from the equation return = this * vector
 DiagonalMatrixMTJ times(DiagonalMatrix matrix)
          Multiplies this by the given DiagonalMatrix, leaving this unmodified
 void timesEquals(DiagonalMatrix matrix)
          Multiplies this by the other diagonal matrix, stores the result in this
 String toString()
           
 String toString(NumberFormat format)
          Converts the vector to a String, using the given formatter.
 DiagonalMatrixMTJ transpose()
          Returns the transpose of this
 
Methods inherited from class gov.sandia.cognition.math.matrix.mtj.AbstractMTJMatrix
clone, dotTimesEquals, equals, getNumColumns, getNumRows, getSubMatrixInto, identity, iterator, minusEquals, minusEquals, plusEquals, plusEquals, scaledMinusEquals, scaledPlusEquals, scaledPlusEquals, scaleEquals, solve, times, times, timesInto, timesInto, transposeInto, zero
 
Methods inherited from class gov.sandia.cognition.math.matrix.AbstractMatrix
assertSameDimensions, checkMultiplicationDimensions, checkSameDimensions, dotDivide, dotDivideEquals, equals, equals, getColumnInto, getRowInto, hashCode, isZero, rank, setColumn, setRow, setSubMatrix, sumOfColumns, sumOfRows, toArray, trace
 
Methods inherited from class gov.sandia.cognition.math.AbstractRing
isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.math.matrix.Matrix
assertSameDimensions, checkMultiplicationDimensions, checkSameDimensions, clone, dotDivide, dotDivideEquals, getNumColumns, getNumRows, identity, rank, setColumn, setRow, setSubMatrix, sumOfColumns, sumOfRows, times, times, toArray, trace
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface gov.sandia.cognition.math.Ring
dotTimesEquals, equals, equals, isZero, isZero, minus, minusEquals, negative, negativeEquals, plus, plusEquals, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaledPlusEquals, scaleEquals, zero
 

Constructor Detail

DiagonalMatrixMTJ

protected DiagonalMatrixMTJ(int dim)
Creates a new instance of DiagonalMatrixMTJ

Parameters:
dim - Dimensionality of the square diagonal matrix

DiagonalMatrixMTJ

protected DiagonalMatrixMTJ(DiagonalMatrixMTJ other)
Copy Constructor

Parameters:
other - DiagonalMatrixMTJ to copy

DiagonalMatrixMTJ

protected DiagonalMatrixMTJ(double[] diagonal)
Creates a new instance of DiagonalMatrixMTJ

Parameters:
diagonal - Array of elements to set the diagonal to
Method Detail

getDimensionality

public int getDimensionality()
Description copied from interface: DiagonalMatrix
Gets the dimensionality of this square matrix, which is equal to either the number of rows or the number of columns

Specified by:
getDimensionality in interface DiagonalMatrix
Returns:
Dimensionality of the square matrix

getInternalMatrix

public no.uib.cipr.matrix.BandMatrix getInternalMatrix()
Description copied from class: AbstractMTJMatrix
Gets the internal MTJ matrix that this class is wrapping.

Overrides:
getInternalMatrix in class AbstractMTJMatrix
Returns:
Internal MTJ matrix.

setInternalMatrix

protected void setInternalMatrix(no.uib.cipr.matrix.Matrix internalMatrix)
Description copied from class: AbstractMTJMatrix
Setter for internalMatrix

Overrides:
setInternalMatrix in class AbstractMTJMatrix
Parameters:
internalMatrix - internal MTJ-based matrix

times

public AbstractMTJMatrix times(AbstractMTJMatrix matrix)
Description copied from class: AbstractMTJMatrix
Matrix multiplication of this and matrix, operates like the "*" operator in Matlab

Specified by:
times in class AbstractMTJMatrix
Parameters:
matrix - this.getNumColumns()==matrix.getNumRows()
Returns:
Matrix multiplication of this and matrix, will this.getNumRows() rows and matrix.getNumColumns() columns

times

public DiagonalMatrixMTJ times(DiagonalMatrix matrix)
Description copied from interface: DiagonalMatrix
Multiplies this by the given DiagonalMatrix, leaving this unmodified

Specified by:
times in interface DiagonalMatrix
Parameters:
matrix - DigonalMatrix to multiply this
Returns:
DiagonalMatrix representing the multiplication

timesEquals

public void timesEquals(DiagonalMatrix matrix)
Description copied from interface: DiagonalMatrix
Multiplies this by the other diagonal matrix, stores the result in this

Specified by:
timesEquals in interface DiagonalMatrix
Parameters:
matrix - Diagonal matrix to multiply this by

times

public AbstractMTJVector times(AbstractMTJVector vector)
Description copied from class: AbstractMTJMatrix
Returns the column vector from the equation return = this * vector

Specified by:
times in class AbstractMTJMatrix
Parameters:
vector - Vector by which to post-multiply this, must have the same number of rows as this
Returns:
Vector with the same dimensionality as the number of rows as this and vector

dotTimes

public DiagonalMatrixMTJ dotTimes(Matrix matrix)
Description copied from interface: Ring
Element-wise multiplication of this and other

Specified by:
dotTimes in interface DiagonalMatrix
Specified by:
dotTimes in interface Ring<Matrix>
Overrides:
dotTimes in class AbstractRing<Matrix>
Parameters:
matrix - elements of other will be multiplied to the corresponding elements of this
Returns:
element-wise multiplication of this and other

dotTimesEquals

public void dotTimesEquals(AbstractMTJMatrix matrix)
Description copied from class: AbstractMTJMatrix
Inline element-wise multiplication of the elements in this and matrix, modifies the elements of this

Overrides:
dotTimesEquals in class AbstractMTJMatrix
Parameters:
matrix - Must have same dimensions this

isSquare

public boolean isSquare()
Description copied from interface: Matrix
Determines if the matrix is square (numRows == numColumns)

Specified by:
isSquare in interface Matrix
Overrides:
isSquare in class AbstractMTJMatrix
Returns:
true if square, false if nonsquare

isSymmetric

public boolean isSymmetric()
Description copied from interface: Matrix
Determines if the matrix is symmetric.

Specified by:
isSymmetric in interface Matrix
Overrides:
isSymmetric in class AbstractMatrix
Returns:
true if the matrix is symmetric, false otherwise

isSymmetric

public boolean isSymmetric(double effectiveZero)
Description copied from interface: Matrix
Determines if the matrix is effectively symmetric

Specified by:
isSymmetric in interface Matrix
Overrides:
isSymmetric in class AbstractMTJMatrix
Parameters:
effectiveZero - tolerance to determine symmetry
Returns:
true if effectively symmetric, false otherwise

logDeterminant

public ComplexNumber logDeterminant()
Description copied from interface: Matrix
Computes the natural logarithm of the determinant of 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.

Specified by:
logDeterminant in interface Matrix
Overrides:
logDeterminant in class AbstractMTJMatrix
Returns:
natural logarithm of the determinant of this

normFrobenius

public double normFrobenius()
Description copied from interface: Matrix
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. This is probably the most intuitive of the matrix norms

Specified by:
normFrobenius in interface Matrix
Overrides:
normFrobenius in class AbstractMTJMatrix
Returns:
Frobenius norm of this

rank

public int rank(double effectiveZero)
Description copied from interface: Matrix
Computes the effective rank of 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 carefully

Specified by:
rank in interface Matrix
Overrides:
rank in class AbstractMTJMatrix
Parameters:
effectiveZero - parameter to pass along to SVD to determine linear dependence
Returns:
rank of this, equivalent to the number of linearly indepenedent rows and columns in this

solve

public Vector solve(AbstractMTJVector b)
Description copied from class: AbstractMTJMatrix
Solves for "x" in the equation: this*x = b

Overrides:
solve in class AbstractMTJMatrix
Parameters:
b - must satisfy this.getNumColumns() == b.getDimensionality()
Returns:
x Vector with dimensions (this.getNumRows())

solve

public Matrix solve(Matrix B)
Description copied from interface: Matrix
Solves for "X" in the equation: this*X = B

Specified by:
solve in interface Matrix
Overrides:
solve in class AbstractMTJMatrix
Parameters:
B - Must satisfy this.getNumColumns() == B.getNumRows();
Returns:
X Matrix with dimensions (this.getNumColumns() x B.getNumColumns())

solve

public Vector solve(Vector b)
Description copied from interface: Matrix
Solves for "x" in the equation: this*x = b

Specified by:
solve in interface Matrix
Overrides:
solve in class AbstractMTJMatrix
Parameters:
b - must satisfy this.getNumColumns() == b.getDimensionality()
Returns:
x Vector with dimensions (this.getNumColumns())

getSubMatrix

public SparseMatrix getSubMatrix(int minRow,
                                 int maxRow,
                                 int minColumn,
                                 int maxColumn)
Description copied from interface: Matrix
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)

Specified by:
getSubMatrix in interface Matrix
Parameters:
minRow - Zero-based index into the rows of the Matrix, must be less than or equal to maxRow
maxRow - Zero-based index into the rows of the Matrix, must be greater than or equal to minRow
minColumn - Zero-based index into the rows of the Matrix, must be less than or equal to maxColumn
maxColumn - Zero-based index into the rows of the Matrix, must be greater than or equal to minColumn
Returns:
the Matrix of dimension (maxRow-minRow+1)x(maxColumn-minColumn+1)

transpose

public DiagonalMatrixMTJ transpose()
Description copied from interface: Matrix
Returns the transpose of this

Specified by:
transpose in interface Matrix
Returns:
Matrix whose elements are equivalent to: this.getElement(i, j) == this.transpose().getElement(j, i) for any valid i, j.

getDiagonal

public double[] getDiagonal()
Gets the data along the diagonal

Specified by:
getDiagonal in interface DiagonalMatrix
Returns:
Diagonal data

pseudoInverse

public DiagonalMatrixMTJ pseudoInverse()
Description copied from interface: Matrix
Computes the effective pseudo-inverse of this, using a rather expensive procedure (SVD)

Specified by:
pseudoInverse in interface DiagonalMatrix
Specified by:
pseudoInverse in interface Matrix
Overrides:
pseudoInverse in class AbstractMatrix
Returns:
full singular-value pseudo-inverse of this

pseudoInverse

public DiagonalMatrixMTJ pseudoInverse(double effectiveZero)
Description copied from interface: Matrix
Computes the effective pseudo-inverse of this, using a rather expensive procedure (SVD)

Specified by:
pseudoInverse in interface DiagonalMatrix
Specified by:
pseudoInverse in interface Matrix
Parameters:
effectiveZero - effective zero to pass along to the SVD
Returns:
effective pseudo-inverse of this

inverse

public DiagonalMatrixMTJ inverse()
Description copied from interface: Matrix
Computes the full-blown inverse of this, which must be a square matrix

Specified by:
inverse in interface DiagonalMatrix
Specified by:
inverse in interface Matrix
Overrides:
inverse in class AbstractMTJMatrix
Returns:
Inverse of this, such that this.times(this.inverse()) == this.inverse().times(this) == identity matrix

isSparse

public boolean isSparse()
Description copied from interface: Matrix
Returns true if this matrix has a potentially sparse underlying structure. This can indicate that it is faster to only process the non-zero elements rather than to do dense operations on it. Of course, even with a sparse structure, there may be no zero elements or conversely even with a non-sparse (dense) structure there may be many zero elements.

Specified by:
isSparse in interface Matrix
Returns:
True if the matrix has a potentially sparse structure. Otherwise, false.

getColumn

public Vector getColumn(int columnIndex)
Description copied from interface: Matrix
Gets the specified column from the zero-based index and returns a vector that corresponds to that column.

Specified by:
getColumn in interface Matrix
Parameters:
columnIndex - zero-based index into the matrix
Returns:
Vector with elements equal to the number of rows in this

getRow

public Vector getRow(int rowIndex)
Description copied from interface: Matrix
Gets the specified row from the zero-based index and returns a vector that corresponds to that column

Specified by:
getRow in interface Matrix
Parameters:
rowIndex - zero-based index into the matrix
Returns:
Vector with elements equal to the number of columns in this

getElement

public double getElement(int rowIndex,
                         int columnIndex)
Description copied from interface: Matrix
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)

Specified by:
getElement in interface Matrix
Overrides:
getElement in class AbstractMTJMatrix
Parameters:
rowIndex - Zero-based index into the Matrix
columnIndex - Zero-based index into the Matrix
Returns:
The value at rowIndex, columnIndex

setElement

public void setElement(int rowIndex,
                       int columnIndex,
                       double value)
Description copied from interface: Matrix
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)

Specified by:
setElement in interface Matrix
Overrides:
setElement in class AbstractMTJMatrix
Parameters:
rowIndex - Zero-based index into the rows of the Matrix
columnIndex - Zero-based index into the columns of the Matrix
value - Value to set at the specified index

getElement

public double getElement(int index)
Description copied from interface: DiagonalMatrix
Gets the zero-based index diagonal element into the diagonal matrix

Specified by:
getElement in interface DiagonalMatrix
Parameters:
index - Zero-based index into the diagonal to get
Returns:
Diagonal value at index

setElement

public void setElement(int index,
                       double value)
Description copied from interface: DiagonalMatrix
Sets the zero-based index diagonal element into the diagonal matrix

Specified by:
setElement in interface DiagonalMatrix
Parameters:
index - Zero-based index into the diagonal to set
value - Value to set

convertToVector

public DenseVector convertToVector()
Description copied from interface: Matrix
Creates a column-stacked version of this, so that v(k) = A(i,j) = v(j*M+i)

Specified by:
convertToVector in interface Matrix
Specified by:
convertToVector in interface Vectorizable
Overrides:
convertToVector in class AbstractMTJMatrix
Returns:
column-stacked Vector representing this

convertFromVector

public void convertFromVector(Vector parameters)
Description copied from interface: Matrix
uploads a matrix from a column-stacked vector of parameters, so that v(k) = A(i,j) = A( k%M, k/M )

Specified by:
convertFromVector in interface Matrix
Specified by:
convertFromVector in interface Vectorizable
Overrides:
convertFromVector in class AbstractMTJMatrix
Parameters:
parameters - column-stacked version of this

toString

public String toString()
Specified by:
toString in interface Matrix
Overrides:
toString in class Object

toString

public String toString(NumberFormat format)
Description copied from interface: Matrix
Converts the vector to a String, using the given formatter.

Specified by:
toString in interface Matrix
Parameters:
format - The number format to use.
Returns:
The String representation of the Matrix.