gov.sandia.cognition.math.matrix
Class MatrixFactory<MatrixType extends Matrix>

java.lang.Object
  extended by gov.sandia.cognition.math.matrix.MatrixFactory<MatrixType>
Type Parameters:
MatrixType - Type of Matrix created by the factory.
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DenseMatrixFactoryMTJ, DiagonalMatrixFactoryMTJ, SparseMatrixFactoryMTJ

public abstract class MatrixFactory<MatrixType extends Matrix>
extends Object
implements Serializable

Abstract factory for creating Matrix objects.

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

Field Summary
protected static MatrixFactory<? extends Matrix> DEFAULT_DENSE_INSTANCE
          The default dense implementation of a MatrixFactory.
protected static DiagonalMatrixFactoryMTJ DEFAULT_DIAGONAL_INSTANCE
          The default implementation of a factory that creates a DiagonalMatrix
protected static MatrixFactory<? extends Matrix> DEFAULT_SPARSE_INSTANCE
          The default sparse implementation of a MatrixFactory.
 
Constructor Summary
protected MatrixFactory()
          Creates a new MatrixFactory.
 
Method Summary
 MatrixType copyArray(double[][] values)
          Copies the values from the array into the Matrix
 MatrixType copyColumnVectors(Collection<? extends Vectorizable> columns)
          Creates a new matrix by copying the given set of column vectors.
 MatrixType copyColumnVectors(Vectorizable... columns)
          Creates a new matrix by copying the given set of column vectors.
abstract  MatrixType copyMatrix(Matrix m)
          Creates a deep copy new Matrix given another, argument is unchanged
 MatrixType copyRowVectors(Collection<? extends Vectorizable> rows)
          Creates a new matrix by copying the given set of row vectors.
 MatrixType copyRowVectors(Vectorizable... rows)
          Creates a new matrix by copying the given set of row vectors.
 MatrixType createDiagonal(Vectorizable diagonal)
          Creates a new square matrix whose number of rows and columns match the dimensionality of the given vector.
 MatrixType createIdentity(int numRows, int numColumns)
          Creates a Matrix with ones (1) on the diagonal, and zeros (0) elsewhere
abstract  MatrixType createMatrix(int numRows, int numColumns)
          Creates an empty Matrix of the specified dimensions, all elements must be all zeros!
 MatrixType createMatrix(int numRows, int numColumns, double initialValue)
          Creates a matrix with the given initial value.
 MatrixType createUniformRandom(int numRows, int numColumns, double min, double max, Random random)
          Creates a new Matrix of the given size with random values for the entries, uniformly distributed between the given minimum and maximum values.
static MatrixFactory<? extends Matrix> getDefault()
          Gets the default implementation of MatrixFactory.
static MatrixFactory<? extends Matrix> getDenseDefault()
          Gets the default implementation of MatrixFactory for dense matrices.
static MatrixFactory<? extends DiagonalMatrix> getDiagonalDefault()
          Gets the default implementation of MatrixFactory for diagonal matrices.
static MatrixFactory<? extends Matrix> getSparseDefault()
          Gets the default implementation of MatrixFactory for sparse matrices.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DENSE_INSTANCE

protected static final MatrixFactory<? extends Matrix> DEFAULT_DENSE_INSTANCE
The default dense implementation of a MatrixFactory.


DEFAULT_SPARSE_INSTANCE

protected static final MatrixFactory<? extends Matrix> DEFAULT_SPARSE_INSTANCE
The default sparse implementation of a MatrixFactory.


DEFAULT_DIAGONAL_INSTANCE

protected static final DiagonalMatrixFactoryMTJ DEFAULT_DIAGONAL_INSTANCE
The default implementation of a factory that creates a DiagonalMatrix

Constructor Detail

MatrixFactory

protected MatrixFactory()
Creates a new MatrixFactory.

Method Detail

getDefault

public static MatrixFactory<? extends Matrix> getDefault()
Gets the default implementation of MatrixFactory.

Returns:
The default MatrixFactory.

getDenseDefault

