public class MU
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
MU.MatrixExpander
A tool for growing matrices (similar to java.util.List).
|
static class |
MU.VectorExpander
A tool for growing vectors (similar to java.util.List).
|
Constructor and Description |
---|
MU() |
Modifier and Type | Method and Description |
---|---|
static double[][] |
clone(double[][] matrix) |
static float[][] |
clone(float[][] matrix) |
static float[][][] |
clone(float[][][] matrix) |
static float[] |
convert(double[] vector) |
static float[][] |
convert(double[][] matrix) |
static double[] |
convert(float[] vector) |
static double[][] |
convert(float[][] matrix) |
static float[][] |
copy(float[][] matrix,
int startRow,
int startCol,
int lengthRow,
int lengthCol) |
static float[] |
copy(float[] vector,
int start,
int interval,
int end) |
static void |
copyInto(float[][] src,
float[][] dest,
int destRowPos,
int destColPos,
int length)
Unlike System.arraycopy, this function copies the source matrix into the destination
while preserving the original row length.
|
static float[][] |
diag(float[] entries) |
static float[] |
diag(float[][] matrix) |
static float[] |
difference(float[] X) |
static float[][] |
difference(float[][] A,
float[][] B) |
static float[] |
difference(float[] X,
float[] Y) |
static float[][] |
I(int dimension) |
static boolean |
isMatrix(float[][] matrix) |
static float[] |
makeVector(float start,
float increment,
float end) |
static float |
max(float[] vector) |
static float |
max(float[][] matrix) |
static float |
mean(float[] vector) |
static float |
mean(float[][] matrix) |
static float |
min(float[] vector) |
static float |
min(float[][] matrix) |
static float[] |
normalize(float[] vector) |
static float[][] |
outerprod(float[] A,
float[] B) |
static float[][] |
outerprod(float[] A,
float[] B,
float[][] result,
int offset)
In-place outer product.
|
static float |
pnorm(float[] vector,
int p) |
static float[][] |
prod(float[][] A,
float a) |
static float[] |
prod(float[][] A,
float[] X) |
static float[][] |
prod(float[][] A,
float[][] B) |
static float[] |
prod(float[] X,
float a) |
static float |
prod(float[] X,
float[] Y) |
static float[][] |
prodElementwise(float[][] A,
float[][] B) |
static float[] |
prodElementwise(float[] A,
float[] B) |
static float[][] |
random(int rows,
int cols,
PDF pdf) |
static int[] |
round(float[] vector) |
static float[][] |
shape(float[][] matrix,
int rows,
int cols) |
static float |
sum(float[] vector) |
static float[][] |
sum(float[][] A,
float[][] B) |
static float[] |
sum(float[] X,
float[] Y) |
static float |
sumToIndex(float[] vector,
int index) |
static java.lang.String |
toString(float[][] matrix,
int decimalPlaces)
TODO: handle exponential notation
|
static float[][] |
transpose(float[] vector) |
static float[][] |
transpose(float[][] matrix) |
static float[][] |
uniform(int rows,
int cols,
float value) |
static float |
variance(float[] vector,
float mean) |
static float[][] |
zero(int rows,
int cols) |
public static boolean isMatrix(float[][] matrix)
matrix
- An array of arrays that is expected to be in matrix formpublic static float[][] clone(float[][] matrix)
matrix
- Any matrixpublic static float[][][] clone(float[][][] matrix)
public static double[][] clone(double[][] matrix)
matrix
- Any matrixpublic static void copyInto(float[][] src, float[][] dest, int destRowPos, int destColPos, int length)
src
- - source matrixdest
- - destination matrixdestRowPos
- - starting target rowdestColPos
- - starting target column positionlength
- - number of rows to copypublic static float[] copy(float[] vector, int start, int interval, int end)
vector
- Vector to copy fromstart
- Index in vector from which to start copyinginterval
- Interval separating copied entries in source vector (ie skip over interval-1 entries)end
- Index in vector at which copying endspublic static float[][] copy(float[][] matrix, int startRow, int startCol, int lengthRow, int lengthCol)
matrix
- Matrix to copy fromstartRow
- Row in matrix from which to start copyingstartCol
- Col in matrix from which to start copyinglengthRow
- Number of rows to copy (set to a negative number to copy all the way to the end)lengthCol
- Number of cols to copy (set to a negative number to copy all the way to the end)public static float[] prod(float[] X, float a)
X
- Any vectora
- Any scalarpublic static float prod(float[] X, float[] Y)
X
- Any vectorY
- Any vector of the same length as Xpublic static float[] prod(float[][] A, float[] X)
A
- Any matrixX
- Any vector with the same number of elements as there are columns in Apublic static float[][] prod(float[][] A, float[][] B)
A
- Any m x n matrixB
- Any n x p matrixpublic static float[] prodElementwise(float[] A, float[] B)
A
- Any vectorB
- Any vector the same length as Apublic static float[][] prodElementwise(float[][] A, float[][] B)
A
- Any matrixB
- Any matrix the same dimensions as Apublic static float[][] prod(float[][] A, float a)
A
- Any matrixa
- Any scalarpublic static float[][] outerprod(float[] A, float[] B)
A
- Any vectorB
- Any vectorpublic static float[][] outerprod(float[] A, float[] B, float[][] result, int offset)
A
- Any vectorB
- Any vectorresult
- the destination matrixoffset
- row in destination matrix to insert resultpublic static float[][] sum(float[][] A, float[][] B)
A
- Any m x n matrixB
- Any m x n matrixpublic static float[][] difference(float[][] A, float[][] B)
A
- Any m x n matrixB
- Any m x n matrixpublic static float[] sum(float[] X, float[] Y)
X
- Any vectorY
- Any vector same length as vector Xpublic static float[] difference(float[] X, float[] Y)
X
- Any vectorY
- Any vector same length as vector Xpublic static float[] difference(float[] X)
X
- Any vectorpublic static float[][] shape(float[][] matrix, int rows, int cols)
matrix
- An array of float arrays (normally a matrix but can have rows of different length)rows
- Desired number of rowscols
- Desired number of columnspublic static float[][] transpose(float[] vector)
vector
- Any vectorpublic static float[][] transpose(float[][] matrix)
matrix
- Any matrixpublic static float[][] diag(float[] entries)
entries
- A list of diagonal entriespublic static float[] diag(float[][] matrix)
matrix
- Any matrixpublic static float[][] I(int dimension)
dimension
- # of rows/columnspublic static float[][] zero(int rows, int cols)
rows
- Number of rows in the requested matrixcols
- Number of columns in the requested matrixpublic static float[][] uniform(int rows, int cols, float value)
rows
- Number of rows in the requested matrixcols
- Number of columns in the requested matrixvalue
- Value of each elementpublic static float[][] random(int rows, int cols, PDF pdf)
rows
- Number of rows in the requested matrixcols
- Number of columns in the requested matrixpdf
- One-dimensional PDF from which each element is drawnpublic static double[][] convert(float[][] matrix)
matrix
- Any float matrixpublic static double[] convert(float[] vector)
vector
- Any float vectorpublic static float[][] convert(double[][] matrix)
matrix
- Any double matrixpublic static float[] convert(double[] vector)
vector
- Any double vectorpublic static float min(float[] vector)
vector
- Any vectorpublic static float max(float[] vector)
vector
- Any vectorpublic static float min(float[][] matrix)
matrix
- Any matrixpublic static float max(float[][] matrix)
matrix
- Any matrixpublic static float sum(float[] vector)
vector
- Any vectorpublic static float sumToIndex(float[] vector, int index)
vector
- Any vectorindex
- Index of last element to include in sumpublic static float mean(float[] vector)
vector
- Any vectorpublic static float mean(float[][] matrix)
matrix
- Any matrixpublic static float variance(float[] vector, float mean)
vector
- Any vectormean
- Value around which to take variance, eg MU.mean(vector) or some pre-defined valuepublic static float[] normalize(float[] vector)
vector
- Any vectorpublic static float pnorm(float[] vector, int p)
vector
- Any vectorp
- Degree of p-norm (use -1 for infinity)public static java.lang.String toString(float[][] matrix, int decimalPlaces)
matrix
- Any matrixdecimalPlaces
- number of decimal places to display for float valuespublic static float[] makeVector(float start, float increment, float end)
start
- Value of first element in vectorincrement
- Increment between adjacent elementsend
- Value of last element in vectorstart
to end
public static int[] round(float[] vector)
vector
- A vector