tpp
Class MatrixUtils

java.lang.Object
  extended by tpp.MatrixUtils

public class MatrixUtils
extends java.lang.Object

Matrix Utilities !!TODO make all methods instance rather than static !!TODO change all these methods to just work on Matrix objects rather than double arrays -- and change the rest of the application to use double arrays less.

Author:
Joe Faith

Constructor Summary
MatrixUtils()
           
 
Method Summary
static double[] abs(double[] x)
           
static double[] add(double[] a1, double[] a2)
          add a1 to a2.
static java.lang.String array2String(double[][] array)
           
static Matrix columnarTimes(Matrix mx, double[] scalars)
          Create a new matrix, the result of multiplying each column of the given matrix by the corresponding scalar value in the array.
static double[] columnMeans(double[][] m)
          The means of each column
static Matrix columnMeans(Matrix m)
          The means of each column
static double[] columnStdev(double[][] m)
          The stdev of each column
static double[] columnStdev(Matrix m)
          The stdev of each column
static double dissimilarity(double[][] a, double[][] b)
          The size of the difference between two arrays
static double[][] distances(double[][] a)
           
static double[] getColumn(double[][] m, int col)
           
static double[] getColumn(Matrix m, int col)
           
static double[] getRow(Matrix m, int r)
           
static Matrix insertRow(Matrix m, double[] row)
          Insert a row of values into the bottom of the given matrix.
static double length(double[] a)
          Euclidean length of a row vector
static double[] localMean(double[] x, int neighbours)
          Find the local mean -- ie the mean of the n neighbours on either side.
static double localVolatility(double[] x, int neighbours)
          Find the local volatility -- ie the root sum square distance from the local mean.
static double logistic(double x)
          The logistic function of a double L(x) = 1 / (1+exp(-x)
static double[] logistic(double[] x)
          The logistic function of an array of doubles
static void main(java.lang.String[] args)
           
static double maxAbsValue(Matrix mx)
          The maximum absolute value of components in the matrix.
static double[] maxAbsValueCol(Matrix mx)
          The maximum absolute value of components in each column of the matrix.
static double mean(double[] x)
          Find the mean of an array of doubles.
static double[] minMax(double[] a)
          The min and max of a set of numbers
static double[] normalise(double[] x)
          Normalise by dividing by root mean square
static Matrix numeric2matrix(Instances instances)
          Construct a matrix from (the numeric attributes of ) a set of instances.
static int[] rank(double[] data)
          Sort the array of doubles, returning the indices of the doubles in order of size -- largest first
static double[][] removeRows(double[][] m, int[] rowsToRemove)
           
static double[] rowNorm2(Matrix mx)
          Return an array comprising the Euclidean norm of each row
static void setColumn(Matrix m, int col, double value)
           
static void setColumn(Matrix m, int col, double[] values)
           
static void setRow(Matrix m, int row, double[] values)
           
static double stdev(double[] x)
          Find the stdev of an array of doubles.
static double[][] times(double[][] a, double[][] b)
          matrix multiplication
static double[] times(double[] a, double d)
          times a by d.
static double[] times(double[] a, double[][] b)
          Multiply a row by a matrix
static java.lang.String toString(double[] x)
           
static java.lang.String toString(double[][] a)
           
static java.lang.String toString(int[] x)
           
static double[][] transpose(double[][] a)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixUtils

public MatrixUtils()
Method Detail

numeric2matrix

public static Matrix numeric2matrix(Instances instances)
Construct a matrix from (the numeric attributes of ) a set of instances. Nominal and string attributes are ignored.


distances

public static double[][] distances(double[][] a)

rowNorm2

public static double[] rowNorm2(Matrix mx)
Return an array comprising the Euclidean norm of each row


rank

public static int[] rank(double[] data)
Sort the array of doubles, returning the indices of the doubles in order of size -- largest first


columnarTimes

public static Matrix columnarTimes(Matrix mx,
                                   double[] scalars)
Create a new matrix, the result of multiplying each column of the given matrix by the corresponding scalar value in the array.


array2String

public static java.lang.String array2String(double[][] array)

maxAbsValue

public static double maxAbsValue(Matrix mx)
The maximum absolute value of components in the matrix.


maxAbsValueCol

public static double[] maxAbsValueCol(Matrix mx)
The maximum absolute value of components in each column of the matrix.


stdev

public static double stdev(double[] x)
Find the stdev of an array of doubles.


mean

public static double mean(double[] x)
Find the mean of an array of doubles.


localMean

public static double[] localMean(double[] x,
                                 int neighbours)
Find the local mean -- ie the mean of the n neighbours on either side.


localVolatility

public static double localVolatility(double[] x,
                                     int neighbours)
Find the local volatility -- ie the root sum square distance from the local mean. Local mean is formed from the n neighbours on either side. Boundary cases are ignored


normalise

public static double[] normalise(double[] x)
Normalise by dividing by root mean square


removeRows

public static double[][] removeRows(double[][] m,
                                    int[] rowsToRemove)

getColumn

public static double[] getColumn(Matrix m,
                                 int col)

getColumn

public static double[] getColumn(double[][] m,
                                 int col)

setColumn

public static void setColumn(Matrix m,
                             int col,
                             double[] values)

setColumn

public static void setColumn(Matrix m,
                             int col,
                             double value)

getRow

public static double[] getRow(Matrix m,
                              int r)

setRow

public static void setRow(Matrix m,
                          int row,
                          double[] values)

abs

public static double[] abs(double[] x)

toString

public static java.lang.String toString(double[] x)

toString

public static java.lang.String toString(int[] x)

add

public static double[] add(double[] a1,
                           double[] a2)
add a1 to a2. return the result


times

public static double[] times(double[] a,
                             double d)
times a by d. return teh result


times

public static double[][] times(double[][] a,
                               double[][] b)
matrix multiplication


times

public static double[] times(double[] a,
                             double[][] b)
Multiply a row by a matrix


toString

public static java.lang.String toString(double[][] a)

insertRow

public static Matrix insertRow(Matrix m,
                               double[] row)
Insert a row of values into the bottom of the given matrix. If matrix is null then construct a new one


columnMeans

public static Matrix columnMeans(Matrix m)
The means of each column


columnMeans

public static double[] columnMeans(double[][] m)
The means of each column


columnStdev

public static double[] columnStdev(Matrix m)
The stdev of each column


columnStdev

public static double[] columnStdev(double[][] m)
The stdev of each column


length

public static double length(double[] a)
Euclidean length of a row vector


dissimilarity

public static double dissimilarity(double[][] a,
                                   double[][] b)
The size of the difference between two arrays


main

public static void main(java.lang.String[] args)

transpose

public static double[][] transpose(double[][] a)

minMax

public static double[] minMax(double[] a)
The min and max of a set of numbers


logistic

public static double logistic(double x)
The logistic function of a double L(x) = 1 / (1+exp(-x)


logistic

public static double[] logistic(double[] x)
The logistic function of an array of doubles