Package cc.mallet.types
Class MatrixOps
- java.lang.Object
-
- cc.mallet.types.MatrixOps
-
public final class MatrixOps extends java.lang.Object
A class of static utility functions for manipulating arrays of double.
-
-
Constructor Summary
Constructors Constructor Description MatrixOps()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static double
absNorm(double[] m)
static double
absNormalize(double[] m)
static double[]
append(double[] original, double newValue)
static double[][]
aTimesB(double[][] a, double[][] b)
static double[][]
aTransposeTimesB(double[][] a, double[][] b)
static double[][]
deepClone(double[][] matrix)
static double
dot(double[] m1, double[] m2)
Deprecated.Use dotProduct()static double
dotProduct(double[] m1, double[] m2)
static void
expNormalize(double[] scores)
static double
infinityNorm(double[] m)
static boolean
isInfinite(double[] m)
static boolean
isNaN(double[] m)
static boolean
isNaNOrInfinite(double[] m)
static boolean
isNonZero(double[] m)
static boolean
isZero(double[] m)
static double[][]
loadtxt(java.io.File matrixFile)
static void
log(double[] m)
static double
max(double[] elems)
static double
max(double[][] ds)
static int
max(int[] elems)
static int
max(int[][] m)
static double
maxAbsdiff(double[] v1, double[] v2)
Returns the maximum elementwise absolute difference between two vectors.static int
maxIndex(double[] elems)
static int[]
maxIndex(double[][] ds)
static double
mean(double[] m)
static java.lang.Double
mean(java.util.List<java.lang.Double> m)
static double
min(double[] elems)
static int
minIndex(double[] elems)
static double
normalize(double[] m)
static double
oneNorm(double[] m)
static double
oneNormalize(double[] m)
static void
plusEquals(double[][] m1, double[][] m2, double factor)
static void
plusEquals(double[] m, double toadd)
Adds a scalar to every element in an array.static void
plusEquals(double[] m1, double[] m2)
static void
plusEquals(double[] m1, double[] m2, double factor)
static void
print(double[] m)
Prints a double array to standard outputstatic void
print(double[][] matrix)
static void
print(int[] m)
static void
print(int[][] arr)
static void
print(java.io.PrintWriter out, double[] m)
Prints a double array to the given PrintWriter.static void
printInRows(double[] arr)
static double[]
randomVector(int n, java.util.Random r)
static double
rowDotProduct(double[] m, int nc, int ri, Vector v, double factor, int maxCi, FeatureSelection selection)
static double
rowDotProduct(double[] m, int nc, int ri, Vector v, int maxCi, FeatureSelection selection)
static void
rowPlusEquals(double[] m, int nc, int ri, Vector v, double factor)
static void
rowSetAll(double[] m, int nc, int ri, double v, FeatureSelection fselection, boolean ifSelected)
If "ifSelected" is false, it reverses the selection.static void
savetxt(double[][] matrix, java.io.File saveFile)
static void
set(double[] dest, double[] source)
static void
setAll(double[][][] m, double v)
static void
setAll(double[][] m, double v)
static void
setAll(double[] m, double v)
Sets every element of a double array to a given value.static double
stddev(double[] m)
Return the standard deviation using 1/n, not the unbiased 1/(n-1).static double
stderr(double[] m)
static void
substitute(double[] m, double oldValue, double newValue)
static double
sum(double[] m)
static double
sum(double[][] m)
static int
sum(int[] m)
static double
sum(Vector v)
static double
sumSquaredDiff(double[][] a, double[][] b)
Frobenius norm of the element-wise differencestatic void
timesEquals(double[][] m, double factor)
static void
timesEquals(double[] m, double factor)
Multiplies every element in an array by a scalar.static void
timesEquals(double[] m1, double[] m2)
static java.lang.String
toString(java.lang.Object m)
Print a space-separated array of elementsstatic double
twoNorm(double[] m)
static double
twoNormalize(double[] m)
static double
twoNormSquared(double[] m)
static double
variance(double[] m)
Return the variance using 1/n, not the unbiased 1/(n-1).
-
-
-
Method Detail
-
setAll
public static void setAll(double[] m, double v)
Sets every element of a double array to a given value.- Parameters:
m
- The array to modifyv
- The value
-
set
public static void set(double[] dest, double[] source)
-
timesEquals
public static void timesEquals(double[] m, double factor)
Multiplies every element in an array by a scalar.- Parameters:
m
- The arrayfactor
- The scalar
-
timesEquals
public static void timesEquals(double[] m1, double[] m2)
-
plusEquals
public static void plusEquals(double[] m, double toadd)
Adds a scalar to every element in an array.- Parameters:
m
- The arraytoadd
- The scalar
-
plusEquals
public static void plusEquals(double[] m1, double[] m2)
-
plusEquals
public static void plusEquals(double[] m1, double[] m2, double factor)
-
plusEquals
public static void plusEquals(double[][] m1, double[][] m2, double factor)
-
log
public static void log(double[] m)
-
dot
@Deprecated public static double dot(double[] m1, double[] m2)
Deprecated.Use dotProduct()
-
dotProduct
public static double dotProduct(double[] m1, double[] m2)
-
absNorm
public static double absNorm(double[] m)
-
twoNorm
public static double twoNorm(double[] m)
-
twoNormSquared
public static double twoNormSquared(double[] m)
-
oneNorm
public static double oneNorm(double[] m)
-
oneNormalize
public static double oneNormalize(double[] m)
-
normalize
public static double normalize(double[] m)
-
infinityNorm
public static double infinityNorm(double[] m)
-
absNormalize
public static double absNormalize(double[] m)
-
twoNormalize
public static double twoNormalize(double[] m)
-
substitute
public static void substitute(double[] m, double oldValue, double newValue)
-
rowSetAll
public static final void rowSetAll(double[] m, int nc, int ri, double v, FeatureSelection fselection, boolean ifSelected)
If "ifSelected" is false, it reverses the selection. If "fselection" is null, this implies that all features are selected; all values in the row will be changed unless "ifSelected" is false.
-
rowDotProduct
public static double rowDotProduct(double[] m, int nc, int ri, Vector v, int maxCi, FeatureSelection selection)
-
rowDotProduct
public static double rowDotProduct(double[] m, int nc, int ri, Vector v, double factor, int maxCi, FeatureSelection selection)
-
rowPlusEquals
public static final void rowPlusEquals(double[] m, int nc, int ri, Vector v, double factor)
-
deepClone
public static double[][] deepClone(double[][] matrix)
-
aTimesB
public static double[][] aTimesB(double[][] a, double[][] b)
-
aTransposeTimesB
public static double[][] aTransposeTimesB(double[][] a, double[][] b)
-
isNaN
public static boolean isNaN(double[] m)
-
isInfinite
public static boolean isInfinite(double[] m)
-
isNaNOrInfinite
public static boolean isNaNOrInfinite(double[] m)
-
isNonZero
public static boolean isNonZero(double[] m)
-
isZero
public static boolean isZero(double[] m)
-
sum
public static double sum(double[] m)
-
sum
public static double sum(double[][] m)
-
sum
public static int sum(int[] m)
-
sum
public static double sum(Vector v)
-
mean
public static java.lang.Double mean(java.util.List<java.lang.Double> m)
-
mean
public static double mean(double[] m)
-
stddev
public static double stddev(double[] m)
Return the standard deviation using 1/n, not the unbiased 1/(n-1).
-
stderr
public static double stderr(double[] m)
-
variance
public static double variance(double[] m)
Return the variance using 1/n, not the unbiased 1/(n-1).
-
print
public static final void print(double[] m)
Prints a double array to standard output- Parameters:
m
- Array to print.
-
print
public static final void print(java.io.PrintWriter out, double[] m)
Prints a double array to the given PrintWriter.- Parameters:
out
- Writer to print ouput tom
- Array to print.
-
print
public static final void print(double[][] matrix)
-
toString
public static final java.lang.String toString(java.lang.Object m)
Print a space-separated array of elements- Parameters:
m
- An array of any type
-
printInRows
public static final void printInRows(double[] arr)
-
setAll
public static void setAll(double[][][] m, double v)
-
setAll
public static void setAll(double[][] m, double v)
-
print
public static void print(int[][] arr)
-
print
public static void print(int[] m)
-
randomVector
public static double[] randomVector(int n, java.util.Random r)
-
timesEquals
public static void timesEquals(double[][] m, double factor)
-
maxAbsdiff
public static double maxAbsdiff(double[] v1, double[] v2)
Returns the maximum elementwise absolute difference between two vectors. This is the same as infinityNorm (v1 - v2) (if that were legal Java).- Parameters:
v1
- Input vector, as double[]v2
- Input vector, as double[]- Returns:
-
max
public static int max(int[][] m)
-
max
public static int max(int[] elems)
-
max
public static double max(double[] elems)
-
min
public static double min(double[] elems)
-
maxIndex
public static int maxIndex(double[] elems)
-
minIndex
public static int minIndex(double[] elems)
-
sumSquaredDiff
public static double sumSquaredDiff(double[][] a, double[][] b)
Frobenius norm of the element-wise difference
-
append
public static double[] append(double[] original, double newValue)
-
max
public static double max(double[][] ds)
-
maxIndex
public static int[] maxIndex(double[][] ds)
-
expNormalize
public static void expNormalize(double[] scores)
-
loadtxt
public static double[][] loadtxt(java.io.File matrixFile) throws java.lang.Exception
- Throws:
java.lang.Exception
-
savetxt
public static void savetxt(double[][] matrix, java.io.File saveFile) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-