org.mymedialite.datatype
Class MatrixExtensions

java.lang.Object
  extended by org.mymedialite.datatype.MatrixExtensions

public class MatrixExtensions
extends java.lang.Object

Utilities to work with matrices * @version 2.03


Constructor Summary
MatrixExtensions()
           
 
Method Summary
static double columnAverage(Matrix<java.lang.Double> matrix, int col)
          Compute the average value of the entries in a column of a matrix.
static void columnInitNormal(Matrix<java.lang.Double> matrix, int column, double mean, double stdev)
          Initializes one column of a double matrix with normal distributed (Gaussian) noise.
static double frobeniusNorm(Matrix<java.lang.Double> matrix)
          Compute the Frobenius norm (square root of the sum of squared entries) of a matrix.
static void inc(Matrix<java.lang.Double> matrix, double d)
          Increment all entries of a matrix with a scalar.
static void inc(Matrix<java.lang.Double> matrix, int i, int j, double v)
          Increments the specified matrix element by a double value.
static void inc(Matrix<java.lang.Double> matrix1, Matrix<java.lang.Double> matrix2)
          Increment the elements in one matrix by the ones in another
static void inc(Matrix<java.lang.Integer> matrix, int i, int j)
          Increments the specified matrix element by 1.
static void initNormal(Matrix<java.lang.Double> matrix, double mean, double stdev)
          Initializes a double matrix with normal distributed (Gaussian) noise.
static double maxDouble(Matrix<java.lang.Double> m)
          Return the maximum value contained in a matrix.
static float maxFloat(Matrix<java.lang.Float> m)
          return the maximum value contained in a matrix.
static int maxInteger(Matrix<java.lang.Integer> m)
          Return the maximum value contained in a matrix.
static void multiply(Matrix<java.lang.Double> matrix, double d)
          Multiply all entries of a matrix with a scalar.
static double rowAverage(Matrix<java.lang.Double> matrix, int row)
          Compute the average value of the entries in a row of a matrix.
static java.util.List<java.lang.Double> rowDifference(Matrix<java.lang.Double> matrix1, int i, Matrix<java.lang.Double> matrix2, int j)
          Compute the difference vector between two rows of two matrices.
static void rowInitNormal(Matrix<java.lang.Double> matrix, int row, double mean, double stdev)
          Initializes one row of a double matrix with normal distributed (Gaussian) noise.
static double rowScalarProduct(Matrix<java.lang.Double> matrix, int i, java.util.List<java.lang.Double> vector)
          Compute the scalar product between a vector and a row of the matrix.
static java.lang.Double rowScalarProduct(Matrix<java.lang.Double> matrix1, int i, Matrix<java.lang.Double> matrix2, int j)
          Compute the scalar product between two rows of two matrices.
static double rowScalarProductWithRowDifference(Matrix<java.lang.Double> matrix1, int i, Matrix<java.lang.Double> matrix2, int j, Matrix<java.lang.Double> matrix3, int k)
          Compute the scalar product of a matrix row with the difference vector of two other matrix rows.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixExtensions

public MatrixExtensions()
Method Detail

rowInitNormal

public static void rowInitNormal(Matrix<java.lang.Double> matrix,
                                 int row,
                                 double mean,
                                 double stdev)
Initializes one row of a double matrix with normal distributed (Gaussian) noise.

Parameters:
matrix - the matrix to initialize
mean - the mean of the normal distribution drawn from
stdev - the standard deviation of the normal distribution
row - the row to be initialized

columnInitNormal

public static void columnInitNormal(Matrix<java.lang.Double> matrix,
                                    int column,
                                    double mean,
                                    double stdev)
Initializes one column of a double matrix with normal distributed (Gaussian) noise.

Parameters:
matrix - the matrix to initialize
mean - the mean of the normal distribution drawn from
stdev - the standard deviation of the normal distribution
column - the column to be initialized

initNormal

public static void initNormal(Matrix<java.lang.Double> matrix,
                              double mean,
                              double stdev)
Initializes a double matrix with normal distributed (Gaussian) noise.

Parameters:
matrix - the matrix to initialize
mean - the mean of the normal distribution drawn from
stdev - the standard deviation of the normal distribution

