public class FloatMatrix extends SMatrix
Modifier and Type | Class and Description |
---|---|
static class |
FloatMatrix.Cholesky
The Cholesky decomposition of a symmetric, positive-definite matrix.
|
static class |
FloatMatrix.EVD
Eigenvalue decomposition.
|
static class |
FloatMatrix.LU
The LU decomposition.
|
static class |
FloatMatrix.QR
The QR decomposition.
|
static class |
FloatMatrix.SVD
Singular Value Decomposition.
|
Constructor and Description |
---|
FloatMatrix(float[] A)
Constructor of a column vector/matrix with given array as the internal storage.
|
FloatMatrix(float[][] A)
Constructor.
|
FloatMatrix(float[] A,
int offset,
int length)
Constructor of a column vector/matrix with given array as the internal storage.
|
FloatMatrix(int m,
int n)
Constructor of zero matrix.
|
FloatMatrix(int m,
int n,
float a)
Constructor.
|
FloatMatrix(int m,
int n,
float[][] A)
Constructor.
|
FloatMatrix(int m,
int n,
int ld,
java.nio.FloatBuffer A)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
FloatMatrix |
aat()
Returns A * A'
|
FloatMatrix |
adb(Transpose transA,
Transpose transB,
FloatMatrix B,
float[] diag)
Returns A * D * B, where D is a diagonal matrix.
|
FloatMatrix |
add(float b)
A += b
|
FloatMatrix |
add(float alpha,
float[] x,
float[] y)
Rank-1 update A += alpha * x * y'
|
FloatMatrix |
add(float alpha,
float beta,
FloatMatrix B)
Element-wise addition A = alpha * A + beta * B
|
FloatMatrix |
add(float alpha,
FloatMatrix B)
Element-wise addition A += alpha * B
|
FloatMatrix |
add(float alpha,
FloatMatrix A,
float beta,
FloatMatrix B)
Element-wise addition C = alpha * A + beta * B
|
FloatMatrix |
add(FloatMatrix B)
Element-wise addition A += B
|
float |
add(int i,
int j,
float b)
A[i,j] += b
|
double |
add(int i,
int j,
float alpha,
float beta)
A[i,j] = alpha * A[i,j] + beta
|
FloatMatrix |
add(int i,
int j,
float alpha,
float beta,
FloatMatrix B)
Element-wise submatrix addition A[i, j] = alpha * A[i, j] + beta * B
|
FloatMatrix |
add(int i,
int j,
float alpha,
FloatMatrix B)
Element-wise submatrix addition A[i, j] += alpha * B
|
FloatMatrix |
ata()
Returns A' * A
|
FloatMatrix.Cholesky |
cholesky()
Cholesky decomposition for symmetric and positive definite matrix.
|
FloatMatrix.Cholesky |
cholesky(boolean overwrite)
Cholesky decomposition for symmetric and positive definite matrix.
|
FloatMatrix |
clone()
Returns a deep copy of matrix.
|
FloatMatrix |
col(int... cols)
Returns the matrix of selected columns.
|
double[] |
col(int j)
Returns the j-th column.
|
float[] |
colMeans()
Returns the mean of each column.
|
float[] |
colSds()
Returns the standard deviations of each column.
|
float[] |
colSums()
Returns the sum of each column.
|
static FloatMatrix |
diag(float[] diag)
Returns a square diagonal matrix with the elements of vector
v on the main diagonal.
|
FloatMatrix |
div(float b)
A /= b
|
FloatMatrix |
div(float alpha,
FloatMatrix B)
Element-wise division A /= alpha * B
|
FloatMatrix |
div(float alpha,
FloatMatrix A,
FloatMatrix B)
Element-wise division C = alpha * A / B
|
FloatMatrix |
div(FloatMatrix B)
Element-wise division A /= B
|
float |
div(int i,
int j,
float b)
A[i,j] /= b
|
FloatMatrix |
div(int i,
int j,
float alpha,
FloatMatrix B)
Element-wise submatrix division A[i, j] /= alpha * B
|
FloatMatrix.EVD |
eigen()
Eigenvalue Decomposition.
|
FloatMatrix.EVD |
eigen(boolean vl,
boolean vr,
boolean overwrite)
Eigenvalue Decomposition.
|
boolean |
equals(FloatMatrix o,
float eps)
Returns if two matrices equals given an error margin.
|
boolean |
equals(java.lang.Object o) |
static FloatMatrix |
eye(int n)
Returns an n-by-n identity matrix.
|
static FloatMatrix |
eye(int m,
int n)
Returns an m-by-n identity matrix.
|
void |
fill(float x)
Fill the matrix with a value.
|
float |
get(int i,
int j)
Returns A[i, j].
|
protected int |
index(int i,
int j)
Returns the linear index of matrix element.
|
FloatMatrix |
inverse()
Returns the inverse matrix.
|
boolean |
isSubmatrix()
Returns if the matrix is a submatrix.
|
boolean |
isSymmetric()
Return if the matrix is symmetric (uplo != null && diag == null).
|
Layout |
layout()
Returns the matrix layout.
|
int |
ld()
Returns the leading dimension.
|
FloatMatrix.LU |
lu()
LU decomposition.
|
FloatMatrix.LU |
lu(boolean overwrite)
LU decomposition.
|
FloatMatrix |
mm(FloatMatrix B)
Returns matrix multiplication A * B.
|
void |
mm(Transpose transA,
Transpose transB,
float alpha,
FloatMatrix B,
float beta,
FloatMatrix C)
Matrix-matrix multiplication.
|
FloatMatrix |
mt(FloatMatrix B)
Returns matrix multiplication A * B'.
|
FloatMatrix |
mul(float b)
A *= b
|
FloatMatrix |
mul(float alpha,
FloatMatrix B)
Element-wise multiplication A *= alpha * B
|
FloatMatrix |
mul(float alpha,
FloatMatrix A,
FloatMatrix B)
Element-wise multiplication C = alpha * A * B
|
FloatMatrix |
mul(FloatMatrix B)
Element-wise multiplication A *= B
|
float |
mul(int i,
int j,
float b)
A[i,j] *= b
|
FloatMatrix |
mul(int i,
int j,
float alpha,
FloatMatrix B)
Element-wise submatrix multiplication A[i, j] *= alpha * B
|
void |
mv(float[] work,
int inputOffset,
int outputOffset)
Matrix-vector multiplication A * x.
|
void |
mv(Transpose trans,
float alpha,
float[] x,
float beta,
float[] y)
Matrix-vector multiplication.
|
void |
mv(Transpose trans,
float alpha,
java.nio.FloatBuffer x,
float beta,
java.nio.FloatBuffer y)
Matrix-vector multiplication.
|
int |
ncols()
Returns the number of columns.
|
float |
norm()
L2 matrix norm.
|
float |
norm1()
L1 matrix norm.
|
float |
norm2()
L2 matrix norm.
|
float |
normFro()
Frobenius matrix norm.
|
float |
normInf()
Infinity matrix norm.
|
int |
nrows()
Returns the number of rows.
|
static FloatMatrix |
of(Layout layout,
int m,
int n)
Creates a matrix.
|
static FloatMatrix |
of(Layout layout,
int m,
int n,
int ld,
java.nio.FloatBuffer A)
Creates a matrix.
|
FloatMatrix.QR |
qr()
QR Decomposition.
|
FloatMatrix.QR |
qr(boolean overwrite)
QR Decomposition.
|
static FloatMatrix |
rand(int m,
int n,
Distribution distribution)
Returns a random matrix.
|
static FloatMatrix |
rand(int m,
int n,
float lo,
float hi)
Returns a random matrix of uniform distribution.
|
static FloatMatrix |
randn(int m,
int n)
Returns a random matrix of standard normal distribution.
|
FloatMatrix |
replaceNaN(float x)
Replaces NaN's with given value.
|
FloatMatrix |
row(int... rows)
Returns the matrix of selected rows.
|
double[] |
row(int i)
Returns the i-th row.
|
float[] |
rowMeans()
Returns the mean of each row.
|
float[] |
rowSds()
Returns the standard deviations of each row.
|
float[] |
rowSums()
Returns the sum of each row.
|
FloatMatrix |
scale()
Centers and scales the columns of matrix.
|
FloatMatrix |
scale(float[] center,
float[] scale)
Centers and scales the columns of matrix.
|
FloatMatrix |
set(int i,
int j,
float x)
Sets A[i,j] = x.
|
FloatMatrix |
set(int i,
int j,
FloatMatrix B)
Sets submatrix A[i,j] = B.
|
long |
size()
Returns the number of stored matrix elements.
|
FloatMatrix |
sub(float b)
A -= b
|
FloatMatrix |
sub(float alpha,
FloatMatrix B)
Element-wise subtraction A -= alpha * B
|
FloatMatrix |
sub(float alpha,
FloatMatrix A,
float beta,
FloatMatrix B)
Element-wise subtraction C = alpha * A - beta * B
|
FloatMatrix |
sub(FloatMatrix B)
Element-wise subtraction A -= B
|
float |
sub(int i,
int j,
float b)
A[i,j] -= b
|
FloatMatrix |
sub(int i,
int j,
float alpha,
FloatMatrix B)
Element-wise submatrix subtraction A[i, j] -= alpha * B
|
FloatMatrix |
submatrix(int i,
int j,
int k,
int l)
Returns the submatrix which top left at (i, j) and bottom right at (k, l).
|
float |
sum()
Returns the sum of all elements in the matrix.
|
FloatMatrix.SVD |
svd()
Singular Value Decomposition.
|
FloatMatrix.SVD |
svd(boolean vectors,
boolean overwrite)
Singular Value Decomposition.
|
FloatMatrix |
tm(FloatMatrix B)
Returns matrix multiplication A' * B.
|
float[][] |
toArray()
Return the two-dimensional array of matrix.
|
static FloatMatrix |
toeplitz(float[] a)
Returns a symmetric Toeplitz matrix in which each descending diagonal
from left to right is constant.
|
static FloatMatrix |
toeplitz(float[] kl,
float[] ku)
Returns a Toeplitz matrix in which each descending diagonal
from left to right is constant.
|
FloatMatrix |
transpose()
Returns the transpose of matrix.
|
Diag |
triangular()
Gets the flag if a triangular matrix has unit diagonal elements.
|
FloatMatrix |
triangular(Diag diag)
Sets/unsets if the matrix is triangular.
|
FloatMatrix |
tt(FloatMatrix B)
Returns matrix multiplication A' * B'.
|
void |
tv(float[] work,
int inputOffset,
int outputOffset)
Matrix-vector multiplication A' * x.
|
UPLO |
uplo()
Gets the format of packed matrix.
|
FloatMatrix |
uplo(UPLO uplo)
Sets the format of packed matrix.
|
float |
xAx(float[] x)
Returns x' * A * x.
|
apply, diag, market, mv, mv, mv, trace, tv, tv, tv, update
public FloatMatrix(int m, int n)
m
- the number of rows.n
- the number of columns.public FloatMatrix(int m, int n, float a)
m
- the number of rows.n
- the number of columns.a
- the initial value.public FloatMatrix(int m, int n, float[][] A)
m
- the number of rows.n
- the number of columns.A
- the array of matrix.public FloatMatrix(float[][] A)
A
- the array of matrix.public FloatMatrix(float[] A)
A
- The array of column vector.public FloatMatrix(float[] A, int offset, int length)
A
- The array of column vector.offset
- The offset of the subarray to be used; must be non-negative and
no larger than array.length.length
- The length of the subarray to be used; must be non-negative and
no larger than array.length - offset.public FloatMatrix(int m, int n, int ld, java.nio.FloatBuffer A)
m
- the number of rows.n
- the number of columns.ld
- the leading dimension.A
- the matrix storage.public static FloatMatrix of(Layout layout, int m, int n)
layout
- the matrix layout.m
- the number of rows.n
- the number of columns.public static FloatMatrix of(Layout layout, int m, int n, int ld, java.nio.FloatBuffer A)
layout
- the matrix layout.m
- the number of rows.n
- the number of columns.ld
- the leading dimension.A
- the matrix storage.public static FloatMatrix eye(int n)
n
- the number of rows/columns.public static FloatMatrix eye(int m, int n)
m
- the number of rows.n
- the number of columns.public static FloatMatrix randn(int m, int n)
public static FloatMatrix rand(int m, int n, Distribution distribution)
distribution
- the distribution of random number.public static FloatMatrix rand(int m, int n, float lo, float hi)
lo
- the lower bound of uniform distribution.hi
- the upper bound of uniform distribution.public static FloatMatrix diag(float[] diag)
diag
- the diagonal elements.public static FloatMatrix toeplitz(float[] a)
a
- A[i, j] = a[i - j] for i >= j (or a[j - i] when j > i)public static FloatMatrix toeplitz(float[] kl, float[] ku)
kl
- A[i, j] = kl[i - j] for i > jku
- A[i, j] = ku[j - i] for i <= jpublic int nrows()
IMatrix
public int ncols()
IMatrix
public long size()
IMatrix
public Layout layout()
public int ld()
public boolean isSubmatrix()
public boolean isSymmetric()
public FloatMatrix uplo(UPLO uplo)
public UPLO uplo()
public FloatMatrix triangular(Diag diag)
diag
- if not null, it specifies if the triangular matrix has unit diagonal elements.public Diag triangular()
public FloatMatrix clone()
clone
in class java.lang.Object
public float[][] toArray()
public double[] row(int i)
public double[] col(int j)
public FloatMatrix row(int... rows)
public FloatMatrix col(int... cols)
public FloatMatrix submatrix(int i, int j, int k, int l)
i
- the beginning row, inclusive.j
- the beginning column, inclusive,k
- the ending row, inclusive.l
- the ending column, inclusive.public void fill(float x)
public FloatMatrix transpose()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public boolean equals(FloatMatrix o, float eps)
o
- the other matrix.eps
- the error margin.protected int index(int i, int j)
public float get(int i, int j)
SMatrix
public FloatMatrix set(int i, int j, float x)
SMatrix
public FloatMatrix set(int i, int j, FloatMatrix B)
public float add(int i, int j, float b)
public float sub(int i, int j, float b)
public float mul(int i, int j, float b)
public float div(int i, int j, float b)
public FloatMatrix add(float b)
public FloatMatrix sub(float b)
public FloatMatrix mul(float b)
public FloatMatrix div(float b)
public FloatMatrix add(int i, int j, float alpha, FloatMatrix B)
public FloatMatrix sub(int i, int j, float alpha, FloatMatrix B)
public FloatMatrix mul(int i, int j, float alpha, FloatMatrix B)
public FloatMatrix div(int i, int j, float alpha, FloatMatrix B)
public FloatMatrix add(FloatMatrix B)
public FloatMatrix sub(FloatMatrix B)
public FloatMatrix mul(FloatMatrix B)
public FloatMatrix div(FloatMatrix B)
public FloatMatrix add(float alpha, FloatMatrix B)
public FloatMatrix sub(float alpha, FloatMatrix B)
public FloatMatrix mul(float alpha, FloatMatrix B)
public FloatMatrix div(float alpha, FloatMatrix B)
public FloatMatrix add(float alpha, FloatMatrix A, float beta, FloatMatrix B)
public FloatMatrix sub(float alpha, FloatMatrix A, float beta, FloatMatrix B)
public FloatMatrix mul(float alpha, FloatMatrix A, FloatMatrix B)
public FloatMatrix div(float alpha, FloatMatrix A, FloatMatrix B)
public double add(int i, int j, float alpha, float beta)
public FloatMatrix add(int i, int j, float alpha, float beta, FloatMatrix B)
public FloatMatrix add(float alpha, float beta, FloatMatrix B)
public FloatMatrix add(float alpha, float[] x, float[] y)
public FloatMatrix replaceNaN(float x)
public float sum()
public float norm1()
public float norm2()
public float norm()
public float normInf()
public float normFro()
public float xAx(float[] x)
public float[] rowSums()
public float[] rowMeans()
public float[] rowSds()
public float[] colSums()
public float[] colMeans()
public float[] colSds()
public FloatMatrix scale()
public FloatMatrix scale(float[] center, float[] scale)
center
- column center. If null, no centering.scale
- column scale. If null, no scaling.public FloatMatrix inverse()
public void mv(Transpose trans, float alpha, java.nio.FloatBuffer x, float beta, java.nio.FloatBuffer y)
y = alpha * A * x + beta * y
public void mv(Transpose trans, float alpha, float[] x, float beta, float[] y)
SMatrix
y = alpha * op(A) * x + beta * y
where op is the transpose operation.public void mv(float[] work, int inputOffset, int outputOffset)
IMatrix
public void tv(float[] work, int inputOffset, int outputOffset)
IMatrix
public void mm(Transpose transA, Transpose transB, float alpha, FloatMatrix B, float beta, FloatMatrix C)
C := alpha*A*B + beta*C
public FloatMatrix ata()
public FloatMatrix aat()
public FloatMatrix adb(Transpose transA, Transpose transB, FloatMatrix B, float[] diag)
public FloatMatrix mm(FloatMatrix B)
public FloatMatrix mt(FloatMatrix B)
public FloatMatrix tm(FloatMatrix B)
public FloatMatrix tt(FloatMatrix B)
public FloatMatrix.LU lu()
public FloatMatrix.LU lu(boolean overwrite)
overwrite
- The flag if the decomposition overwrites this matrix.public FloatMatrix.Cholesky cholesky()
java.lang.ArithmeticException
- if the matrix is not positive definite.public FloatMatrix.Cholesky cholesky(boolean overwrite)
overwrite
- The flag if the decomposition overwrites this matrix.java.lang.ArithmeticException
- if the matrix is not positive definite.public FloatMatrix.QR qr()
public FloatMatrix.QR qr(boolean overwrite)
overwrite
- The flag if the decomposition overwrites this matrix.public FloatMatrix.SVD svd()
public FloatMatrix.SVD svd(boolean vectors, boolean overwrite)
vectors
- The flag if computing the singular vectors.overwrite
- The flag if the decomposition overwrites this matrix.public FloatMatrix.EVD eigen()
By default eigen
does not always return the eigenvalues
and eigenvectors in sorted order. Use the EVD.sort
function
to put the eigenvalues in descending order and reorder the corresponding
eigenvectors.
public FloatMatrix.EVD eigen(boolean vl, boolean vr, boolean overwrite)
By default eigen
does not always return the eigenvalues
and eigenvectors in sorted order. Use the sort
function
to put the eigenvalues in descending order and reorder the corresponding
eigenvectors.
vl
- The flag if computing the left eigenvectors.vr
- The flag if computing the right eigenvectors.overwrite
- The flag if the decomposition overwrites this matrix.