Package com.macrofocus.high_d.mds.pca
Class PCAMatrix
java.lang.Object
com.macrofocus.high_d.mds.pca.PCAMatrix
-
Constructor Summary
ConstructorsConstructorDescriptionPCAMatrix
(double[][] A) Construct a matrix from a 2-D array.PCAMatrix
(double[][] A, int m, int n) Construct a matrix quickly without checking arguments.PCAMatrix
(double[] vals, int m) Construct a matrix from a one-dimensional packed arrayPCAMatrix
(int m, int n) Construct an m-by-n matrix of zeros.PCAMatrix
(int m, int n, double s) Construct an m-by-n constant matrix. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Make a deep copy of a matrixdouble
get
(int i, int j) Get a single element.double[][]
getArray()
Access the internal two-dimensional array.double[][]
Copy the internal two-dimensional array.int
Get column dimension.int
Get row dimension.static double
hypot
(double a, double b) sqrt(a^2 + b^2) without under/overflow.static PCAMatrix
identity
(int m, int n) Generate identity matrixC = A - Bstatic PCAMatrix
random
(int m, int n) Generate matrix with random elementsvoid
set
(int i, int j, double s) Set a single element.times
(double s) Multiply a matrix by a scalar, C = s*ALinear algebraic matrix multiplication, A * Bdouble
trace()
Matrix trace.Matrix transpose.
-
Constructor Details
-
PCAMatrix
public PCAMatrix(int m, int n) Construct an m-by-n matrix of zeros.- Parameters:
m
- Number of rows.n
- Number of colums.
-
PCAMatrix
public PCAMatrix(int m, int n, double s) Construct an m-by-n constant matrix.- Parameters:
m
- Number of rows.n
- Number of colums.s
- Fill the matrix with this scalar value.
-
PCAMatrix
public PCAMatrix(double[][] A) Construct a matrix from a 2-D array.- Parameters:
A
- Two-dimensional array of doubles.- Throws:
IllegalArgumentException
- All rows must have the same length
-
PCAMatrix
public PCAMatrix(double[][] A, int m, int n) Construct a matrix quickly without checking arguments.- Parameters:
A
- Two-dimensional array of doubles.m
- Number of rows.n
- Number of colums.
-
PCAMatrix
public PCAMatrix(double[] vals, int m) Construct a matrix from a one-dimensional packed array- Parameters:
vals
- One-dimensional array of doubles, packed by columns (ala Fortran).m
- Number of rows.- Throws:
IllegalArgumentException
- Array length must be a multiple of m.
-
-
Method Details
-
identity
Generate identity matrix- Parameters:
m
- Number of rows.n
- Number of colums.- Returns:
- An m-by-n matrix with ones on the diagonal and zeros elsewhere.
-
getArray
public double[][] getArray()Access the internal two-dimensional array.- Returns:
- Pointer to the two-dimensional array of matrix elements.
-
random
Generate matrix with random elements- Parameters:
m
- Number of rows.n
- Number of colums.- Returns:
- An m-by-n matrix with uniformly distributed random elements.
-
hypot
public static double hypot(double a, double b) sqrt(a^2 + b^2) without under/overflow. -
copy
Make a deep copy of a matrix -
getArrayCopy
public double[][] getArrayCopy()Copy the internal two-dimensional array.- Returns:
- Two-dimensional array copy of matrix elements.
-
getRowDimension
public int getRowDimension()Get row dimension.- Returns:
- m, the number of rows.
-
getColumnDimension
public int getColumnDimension()Get column dimension.- Returns:
- n, the number of columns.
-
get
public double get(int i, int j) Get a single element.- Parameters:
i
- Row index.j
- Column index.- Returns:
- A(i, j)
- Throws:
ArrayIndexOutOfBoundsException
-
set
public void set(int i, int j, double s) Set a single element.- Parameters:
i
- Row index.j
- Column index.s
- A(i,j).- Throws:
ArrayIndexOutOfBoundsException
-
times
Multiply a matrix by a scalar, C = s*A- Parameters:
s
- scalar- Returns:
- s*A
-
minus
C = A - B- Parameters:
B
- another matrix- Returns:
- A - B
-
times
Linear algebraic matrix multiplication, A * B- Parameters:
B
- another matrix- Returns:
- Matrix product, A * B
- Throws:
IllegalArgumentException
- Matrix inner dimensions must agree.
-
trace
public double trace()Matrix trace.- Returns:
- sum of the diagonal elements.
-
transpose
Matrix transpose.- Returns:
- A'
-