public class MatrixUtils extends Object
DoubleMatrix2D shorthands and utility methods.| Constructor and Description |
|---|
MatrixUtils() |
| Modifier and Type | Method and Description |
|---|---|
static double |
computeOrthogonality(org.apache.mahout.math.matrix.DoubleMatrix2D A)
Computes the orthogonality of matrix A.
|
static double |
computeSparseness(org.apache.mahout.math.matrix.DoubleMatrix2D A)
Computers sparseness of matrix
A as a fraction of non-zero elements to
the total number of elements. |
static double |
frobeniusNorm(org.apache.mahout.math.matrix.DoubleMatrix2D matrix)
Calculates the Frobenius norm of a matrix.
|
static int[] |
maxInColumns(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int[] indices,
double[] maxValues)
Finds the first maximum element in each column of matrix A.
|
static int[] |
maxInColumns(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int[] indices,
double[] maxValues,
org.apache.mahout.math.function.DoubleFunction transform) |
static int |
maxInRow(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int row)
Finds the index of the first maximum element in given row of
A. |
static int[] |
minInColumns(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int[] indices,
double[] minValues)
Finds the first minimum element in each column of matrix A.
|
static org.apache.mahout.math.matrix.DoubleMatrix2D |
normalizeColumnL1(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] work)
Normalizes column vectors of matrix
A so that their L1 norm is equal
to 1.0. |
static org.apache.mahout.math.matrix.DoubleMatrix2D |
normalizeColumnL2(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] work)
Normalizes column vectors of matrix
A so that their L2 norm (Euclidean
distance) is equal to 1.0. |
static org.apache.mahout.math.matrix.DoubleMatrix2D |
normalizeSparseColumnL2(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] work)
Normalizes column vectors of a sparse matrix
A so that their L2 norm
(Euclidean distance) is equal to 1.0. |
static org.apache.mahout.math.matrix.DoubleMatrix2D |
sortedRowsView(org.apache.mahout.math.matrix.DoubleMatrix2D matrix,
com.carrotsearch.hppc.sorting.IndirectComparator comparator)
Returns view of the provided matrix with rows permuted according to the order
defined by the provided comparator.
|
static double[] |
sumRows(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] sums)
Calculates the sum of rows of matrix
A. |
public static org.apache.mahout.math.matrix.DoubleMatrix2D normalizeColumnL2(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] work)
A so that their L2 norm (Euclidean
distance) is equal to 1.0.A - matrix to normalizework - a temporary array of A.columns() doubles that will be
overwritten with column's original L2 norms. Supply a non-null pointer
to avoid continuous allocation/freeing of memory when doing calculations
in a loop. If this parameter is null, a new array will be
allocated every time this method is called.public static org.apache.mahout.math.matrix.DoubleMatrix2D normalizeSparseColumnL2(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] work)
A so that their L2 norm
(Euclidean distance) is equal to 1.0.A - matrix to normalizework - a temporary array of A.columns() doubles that will be
overwritten with column's original L2 norms. Supply a non-null pointer
to avoid continuous allocation/freeing of memory when doing calculations
in a loop. If this parameter is null, a new array will be
allocated every time this method is called.public static org.apache.mahout.math.matrix.DoubleMatrix2D normalizeColumnL1(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] work)
A so that their L1 norm is equal
to 1.0.A - matrix to normalizework - a temporary array of A.columns() doubles that will be
overwritten with column's original L1 norms. Supply a non-null pointer
to avoid continuous allocation/freeing of memory when doing calculations
in a loop. If this parameter is null, a new array will be
allocated every time this method is called.public static double computeOrthogonality(org.apache.mahout.math.matrix.DoubleMatrix2D A)
A - matrix to compute orthogonality for, must be column length-normalizedpublic static double computeSparseness(org.apache.mahout.math.matrix.DoubleMatrix2D A)
A as a fraction of non-zero elements to
the total number of elements.A, which is a value between 0.0 (all elements
are zero) and 1.0 (all elements are non-zero)public static int[] minInColumns(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int[] indices,
double[] minValues)
indices - an array of A.columns() integers in which indices of
the first minimum element will be stored. If this parameter is
null a new array will be allocated.minValues - an array of A.columns() doubles in which values of
each column's minimum elements will be stored. If this parameter is
null a new array will be allocated.public static int[] maxInColumns(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int[] indices,
double[] maxValues)
A - indices - an array of A.columns() integers in which indices of
the first maximum element will be stored. If this parameter is
null a new array will be allocated.maxValues - an array of A.columns() doubles in which values of
each column's maximum elements will be stored. If this parameter is
null a new array will be
allocated.public static int[] maxInColumns(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int[] indices,
double[] maxValues,
org.apache.mahout.math.function.DoubleFunction transform)
public static int maxInRow(org.apache.mahout.math.matrix.DoubleMatrix2D A,
int row)
A.A - the matrix to searchrow - the row to searchnull or has zero size.public static double[] sumRows(org.apache.mahout.math.matrix.DoubleMatrix2D A,
double[] sums)
A.sums - an array to store the results. If the array is null or
does not match the number of rows in matrix A, a new array
will be created.Apublic static double frobeniusNorm(org.apache.mahout.math.matrix.DoubleMatrix2D matrix)
public static org.apache.mahout.math.matrix.DoubleMatrix2D sortedRowsView(org.apache.mahout.math.matrix.DoubleMatrix2D matrix,
com.carrotsearch.hppc.sorting.IndirectComparator comparator)
matrix - to permutecomparator - to use