public class MatrixFactory extends Object
Modifier and Type | Method and Description |
---|---|
static Matrix |
cbind(List<Vector> vectors)
Combines a list of vectors by columns.
|
static Matrix |
cbind(Matrix... matrices)
Combines an array of matrices by columns.
|
static SparseMatrix |
cbind(SparseMatrix... matrices)
Combines an array of sparse matrices by columns.
|
static SparseMatrix |
cbind(SparseVector... vectors)
Combines an array of sparse vectors by columns and returns a CSR sparse matrix.
|
static Matrix |
cbind(Vector... vectors)
Combines an array of vectors by columns.
|
static Matrix |
columns(Matrix A,
int[] cols)
Constructs a sub-matrix from the columns of a matrix.
|
static Matrix |
columns(Matrix A,
int begin,
int end)
Constructs a sub-matrix from the columns of a matrix.
|
static DiagonalMatrix |
diagonalMatrix(Matrix A)
Gets the diagonal of a matrix.
|
static Matrix |
foreach(Matrix A,
UnivariateRealFunction f)
Constructs a new matrix in which each entry is the result of applying a function to the
corresponding entry of a matrix.
|
static Matrix |
foreachColumn(Matrix matrix,
RealVectorFunction f)
Constructs a new matrix in which each column is the result of applying a real vector function
on each column vector of an input matrix.
|
static Matrix |
foreachRow(Matrix A,
RealVectorFunction f)
Constructs a new matrix in which each row is the result of applying a real vector function on
each row vector of an input matrix.
|
static Matrix |
identity(int nRows,
int nCols)
Constructs a new identity matrix.
|
static Matrix |
minorMatrix(Matrix X,
int row,
int col)
Gets the minor matrix of a given matrix, by removing a specified row and a specified column.
|
static Matrix |
ones(int nRows,
int nCols)
Constructs a matrix of 1's.
|
static Matrix |
ones(int nRows,
int nCols,
double s)
Constructs a matrix of the same scalar, e.g.,1.
|
static CSRSparseMatrix |
randomCSRSparseMatrix(int nRows,
int nCols,
int nNonZero,
RandomLongGenerator uniform)
Constructs a random CSRSparseMatrix.
|
static DenseMatrix |
randomDenseMatrix(int nRows,
int nCols,
RandomNumberGenerator rng)
Constructs a random DenseMatrix.
|
static DOKSparseMatrix |
randomDOKSparseMatrix(int nRows,
int nCols,
int nNonZero,
RandomLongGenerator uniform)
Constructs a random DOKSparseMatrix.
|
static LILSparseMatrix |
randomLILSparseMatrix(int nRows,
int nCols,
int nNonZero,
RandomLongGenerator uniform)
Constructs a random LILSparseMatrix.
|
static LowerTriangularMatrix |
randomLowerTriangularMatrix(int dim,
RandomNumberGenerator rng)
Constructs a random LowerTriangularMatrix.
|
static Matrix |
randomPositiveDefiniteMatrix(int dim,
RandomNumberGenerator rng)
Constructs a random symmetric, positive definite matrix.
|
static SymmetricMatrix |
randomSymmetricMatrix(int dim,
RandomNumberGenerator rng)
Constructs a random SymmetricMatrix.
|
static UpperTriangularMatrix |
randomUpperTriangularMatrix(int dim,
RandomNumberGenerator rng)
Constructs a random UpperTriangularMatrix.
|
static Matrix |
rbind(List<Vector> vectors)
Combines a list of array of vectors by rows.
|
static Matrix |
rbind(Matrix... matrices)
Combines an array of matrices by rows.
|
static SparseMatrix |
rbind(SparseMatrix... matrices)
Combines an array of sparse matrices by rows.
|
static SparseMatrix |
rbind(SparseVector... vectors)
Combines an array of sparse vectors by rows and returns a sparse matrix.
|
static Matrix |
rbind(Vector... vectors)
Combines an array of vectors by rows.
|
static Matrix |
replaceInPlace(Matrix original,
int rowFrom,
int rowTo,
int colFrom,
int colTo,
Matrix replacement)
Replaces a sub-matrix of a matrix with a smaller matrix.
|
static Matrix |
rows(Matrix A,
int[] rows)
Construct a sub-matrix from the rows of a matrix.
|
static Matrix |
rows(Matrix A,
int begin,
int end)
Constructs a sub-matrix from the rows of a matrix.
|
static Matrix |
subMatrix(Matrix A,
int[] rows,
int[] cols)
Constructs a sub-matrix from the intersections of rows and columns of a matrix.
|
static Matrix |
subMatrix(Matrix A,
int rowFrom,
int rowTo,
int colFrom,
int colTo)
Constructs a sub-matrix from the four corners of a matrix.
|
static Matrix |
subMatrix(Matrix A,
List<Integer> rows,
List<Integer> cols)
Constructs a sub-matrix from the intersections of rows and columns of a
matrix.
|
static SparseMatrix |
subMatrix(SparseMatrix A,
int[] rows,
int[] cols)
Constructs a sub-matrix from the intersections of rows and columns of a sparse matrix.
|
static SparseMatrix |
subMatrix(SparseMatrix A,
int rowFrom,
int rowTo,
int colFrom,
int colTo)
Constructs a sub-matrix from the four corners of a sparse matrix.
|
public static Matrix identity(int nRows, int nCols)
nRows
- the number of rowsnCols
- the number of columnspublic static Matrix ones(int nRows, int nCols, double s)
nRows
- the number of rowsnCols
- the number of columnss
- the scale to fill the matrixpublic static Matrix ones(int nRows, int nCols)
nRows
- the number of rowsnCols
- the number of columnspublic static Matrix replaceInPlace(Matrix original, int rowFrom, int rowTo, int colFrom, int colTo, Matrix replacement)
SymmetricMatrix
because this method does not ensure the symmetry property after
replacement.
Note that The original matrix is modified afterward (for performance reason in case of a
big matrix).
No new Matrix
instance is constructed.
original
- the matrix whose entries are to be replacedrowFrom
- the beginning row indexrowTo
- the ending row indexcolFrom
- the beginning column indexcolTo
- the ending column indexreplacement
- the matrix to be inserted into the original matrixpublic static Matrix foreach(Matrix A, UnivariateRealFunction f)
A
- a matrixf
- the function to be applied to each entry of a matrixpublic static Matrix foreachRow(Matrix A, RealVectorFunction f)
A
- the input matrixf
- the real vector functionpublic static Matrix foreachColumn(Matrix matrix, RealVectorFunction f)
matrix
- the input matrixf
- the real vector functionpublic static Matrix cbind(Vector... vectors)
vectors
- an array of vectors, e.g., v1, v2, v3,
...public static SparseMatrix cbind(SparseVector... vectors)
vectors
- an array of vectors, e.g., v1, v2, v3,
...public static Matrix cbind(List<Vector> vectors)
vectors
- a list of vectors, e.g., v1, v2, v3,
...public static Matrix cbind(Matrix... matrices)
matrices
- an array of matrices, e.g., A1, A2, A3,
...public static SparseMatrix cbind(SparseMatrix... matrices)
matrices
- an array of matrices, e.g., A1, A2, A3,
...public static Matrix rbind(Vector... vectors)
vectors
- an array of vector, e.g., v1, v2, v3,
...IllegalArgumentException
- if the vectors form a jagged arraypublic static SparseMatrix rbind(SparseVector... vectors)
vectors
- an array of vector, e.g., v1, v2, v3,
...IllegalArgumentException
- if the vectors form a jagged arraypublic static Matrix rbind(List<Vector> vectors)
vectors
- a list of vector, e.g., v1, v2, v3,
...IllegalArgumentException
- if the vectors form a jagged arraypublic static Matrix rbind(Matrix... matrices)
matrices
- an array of matrices, e.g., A1, A2, A3,
...public static SparseMatrix rbind(SparseMatrix... matrices)
matrices
- an array of matrices, e.g., A1, A2, A3,
...public static Matrix subMatrix(Matrix A, int rowFrom, int rowTo, int colFrom, int colTo)
A
- a matrixrowFrom
- the beginning row indexrowTo
- the ending row indexcolFrom
- the beginning column indexcolTo
- the ending column indexpublic static SparseMatrix subMatrix(SparseMatrix A, int rowFrom, int rowTo, int colFrom, int colTo)
A
- a sparse matrixrowFrom
- the beginning row indexrowTo
- the ending row indexcolFrom
- the beginning column indexcolTo
- the ending column indexpublic static Matrix subMatrix(Matrix A, List<Integer> rows, List<Integer> cols)
A
- a matrixrows
- the rows to be extractedcols
- the columns to be extractedpublic static Matrix subMatrix(Matrix A, int[] rows, int[] cols)
A
- a matrixrows
- the rows to be extractedcols
- the columns to be extractedpublic static SparseMatrix subMatrix(SparseMatrix A, int[] rows, int[] cols)
A
- a sparse matrixrows
- the rows to be extractedcols
- the columns to be extractedpublic static Matrix rows(Matrix A, int[] rows)
A
- a matrixrows
- the rows to be extractedpublic static Matrix rows(Matrix A, int begin, int end)
A
- a matrixbegin
- the beginning row index (counting from 1)end
- the ending row index (counting from 1)public static Matrix columns(Matrix A, int[] cols)
A
- a matrixcols
- the columns to be extractedpublic static Matrix columns(Matrix A, int begin, int end)
A
- a matrixbegin
- the beginning column index (counting from 1)end
- the ending column index (counting from 1)public static DiagonalMatrix diagonalMatrix(Matrix A)
A
- a matrixIllegalArgumentException
- if A is not squarepublic static Matrix minorMatrix(Matrix X, int row, int col)
X
- the matrixrow
- the index of the row to be removedcol
- the index of the column to be removedpublic static DenseMatrix randomDenseMatrix(int nRows, int nCols, RandomNumberGenerator rng)
nRows
- the number of rowsnCols
- the number of columnsrng
- a random number generatorpublic static SymmetricMatrix randomSymmetricMatrix(int dim, RandomNumberGenerator rng)
dim
- the matrix dimensionrng
- a random number generatorpublic static LowerTriangularMatrix randomLowerTriangularMatrix(int dim, RandomNumberGenerator rng)
dim
- the matrix dimensionrng
- a random number generatorpublic static UpperTriangularMatrix randomUpperTriangularMatrix(int dim, RandomNumberGenerator rng)
dim
- the matrix dimensionrng
- a random number generatorpublic static DOKSparseMatrix randomDOKSparseMatrix(int nRows, int nCols, int nNonZero, RandomLongGenerator uniform)
nRows
- the number of rowsnCols
- the number of columnsnNonZero
- the number of non-zero elementsuniform
- a uniform random number generatorpublic static LILSparseMatrix randomLILSparseMatrix(int nRows, int nCols, int nNonZero, RandomLongGenerator uniform)
nRows
- the number of rowsnCols
- the number of columnsnNonZero
- the number of non-zero elementsuniform
- a uniform random number generatorpublic static CSRSparseMatrix randomCSRSparseMatrix(int nRows, int nCols, int nNonZero, RandomLongGenerator uniform)
nRows
- the number of rowsnCols
- the number of columnsnNonZero
- the number of non-zero elementsuniform
- a uniform random number generatorpublic static Matrix randomPositiveDefiniteMatrix(int dim, RandomNumberGenerator rng)
dim
- the matrix dimensionrng
- a random number generatorCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.