public class MatlibMatrixUtils extends Object
Matrix
instances from Adrian Kuhn's
library.Constructor and Description |
---|
MatlibMatrixUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
any(Vector v) |
static <T extends Matrix> |
appendColumn(T m,
Vector col) |
static <T extends Matrix> |
appendRow(T m,
Vector row) |
static com.jmatio.types.MLDouble |
asMatlab(Matrix m) |
static <T extends Matrix> |
copy(T sparseMatrix)
Copy a matrix
|
static Matrix |
dotProduct(Matrix X,
Matrix W)
Compute the dot product X.W
|
static Matrix |
dotProductTranspose(Matrix A,
Matrix B)
Compute Y = A .
|
static <T extends Matrix> |
dotProductTranspose(Matrix A,
Matrix B,
T Y)
Y = A .
|
static Matrix |
dotProductTransposeTranspose(Matrix A,
Matrix B)
Perform: A.T.dot(B.T) without performing the transpose.
|
static Matrix |
fromCF(gov.sandia.cognition.math.matrix.Matrix init)
Create a
Matrix from the Cognitive Foundry equivalent |
static Matrix |
fromJama(Jama.Matrix sol) |
static Matrix |
fromMatlab(com.jmatio.types.MLArray mlArray)
Create a
Matrix from a matlab MLArray |
static Vector |
lessThan(Vector v,
double d) |
static double |
max(Matrix mat)
uses the second value returned by
minmaxmean(Matrix) |
static SparseMatrix |
maxInplace(SparseMatrix A,
SparseMatrix B) |
static double |
mean(Matrix mat)
uses the third value returned by
minmaxmean(Matrix) |
static double |
min(Matrix mat)
uses the first value returned by
minmaxmean(Matrix) |
static SparseMatrix |
minInplace(SparseMatrix A,
SparseMatrix B) |
static double[] |
minmaxmean(Matrix mat)
|
static <T extends Matrix> |
minus(double v,
T l) |
static Matrix |
minus(Matrix A,
Matrix B)
Subtract matrices A-B
|
static <T extends Matrix> |
minus(T l,
double v) |
static Vector |
minus(Vector l,
Vector v) |
static <T extends Matrix> |
minusInplace(DiagonalMatrix D,
T A)
Subtract two matrices, storing the result in the second:
A = D - A |
static Matrix |
minusInplace(Matrix A,
Matrix B)
Subtract two matrices, storing the result in the first:
A = A - B |
static <T extends Vector> |
minusInplace(T A,
Vector D)
Subtract a vector from another vector
A = A - D |
static double |
norm2(Vector row)
Compute the 2-norm (Euclidean norm) of the vector
|
static double |
normF(Matrix A)
Compute the Frobenius norm
|
static <T extends Matrix> |
plusInplace(DiagonalMatrix D,
T A)
Add two matrices, storing the results in the second:
A = D + A |
static SparseMatrix |
plusInplace(SparseMatrix A,
Matrix B)
Add two matrices, storing the results in the first:
A = A + B |
static <T extends Matrix> |
plusInplace(T A,
double d)
Add a constant inplace
A = A + d |
static <T extends Matrix> |
plusInplace(T A,
Matrix B)
Add two matrices, storing the results in the first:
A = A + B |
static <T extends Vector> |
plusInplace(T A,
Vector D)
Subtract a vector from another vector
A = A + D |
static <T extends Matrix> |
powInplace(T matrix,
double d)
Raise each element to the power d, operating on the matrix itself
|
static <T extends Matrix> |
scaleInplace(T A,
double s)
A = A .
|
static void |
setSubMatrix(Matrix to,
int row,
int col,
Matrix from)
Set a submatrix of a larger matrix
|
static void |
setSubMatrixCol(Matrix to,
int row,
int col,
Vector v)
Starting from a given row of a column, set the values of a matrix to the
values of v
|
static void |
setSubMatrixRow(Matrix to,
int row,
int col,
Vector v)
Starting from a given column of a row, set the values of a matrix to the
values of v
|
static void |
setSubVector(Vector to,
int startindex,
Vector from) |
static SparseDoubleArray |
sparseVectorToSparseArray(SparseVector row)
Convert a
SparseVector to a
SparseDoubleArray . |
static double |
sparsity(Matrix mat)
Compute the matrix sparsity (i.e.
|
static <T extends Matrix> |
subMatrix(T mat,
int rowstart,
int rowend,
int colstart,
int colend)
Extract the submatrix of the same type of mat
|
static <T extends Matrix> |
subMatrix(T mat,
int rowstart,
int rowend,
gnu.trove.list.array.TIntArrayList cols) |
static <T extends Matrix> |
subMatrix(T mat,
gnu.trove.list.array.TIntArrayList rows,
int colstart,
int colend) |
static <T extends Matrix> |
subMatrix(T mat,
gnu.trove.TIntCollection rows,
gnu.trove.TIntCollection cols)
Extract a submatrix from the given rows and cols
|
static double |
sum(DiagonalMatrix d)
Sum the diagonal of the given matrix
|
static SparseMatrix |
threshold(SparseMatrix data,
double thresh)
Set values below the given threshold to zero in the output matrix.
|
static SparseMatrix |
times(DiagonalMatrix D,
SparseMatrix A)
Left multiply two matrices:
R = D . |
static SparseMatrix |
times(SparseMatrix A,
DiagonalMatrix D)
Right multiply two matrices:
R = A . |
static Matrix |
timesInplace(Matrix A,
Matrix B) |
static SparseMatrix |
timesInplace(SparseMatrix A,
SparseMatrix B) |
static Jama.Matrix |
toColJama(Vector vector) |
static Jama.Matrix |
toJama(Matrix laplacian) |
static no.uib.cipr.matrix.Matrix |
toMTJ(Matrix sol) |
static Jama.Matrix |
toRowJama(Vector vector) |
static <T extends Matrix> |
transpose(T mat)
Transpose a matrix, returning a new matrix.
|
static Matrix |
transposeDotProduct(Matrix A,
Matrix B)
Compute A^T .
|
static Matrix |
vstack(Matrix... matricies)
Stack matrices vertically
|
public MatlibMatrixUtils()
public static double sparsity(Matrix mat)
mat
- the matrixMatrix.density()
public static <T extends Matrix> T powInplace(T matrix, double d)
matrix
- the matrixd
- the powerpublic static SparseMatrix times(DiagonalMatrix D, SparseMatrix A)
R = D . A
D
- first matrixA
- second matrixpublic static SparseMatrix times(SparseMatrix A, DiagonalMatrix D)
R = A . D
D
- first matrixA
- second matrixpublic static SparseMatrix plusInplace(SparseMatrix A, Matrix B)
A = A + B
A
- first matrixB
- matrix to addpublic static <T extends Matrix> T plusInplace(T A, Matrix B)
A = A + B
A
- first matrixB
- matrix to addpublic static <T extends Matrix> T plusInplace(T A, double d)
A = A + d
A
- first matrixd
- the constant to addpublic static <T extends Matrix> T minusInplace(DiagonalMatrix D, T A)
A = D - A
D
- first matrixA
- second matrixpublic static Matrix minusInplace(Matrix A, Matrix B)
A = A - B
A
- first matrixB
- second matrixpublic static <T extends Vector> T minusInplace(T A, Vector D)
A = A - D
A
- first matrixD
- second matrixpublic static <T extends Vector> T plusInplace(T A, Vector D)
A = A + D
A
- first matrixD
- second matrixpublic static <T extends Matrix> T plusInplace(DiagonalMatrix D, T A)
A = D + A
D
- first matrixA
- second matrixpublic static Matrix transposeDotProduct(Matrix A, Matrix B)
A
- B
- public static Matrix dotProductTranspose(Matrix A, Matrix B)
A
- B
- public static Matrix dotProductTransposeTranspose(Matrix A, Matrix B)
A
- B
- public static <T extends Matrix> T dotProductTranspose(Matrix A, Matrix B, T Y)
A
- B
- Y
- public static <T extends Matrix> T scaleInplace(T A, double s)
A
- s
- public static Jama.Matrix toJama(Matrix laplacian)
laplacian
- public static Jama.Matrix toColJama(Vector vector)
vector
- public static Jama.Matrix toRowJama(Vector vector)
vector
- public static Matrix fromJama(Jama.Matrix sol)
sol
- Matrix
public static no.uib.cipr.matrix.Matrix toMTJ(Matrix sol)
sol
- Matrix
public static <T extends Matrix> T subMatrix(T mat, int rowstart, int rowend, int colstart, int colend)
mat
- rowstart
- rowend
- colstart
- colend
- public static <T extends Matrix> T subMatrix(T mat, gnu.trove.TIntCollection rows, gnu.trove.TIntCollection cols)
mat
- the matrix to extract fromrows
- the rows to extractcols
- the columns to extractpublic static <T extends Matrix> T subMatrix(T mat, gnu.trove.list.array.TIntArrayList rows, int colstart, int colend)
mat
- rows
- colstart
- colend
- public static <T extends Matrix> T subMatrix(T mat, int rowstart, int rowend, gnu.trove.list.array.TIntArrayList cols)
mat
- rowstart
- rowend
- cols
- public static com.jmatio.types.MLDouble asMatlab(Matrix m)
m
- MLDouble
for matlabpublic static double[] minmaxmean(Matrix mat)
mat
- public static double min(Matrix mat)
minmaxmean(Matrix)
mat
- public static double max(Matrix mat)
minmaxmean(Matrix)
mat
- public static double mean(Matrix mat)
minmaxmean(Matrix)
mat
- public static <T extends Matrix> T minus(T l, double v)
l
- v
- public static Vector minus(Vector l, Vector v)
l
- v
- public static <T extends Matrix> T minus(double v, T l)
v
- l
- public static Matrix fromMatlab(com.jmatio.types.MLArray mlArray)
Matrix
from a matlab MLArray
mlArray
- the matlab arraypublic static double sum(DiagonalMatrix d)
d
- the matrixpublic static void setSubMatrix(Matrix to, int row, int col, Matrix from)
to
- the matrix to write intorow
- the row to start inserting fromcol
- the column to start inserting fromfrom
- the matrix to insertpublic static <T extends Matrix> T transpose(T mat)
mat
- the matrix to transposepublic static SparseMatrix maxInplace(SparseMatrix A, SparseMatrix B)
A
- B
- public static SparseMatrix minInplace(SparseMatrix A, SparseMatrix B)
A
- B
- public static SparseMatrix timesInplace(SparseMatrix A, SparseMatrix B)
A
- B
- public static Matrix timesInplace(Matrix A, Matrix B)
A
- B
- public static <T extends Matrix> T copy(T sparseMatrix)
sparseMatrix
- the matrix to copypublic static SparseMatrix threshold(SparseMatrix data, double thresh)
data
- the input matrixthresh
- the thresholdpublic static SparseDoubleArray sparseVectorToSparseArray(SparseVector row)
SparseVector
to a
SparseDoubleArray
.row
- the vector to convertpublic static void setSubVector(Vector to, int startindex, Vector from)
to
- add items to thisstartindex
- starting index in tofrom
- add items from thispublic static void setSubMatrixRow(Matrix to, int row, int col, Vector v)
to
- row
- col
- v
- public static void setSubMatrixCol(Matrix to, int row, int col, Vector v)
to
- row
- col
- v
- public static Vector lessThan(Vector v, double d)
v
- the value vectord
- the check valuepublic static boolean any(Vector v)
v
- public static <T extends Matrix> T appendColumn(T m, Vector col)
m
- col
- public static <T extends Matrix> T appendRow(T m, Vector row)
m
- row
- public static Matrix fromCF(gov.sandia.cognition.math.matrix.Matrix init)
Matrix
from the Cognitive Foundry equivalentinit
- the matrixpublic static Matrix dotProduct(Matrix X, Matrix W)
X
- W
- public static double norm2(Vector row)
row
- the vectorpublic static Matrix minus(Matrix A, Matrix B)
A
- B
- public static double normF(Matrix A)
A
- the matrix