inc

public static void inc(Matrix<java.lang.Double> matrix,
                       int i,
                       int j,
                       double v)
Increments the specified matrix element by a double value.

Parameters:
matrix - The matrix
i - the row
j - the column
v - the value

inc

public static void inc(Matrix<java.lang.Double> matrix1,
                       Matrix<java.lang.Double> matrix2)
Increment the elements in one matrix by the ones in another

Parameters:
matrix1 - the matrix to be incremented
matrix2 - the other matrix

inc

public static void inc(Matrix<java.lang.Integer> matrix,
                       int i,
                       int j)
Increments the specified matrix element by 1.

Parameters:
matrix - the matrix
i - the row
j - the column

inc

public static void inc(Matrix<java.lang.Double> matrix,
                       double d)
Increment all entries of a matrix with a scalar.

Parameters:
matrix - the matrix
d - the number to increment with

columnAverage

public static double columnAverage(Matrix<java.lang.Double> matrix,
                                   int col)
Compute the average value of the entries in a column of a matrix.

Parameters:
matrix - the matrix
col - the column ID
Returns:
the average

rowAverage

public static double rowAverage(Matrix<java.lang.Double> matrix,
                                int row)
Compute the average value of the entries in a row of a matrix.

Parameters:
matrix - the matrix
row - the row ID
Returns:
the average

multiply

public static void multiply(Matrix<java.lang.Double> matrix,
                            double d)
Multiply all entries of a matrix with a scalar.

Parameters:
matrix - the matrix
d - the number to multiply with

frobeniusNorm

public static double frobeniusNorm(Matrix<java.lang.Double> matrix)
Compute the Frobenius norm (square root of the sum of squared entries) of a matrix. See http://en.wikipedia.org/wiki/Matrix_norm

Parameters:
matrix - the matrix
Returns:
the Frobenius norm of the matrix

rowScalarProduct

public static double rowScalarProduct(Matrix<java.lang.Double> matrix,
                                      int i,
                                      java.util.List<java.lang.Double> vector)
Compute the scalar product between a vector and a row of the matrix.

Parameters:
matrix - the matrix
i - the row ID
vector - the numeric vector
Returns:
the scalar product of row i and the vector

rowScalarProduct

public static java.lang.Double rowScalarProduct(Matrix<java.lang.Double> matrix1,
                                                int i,
                                                Matrix<java.lang.Double> matrix2,
                                                int j)
Compute the scalar product between two rows of two matrices.

Parameters:
matrix1 - the first matrix
i - the first row ID
matrix2 - the second matrix
j - the second row ID
Returns:
the scalar product of row i of matrix1 and row j of matrix2

rowDifference

public static java.util.List<java.lang.Double> rowDifference(Matrix<java.lang.Double> matrix1,
                                                             int i,
                                                             Matrix<java.lang.Double> matrix2,
                                                             int j)
Compute the difference vector between two rows of two matrices.

Parameters:
matrix1 - the first matrix
i - the first row ID
matrix2 - the second matrix
j - the second row ID
Returns:
the difference vector of row i of matrix1 and row j of matrix2

rowScalarProductWithRowDifference

public static double rowScalarProductWithRowDifference(Matrix<java.lang.Double> matrix1,
                                                       int i,
                                                       Matrix<java.lang.Double> matrix2,
                                                       int j,
                                                       Matrix<java.lang.Double> matrix3,
                                                       int k)
Compute the scalar product of a matrix row with the difference vector of two other matrix rows.

Parameters:
matrix1 - the first matrix
i - the first row ID
matrix2 - the second matrix
j - the second row ID
matrix3 - the third matrix
k - the third row ID
Returns:
see summary

maxInteger

public static int maxInteger(Matrix<java.lang.Integer> m)
Return the maximum value contained in a matrix.

Parameters:
m - the matrix

maxDouble

public static double maxDouble(Matrix<java.lang.Double> m)
Return the maximum value contained in a matrix.

Parameters:
m - the matrix

maxFloat

public static float maxFloat(Matrix<java.lang.Float> m)
return the maximum value contained in a matrix.

Parameters:
m - the matrix