netflix.algorithms.modelbased.svd
Class MatrixHelper

java.lang.Object
  extended by netflix.algorithms.modelbased.svd.MatrixHelper

public class MatrixHelper
extends java.lang.Object

Provides utility functions for use with the Colt matrix package.


Constructor Summary
MatrixHelper()
           
 
Method Summary
static cern.colt.matrix.DoubleMatrix2D addMatrices(cern.colt.matrix.DoubleMatrix2D A, cern.colt.matrix.DoubleMatrix2D B)
          Adds two matrices.
static cern.colt.matrix.DoubleMatrix1D addVectors(cern.colt.matrix.DoubleMatrix1D a, cern.colt.matrix.DoubleMatrix1D b)
          Adds two vectors.
static cern.colt.matrix.DoubleMatrix2D appendColToMatrix(cern.colt.matrix.DoubleMatrix2D A)
          Appends an additional column of zeros to the specified matrix.
static cern.colt.matrix.DoubleMatrix2D appendToMatrix(cern.colt.matrix.DoubleMatrix2D A, cern.colt.matrix.DoubleMatrix1D B)
          Appends a new column to the matrix A.
static cern.colt.matrix.DoubleMatrix1D appendToVector(cern.colt.matrix.DoubleMatrix1D a, double b)
          Appends the scalar b to the end of vector a.
static cern.colt.matrix.DoubleMatrix1D divideVector(cern.colt.matrix.DoubleMatrix1D a, double b)
          Divides a vector by a scalar.
static cern.colt.matrix.DoubleMatrix2D growMatrix(cern.colt.matrix.DoubleMatrix2D A)
          Appends an additional row and column of zeros to the specified matrix.
static void printMatrix(cern.colt.matrix.DoubleMatrix1D vector)
          Prints a one dimensional matrix (i.e.
static void printMatrix(cern.colt.matrix.DoubleMatrix2D matrix)
          Prints a two dimensional matrix.
static cern.colt.matrix.DoubleMatrix1D subVectors(cern.colt.matrix.DoubleMatrix1D a, cern.colt.matrix.DoubleMatrix1D b)
          Subtracts two vectors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixHelper

public MatrixHelper()
Method Detail

printMatrix

public static void printMatrix(cern.colt.matrix.DoubleMatrix2D matrix)
Prints a two dimensional matrix.

Parameters:
matrix - The DoubbleMatrix2D object to print

printMatrix

public static void printMatrix(cern.colt.matrix.DoubleMatrix1D vector)
Prints a one dimensional matrix (i.e. a vector).

Parameters:
vector - The DoubleMatrix1D to print

addVectors

public static cern.colt.matrix.DoubleMatrix1D addVectors(cern.colt.matrix.DoubleMatrix1D a,
                                                         cern.colt.matrix.DoubleMatrix1D b)
                                                  throws java.lang.IllegalArgumentException
Adds two vectors.

Parameters:
a - First vector to add
b - Second vector to add
Returns:
a + b
Throws:
java.lang.IllegalArgumentException - if a.size() != b.size()

subVectors

public static cern.colt.matrix.DoubleMatrix1D subVectors(cern.colt.matrix.DoubleMatrix1D a,
                                                         cern.colt.matrix.DoubleMatrix1D b)
                                                  throws java.lang.IllegalArgumentException
Subtracts two vectors.

Parameters:
a -
b -
Returns:
a - b.
Throws:
java.lang.IllegalArgumentException - if a.size() != b.size()

divideVector

public static cern.colt.matrix.DoubleMatrix1D divideVector(cern.colt.matrix.DoubleMatrix1D a,
                                                           double b)
Divides a vector by a scalar.

Parameters:
a - Vector
b - Scalar to divide a by.
Returns:
a / b

appendToVector

public static cern.colt.matrix.DoubleMatrix1D appendToVector(cern.colt.matrix.DoubleMatrix1D a,
                                                             double b)
Appends the scalar b to the end of vector a.

Parameters:
a - The vector to append to.
b - The scalar to append.
Returns:
A vector of size a.size() + 1 containing b as its last entry.

appendToMatrix

public static cern.colt.matrix.DoubleMatrix2D appendToMatrix(cern.colt.matrix.DoubleMatrix2D A,
                                                             cern.colt.matrix.DoubleMatrix1D B)
                                                      throws java.lang.IllegalArgumentException
Appends a new column to the matrix A.

Parameters:
A - The matrix.
B - The vector to append to A.
Returns:
A matrix
Throws:
java.lang.IllegalArgumentException - if A.rows() != B.size()

addMatrices

public static cern.colt.matrix.DoubleMatrix2D addMatrices(cern.colt.matrix.DoubleMatrix2D A,
                                                          cern.colt.matrix.DoubleMatrix2D B)
                                                   throws java.lang.IllegalArgumentException
Adds two matrices.

Parameters:
A - First matrix to add.
B - Second matrix to add.
Returns:
A + B
Throws:
java.lang.IllegalArgumentException - if A and B are not the same size.

growMatrix

public static cern.colt.matrix.DoubleMatrix2D growMatrix(cern.colt.matrix.DoubleMatrix2D A)
Appends an additional row and column of zeros to the specified matrix.

Parameters:
A - The matrix to grow.
Returns:
A matrix with A.rows() + 1 rows and A.columns() + 1 columns.

appendColToMatrix

public static cern.colt.matrix.DoubleMatrix2D appendColToMatrix(cern.colt.matrix.DoubleMatrix2D A)
Appends an additional column of zeros to the specified matrix.

Parameters:
A - The matrix to grow.
Returns:
A matrix with A.rows() rows and A.columns() + 1 columns.