public static MatrixFactory<? extends Matrix> getDenseDefault()
Gets the default implementation of MatrixFactory for dense matrices.

Returns:
The default dense MatrixFactory.

getSparseDefault

public static MatrixFactory<? extends Matrix> getSparseDefault()
Gets the default implementation of MatrixFactory for sparse matrices.

Returns:
The default sparse MatrixFactory.

getDiagonalDefault

public static MatrixFactory<? extends DiagonalMatrix> getDiagonalDefault()
Gets the default implementation of MatrixFactory for diagonal matrices.

Returns:
The default DiagonalMatrixFactory.

copyMatrix

public abstract MatrixType copyMatrix(Matrix m)
Creates a deep copy new Matrix given another, argument is unchanged

Parameters:
m - Matrix to copy
Returns:
Deep copy of the given Matrix

copyArray

public MatrixType copyArray(double[][] values)
Copies the values from the array into the Matrix

Parameters:
values - Values to copy
Returns:
Matrix with same dimension and values as "values"

createMatrix

public abstract MatrixType createMatrix(int numRows,
                                        int numColumns)
Creates an empty Matrix of the specified dimensions, all elements must be all zeros!

Parameters:
numRows - number of rows in the Matrix
numColumns - number of columns in the Matrix
Returns:
All-zero empty Matrix of the specified dimensions

createIdentity

public MatrixType createIdentity(int numRows,
                                 int numColumns)
Creates a Matrix with ones (1) on the diagonal, and zeros (0) elsewhere

Parameters:
numRows - number of rows in the Matrix
numColumns - number of columns in the Matrix
Returns:
Identity Matrix with ones on the diagonal and zeros elsewhere

createUniformRandom

public MatrixType createUniformRandom(int numRows,
                                      int numColumns,
                                      double min,
                                      double max,
                                      Random random)
Creates a new Matrix of the given size with random values for the entries, uniformly distributed between the given minimum and maximum values.

Parameters:
numRows - The number of rows in the Matrix.
numColumns - The number of columns in the Matrix.
min - The minimum range of the uniform distribution.
max - The maximum range of the uniform distribution.
random - The random number generator.
Returns:
Matrix with random values for the entries, uniformly distributed between the given minimum and maximum values.

copyRowVectors

public MatrixType copyRowVectors(Collection<? extends Vectorizable> rows)
Creates a new matrix by copying the given set of row vectors.

Parameters:
rows - The row vectors to create a matrix from. Must all be the same dimensionality.
Returns:
A new matrix whose rows are equal to the given set of rows.

copyRowVectors

public MatrixType copyRowVectors(Vectorizable... rows)
Creates a new matrix by copying the given set of row vectors.

Parameters:
rows - The row vectors to create a matrix from. Must all be the same dimensionality.
Returns:
A new matrix whose rows are equal to the given set of rows.

copyColumnVectors

public MatrixType copyColumnVectors(Collection<? extends Vectorizable> columns)
Creates a new matrix by copying the given set of column vectors.

Parameters:
columns - The column vectors to create a matrix from. Must all be the same dimensionality.
Returns:
A new matrix whose columns are equal to the given set of columns.

copyColumnVectors

public MatrixType copyColumnVectors(Vectorizable... columns)
Creates a new matrix by copying the given set of column vectors.

Parameters:
columns - The column vectors to create a matrix from. Must all be the same dimensionality.
Returns:
A new matrix whose columns are equal to the given set of columns.

createMatrix

public MatrixType createMatrix(int numRows,
                               int numColumns,
                               double initialValue)
Creates a matrix with the given initial value.

Parameters:
numRows - The number of rows. Cannot be negative.
numColumns - The number of columns. Cannot be negative.
initialValue - The initial value to set all elements to.
Returns:
A Matrix of the given size initialized with the given initial value.

createDiagonal

public MatrixType createDiagonal(Vectorizable diagonal)
Creates a new square matrix whose number of rows and columns match the dimensionality of the given vector. It also places the values of the vector on the diagonal of the matrix.

Parameters:
diagonal - The vector of diagonal values.
Returns:
A new, square matrix with the diagonal elements equal to the elements of the given vector.