cc.mallet.types
Class MatrixOps

java.lang.Object
  extended by 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
MatrixOps()
           
 
Method Summary
static double absNorm(double[] m)
           
static double absNormalize(double[] m)
           
static double[] append(double[] original, double newValue)
           
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 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 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 output
static void print(double[][] arr)
           
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 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
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 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 elements
static double twoNorm(double[] m)
           
static double twoNormalize(double[] m)
           
static double twoNormSquared(double[] m)
           
static double variance(double[] m)
          Return the variance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixOps

public MatrixOps()
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 modify
v - 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 array
factor - 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 array
toadd - 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

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)

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 double mean(double[] m)

stddev

public static double stddev(double[] m)
Return the standard deviation


stderr

public static double stderr(double[] m)

variance

public static double variance(double[] m)
Return the variance


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 to
m - Array to print.

print

public static final void print(double[][] arr)

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)

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)