edu.umbc.cs.maple.utils
Class ColtUtils

java.lang.Object
  extended by edu.umbc.cs.maple.utils.ColtUtils

public class ColtUtils
extends java.lang.Object

Various utility functions for the COLT matrix library.

Copyright (c) 2008 Eric Eaton

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Version:
0.1
Author:
Eric Eaton (EricEaton@umbc.edu)
University of Maryland Baltimore County

Nested Class Summary
static class ColtUtils.MaxMin
           
 
Constructor Summary
ColtUtils()
           
 
Method Summary
static cern.colt.matrix.DoubleMatrix1D colsum(cern.colt.matrix.DoubleMatrix2D m)
          Computes the sum of each column of a matrix.
static double colsum(cern.colt.matrix.DoubleMatrix2D m, int col)
          Gets the sum of the specified column of the matrix.
static cern.colt.matrix.DoubleMatrix2D columnAppend(cern.colt.matrix.DoubleMatrix2D m, cern.colt.matrix.DoubleMatrix2D n)
          Appends additional columns to the first matrix.
static cern.colt.matrix.DoubleMatrix2D deleteCol(cern.colt.matrix.DoubleMatrix2D m, int col)
          Deletes a column from a matrix.
static cern.colt.matrix.DoubleMatrix2D deleteRow(cern.colt.matrix.DoubleMatrix2D m, int row)
          Deletes a row from a matrix.
static cern.colt.matrix.DoubleMatrix2D diagonalPow(cern.colt.matrix.DoubleMatrix2D m, double exponent)
           
static double dotproduct(cern.colt.matrix.DoubleMatrix1D m1, cern.colt.matrix.DoubleMatrix1D m2)
          Computes the dot product of two vectors.
static double dotproduct(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
          Computes the dot product of two vectors.
static cern.colt.matrix.DoubleMatrix2D elementMult(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
           
static cern.colt.matrix.DoubleMatrix2D elementMultEquals(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
           
protected static double gcv(cern.colt.matrix.DoubleMatrix2D A, cern.colt.matrix.DoubleMatrix2D b)
           
static cern.colt.matrix.DoubleMatrix1D getcol(cern.colt.matrix.DoubleMatrix2D m, int col)
          Gets the specified column of a matrix.
static cern.colt.matrix.DoubleMatrix2D getcolumns(cern.colt.matrix.DoubleMatrix2D m, int[] columns)
          Gets the specified columns of a matrix.
static double getMax(cern.colt.matrix.DoubleMatrix2D m)
           
static double getMin(cern.colt.matrix.DoubleMatrix2D m)
           
static double[] getNonZeros(cern.colt.matrix.DoubleMatrix1D m)
           
static double[] getNonZeros(cern.colt.matrix.DoubleMatrix2D m)
           
static cern.colt.matrix.DoubleMatrix1D getrow(cern.colt.matrix.DoubleMatrix2D m, int row)
          Gets the specified row of a matrix.
static cern.colt.matrix.DoubleMatrix2D getrows(cern.colt.matrix.DoubleMatrix2D m, int[] rows)
          Gets the specified rows of a matrix.
static cern.colt.matrix.DoubleMatrix2D identity(int m)
           
static cern.colt.matrix.DoubleMatrix2D inverse(cern.colt.matrix.DoubleMatrix2D m)
           
static boolean isColumnVector(cern.colt.matrix.DoubleMatrix2D m)
          Determines if a given matrix is a column vector, that is, it has only one column.
static boolean isRowVector(cern.colt.matrix.DoubleMatrix2D m)
          Determines if a given matrix is a row vector, that is, it has only one row.
static boolean isSymmetric(cern.colt.matrix.DoubleMatrix2D m)
          Determines whether a matrix is symmetric.
static cern.colt.matrix.DoubleMatrix2D loadDoubleMatrix2D(java.io.File file)
           
static void main(java.lang.String[] args)
           
static cern.colt.matrix.DoubleMatrix2D makeColumnVector(cern.colt.matrix.DoubleMatrix2D m)
          Transforms the given matrix into a column vector, that is, a matrix with one column.
static void makeMatrixSymmetric(cern.colt.matrix.DoubleMatrix2D m, ColtUtils.MaxMin maxmin)
           
static cern.colt.matrix.DoubleMatrix2D makeRowVector(cern.colt.matrix.DoubleMatrix2D m)
          Transforms the given matrix into a row vector, that is, a matrix with one row.
static cern.colt.matrix.DoubleMatrix1D minus(cern.colt.matrix.DoubleMatrix1D m1, cern.colt.matrix.DoubleMatrix1D m2)
           
static cern.colt.matrix.DoubleMatrix2D minus(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
           
static cern.colt.matrix.DoubleMatrix1D minusEquals(cern.colt.matrix.DoubleMatrix1D m1, cern.colt.matrix.DoubleMatrix1D m2)
           
static cern.colt.matrix.DoubleMatrix2D minusEquals(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
           
static cern.colt.matrix.DoubleMatrix2D mult(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
           
static cern.colt.matrix.DoubleMatrix2D normalize(cern.colt.matrix.DoubleMatrix2D m)
          Normalizes a matrix to make the elements sum to 1.
static double normF(cern.colt.matrix.DoubleMatrix2D m)
           
static cern.colt.matrix.DoubleMatrix2D ones(int numRows, int numCols)
          Make a matrix of ones.
static cern.colt.matrix.DoubleMatrix1D plus(cern.colt.matrix.DoubleMatrix1D m1, cern.colt.matrix.DoubleMatrix1D m2)
           
static cern.colt.matrix.DoubleMatrix2D plus(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
           
static cern.colt.matrix.DoubleMatrix1D plusEquals(cern.colt.matrix.DoubleMatrix1D m1, cern.colt.matrix.DoubleMatrix1D m2)
           
static cern.colt.matrix.DoubleMatrix2D plusEquals(cern.colt.matrix.DoubleMatrix2D m1, cern.colt.matrix.DoubleMatrix2D m2)
           
static void printSparseMatrix(java.io.PrintStream outStream, cern.colt.matrix.DoubleMatrix2D m)
           
static cern.colt.matrix.DoubleMatrix2D regLeastSquares(cern.colt.matrix.DoubleMatrix2D A, cern.colt.matrix.DoubleMatrix2D b)
           
static cern.colt.matrix.DoubleMatrix2D regLeastSquares(cern.colt.matrix.DoubleMatrix2D A, cern.colt.matrix.DoubleMatrix2D b, double lambda)
           
static cern.colt.matrix.DoubleMatrix2D regLeastSquares(cern.colt.matrix.DoubleMatrix2D A, cern.colt.matrix.DoubleMatrix2D b, cern.colt.matrix.DoubleMatrix2D regop)
           
static double rmse(cern.colt.matrix.DoubleMatrix2D a, cern.colt.matrix.DoubleMatrix2D b)
           
static cern.colt.matrix.DoubleMatrix2D rowAppend(cern.colt.matrix.DoubleMatrix2D m, cern.colt.matrix.DoubleMatrix2D n)
          Appends additional rows to the first matrix.
static cern.colt.matrix.DoubleMatrix1D rowsum(cern.colt.matrix.DoubleMatrix2D m)
          Computes the sum of each row of a matrix.
static double rowsum(cern.colt.matrix.DoubleMatrix2D m, int row)
          Gets the sum of the specified row of the matrix.
static cern.colt.matrix.DoubleMatrix1D scale(cern.colt.matrix.DoubleMatrix1D m, double d)
           
static cern.colt.matrix.DoubleMatrix2D scale(cern.colt.matrix.DoubleMatrix2D m, double d)
           
static void setcol(cern.colt.matrix.DoubleMatrix2D m, int col, double[] values)
          Sets the specified column of a matrix.
static void setcol(cern.colt.matrix.DoubleMatrix2D m, int col, cern.colt.matrix.DoubleMatrix1D values)
          Sets the specified column of a matrix.
static void setrow(cern.colt.matrix.DoubleMatrix2D m, int row, cern.colt.matrix.DoubleMatrix1D values)
          Sets the specified row of a matrix.
static double sum(cern.colt.matrix.DoubleMatrix1D m)
           
static double sum(cern.colt.matrix.DoubleMatrix2D m)
           
static cern.colt.matrix.DoubleMatrix1D to1D(cern.colt.matrix.DoubleMatrix2D m)
           
static cern.colt.matrix.DoubleMatrix2D to2D(cern.colt.matrix.DoubleMatrix1D m)
           
static cern.colt.matrix.DoubleMatrix2D transpose(cern.colt.matrix.DoubleMatrix2D m)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColtUtils

public ColtUtils()
Method Detail

getcol

public static cern.colt.matrix.DoubleMatrix1D getcol(cern.colt.matrix.DoubleMatrix2D m,
                                                     int col)
Gets the specified column of a matrix.

Parameters:
m - the matrix.
col - the column to get.
Returns:
the specified column of m.

getcolumns

public static cern.colt.matrix.DoubleMatrix2D getcolumns(cern.colt.matrix.DoubleMatrix2D m,
                                                         int[] columns)
Gets the specified columns of a matrix.

Parameters:
m - the matrix
columns - the columns to get
Returns:
the matrix of the specified columns of m.

getrow

public static cern.colt.matrix.DoubleMatrix1D getrow(cern.colt.matrix.DoubleMatrix2D m,
                                                     int row)
Gets the specified row of a matrix.

Parameters:
m - the matrix.
row - the row to get.
Returns:
the specified row of m.

getrows

public static cern.colt.matrix.DoubleMatrix2D getrows(cern.colt.matrix.DoubleMatrix2D m,
                                                      int[] rows)
Gets the specified rows of a matrix.

Parameters:
m - the matrix
rows - the rows to get
Returns:
the matrix of the specified rows of m.

setrow

public static void setrow(cern.colt.matrix.DoubleMatrix2D m,
                          int row,
                          cern.colt.matrix.DoubleMatrix1D values)
Sets the specified row of a matrix. Modifies the passed matrix.

Parameters:
m - the matrix.
row - the row to modify.
values - the new values of the row.

setcol

public static void setcol(cern.colt.matrix.DoubleMatrix2D m,
                          int col,
                          cern.colt.matrix.DoubleMatrix1D values)
Sets the specified column of a matrix. Modifies the passed matrix.

Parameters:
m - the matrix.
col - the column to modify.
values - the new values of the column.

setcol

public static void setcol(cern.colt.matrix.DoubleMatrix2D m,
                          int col,
                          double[] values)
Sets the specified column of a matrix. Modifies the passed matrix.

Parameters:
m - the matrix.
col - the column to modify.
values - the new values of the column.

rowAppend

public static cern.colt.matrix.DoubleMatrix2D rowAppend(cern.colt.matrix.DoubleMatrix2D m,
                                                        cern.colt.matrix.DoubleMatrix2D n)
Appends additional rows to the first matrix.

Parameters:
m - the first matrix.
n - the matrix to append containing additional rows.
Returns:
a matrix with all the rows of m then all the rows of n.

columnAppend

public static cern.colt.matrix.DoubleMatrix2D columnAppend(cern.colt.matrix.DoubleMatrix2D m,
                                                           cern.colt.matrix.DoubleMatrix2D n)
Appends additional columns to the first matrix.

Parameters:
m - the first matrix.
n - the matrix to append containing additional columns.
Returns:
a matrix with all the columns of m then all the columns of n.

deleteRow

public static cern.colt.matrix.DoubleMatrix2D deleteRow(cern.colt.matrix.DoubleMatrix2D m,
                                                        int row)
Deletes a row from a matrix. Does not change the passed matrix.

Parameters:
m - the matrix.
row - the row to delete.
Returns:
m with the specified row deleted.

deleteCol

public static cern.colt.matrix.DoubleMatrix2D deleteCol(cern.colt.matrix.DoubleMatrix2D m,
                                                        int col)
Deletes a column from a matrix. Does not change the passed matrix.

Parameters:
m - the matrix.
col - the column to delete.
Returns:
m with the specified column deleted.

rowsum

public static double rowsum(cern.colt.matrix.DoubleMatrix2D m,
                            int row)
Gets the sum of the specified row of the matrix.

Parameters:
m - the matrix.
row - the row.
Returns:
the sum of m[row,*]

colsum

public static double colsum(cern.colt.matrix.DoubleMatrix2D m,
                            int col)
Gets the sum of the specified column of the matrix.

Parameters:
m - the matrix.
col - the column.
Returns:
the sum of m[*,col]

rowsum

public static cern.colt.matrix.DoubleMatrix1D rowsum(cern.colt.matrix.DoubleMatrix2D m)
Computes the sum of each row of a matrix.

Parameters:
m - the matrix.
Returns:
a column vector of the sum of each row of m.

colsum

public static cern.colt.matrix.DoubleMatrix1D colsum(cern.colt.matrix.DoubleMatrix2D m)
Computes the sum of each column of a matrix.

Parameters:
m - the matrix.
Returns:
a row vector of the sum of each column of m.

isRowVector

public static boolean isRowVector(cern.colt.matrix.DoubleMatrix2D m)
Determines if a given matrix is a row vector, that is, it has only one row.

Parameters:
m - the matrix.
Returns:
whether the given matrix is a row vector (whether it has only one row).

isColumnVector

public static boolean isColumnVector(cern.colt.matrix.DoubleMatrix2D m)
Determines if a given matrix is a column vector, that is, it has only one column.

Parameters:
m - the matrix.
Returns:
whether the given matrix is a column vector (whether it has only one column).

makeColumnVector

public static cern.colt.matrix.DoubleMatrix2D makeColumnVector(cern.colt.matrix.DoubleMatrix2D m)
Transforms the given matrix into a column vector, that is, a matrix with one column. The matrix must be a vector (row or column) to begin with.

Parameters:
m -
Returns:
m.transpose() if m is a row vector, m if m is a column vector.
Throws:
java.lang.IllegalArgumentException - if m is not a row vector or a column vector.

makeRowVector

public static cern.colt.matrix.DoubleMatrix2D makeRowVector(cern.colt.matrix.DoubleMatrix2D m)
Transforms the given matrix into a row vector, that is, a matrix with one row. The matrix must be a vector (row or column) to begin with.

Parameters:
m -
Returns:
m.transpose() if m is a column vector, m if m is a row vector.
Throws:
java.lang.IllegalArgumentException - if m is not a row vector or a column vector.

dotproduct

public static double dotproduct(cern.colt.matrix.DoubleMatrix2D m1,
                                cern.colt.matrix.DoubleMatrix2D m2)
Computes the dot product of two vectors. Both must be either row or column vectors.

Parameters:
m1 -
m2 -
Returns:
the dot product of the two vectors.

dotproduct

public static double dotproduct(cern.colt.matrix.DoubleMatrix1D m1,
                                cern.colt.matrix.DoubleMatrix1D m2)
Computes the dot product of two vectors. Both must be either row or column vectors.

Parameters:
m1 -
m2 -
Returns:
the dot product of the two vectors.

isSymmetric

public static boolean isSymmetric(cern.colt.matrix.DoubleMatrix2D m)
Determines whether a matrix is symmetric.

Parameters:
m - the matrix.
Returns:
true if a is symmetric, false otherwise

makeMatrixSymmetric

public static void makeMatrixSymmetric(cern.colt.matrix.DoubleMatrix2D m,
                                       ColtUtils.MaxMin maxmin)

normalize

public static cern.colt.matrix.DoubleMatrix2D normalize(cern.colt.matrix.DoubleMatrix2D m)
Normalizes a matrix to make the elements sum to 1.

Parameters:
m - the matrix
Returns:
the normalized form of m with all elements summing to 1.

getMax

public static double getMax(cern.colt.matrix.DoubleMatrix2D m)

getMin

public static double getMin(cern.colt.matrix.DoubleMatrix2D m)

ones

public static cern.colt.matrix.DoubleMatrix2D ones(int numRows,
                                                   int numCols)
Make a matrix of ones.

Parameters:
numRows - the number of rows.
numCols - the number of columns.
Returns:
the numRows x numCols matrix of ones.

regLeastSquares

public static cern.colt.matrix.DoubleMatrix2D regLeastSquares(cern.colt.matrix.DoubleMatrix2D A,
                                                              cern.colt.matrix.DoubleMatrix2D b)

scale

public static cern.colt.matrix.DoubleMatrix2D scale(cern.colt.matrix.DoubleMatrix2D m,
                                                    double d)

scale

public static cern.colt.matrix.DoubleMatrix1D scale(cern.colt.matrix.DoubleMatrix1D m,
                                                    double d)

identity

public static cern.colt.matrix.DoubleMatrix2D identity(int m)

plus

public static cern.colt.matrix.DoubleMatrix2D plus(cern.colt.matrix.DoubleMatrix2D m1,
                                                   cern.colt.matrix.DoubleMatrix2D m2)

plusEquals

public static cern.colt.matrix.DoubleMatrix2D plusEquals(cern.colt.matrix.DoubleMatrix2D m1,
                                                         cern.colt.matrix.DoubleMatrix2D m2)

plus

public static cern.colt.matrix.DoubleMatrix1D plus(cern.colt.matrix.DoubleMatrix1D m1,
                                                   cern.colt.matrix.DoubleMatrix1D m2)

plusEquals

public static cern.colt.matrix.DoubleMatrix1D plusEquals(cern.colt.matrix.DoubleMatrix1D m1,
                                                         cern.colt.matrix.DoubleMatrix1D m2)

minus

public static cern.colt.matrix.DoubleMatrix2D minus(cern.colt.matrix.DoubleMatrix2D m1,
                                                    cern.colt.matrix.DoubleMatrix2D m2)

minusEquals

public static cern.colt.matrix.DoubleMatrix2D minusEquals(cern.colt.matrix.DoubleMatrix2D m1,
                                                          cern.colt.matrix.DoubleMatrix2D m2)

minus

public static cern.colt.matrix.DoubleMatrix1D minus(cern.colt.matrix.DoubleMatrix1D m1,
                                                    cern.colt.matrix.DoubleMatrix1D m2)

minusEquals

public static cern.colt.matrix.DoubleMatrix1D minusEquals(cern.colt.matrix.DoubleMatrix1D m1,
                                                          cern.colt.matrix.DoubleMatrix1D m2)

mult

public static cern.colt.matrix.DoubleMatrix2D mult(cern.colt.matrix.DoubleMatrix2D m1,
                                                   cern.colt.matrix.DoubleMatrix2D m2)

transpose

public static cern.colt.matrix.DoubleMatrix2D transpose(cern.colt.matrix.DoubleMatrix2D m)

inverse

public static cern.colt.matrix.DoubleMatrix2D inverse(cern.colt.matrix.DoubleMatrix2D m)

normF

public static double normF(cern.colt.matrix.DoubleMatrix2D m)

elementMultEquals

public static cern.colt.matrix.DoubleMatrix2D elementMultEquals(cern.colt.matrix.DoubleMatrix2D m1,
                                                                cern.colt.matrix.DoubleMatrix2D m2)

elementMult

public static cern.colt.matrix.DoubleMatrix2D elementMult(cern.colt.matrix.DoubleMatrix2D m1,
                                                          cern.colt.matrix.DoubleMatrix2D m2)

diagonalPow

public static cern.colt.matrix.DoubleMatrix2D diagonalPow(cern.colt.matrix.DoubleMatrix2D m,
                                                          double exponent)

to1D

public static cern.colt.matrix.DoubleMatrix1D to1D(cern.colt.matrix.DoubleMatrix2D m)

to2D

public static cern.colt.matrix.DoubleMatrix2D to2D(cern.colt.matrix.DoubleMatrix1D m)

regLeastSquares

public static cern.colt.matrix.DoubleMatrix2D regLeastSquares(cern.colt.matrix.DoubleMatrix2D A,
                                                              cern.colt.matrix.DoubleMatrix2D b,
                                                              double lambda)

regLeastSquares

public static cern.colt.matrix.DoubleMatrix2D regLeastSquares(cern.colt.matrix.DoubleMatrix2D A,
                                                              cern.colt.matrix.DoubleMatrix2D b,
                                                              cern.colt.matrix.DoubleMatrix2D regop)

gcv

protected static double gcv(cern.colt.matrix.DoubleMatrix2D A,
                            cern.colt.matrix.DoubleMatrix2D b)

rmse

public static double rmse(cern.colt.matrix.DoubleMatrix2D a,
                          cern.colt.matrix.DoubleMatrix2D b)

getNonZeros

public static double[] getNonZeros(cern.colt.matrix.DoubleMatrix2D m)

getNonZeros

public static double[] getNonZeros(cern.colt.matrix.DoubleMatrix1D m)

sum

public static double sum(cern.colt.matrix.DoubleMatrix2D m)

sum

public static double sum(cern.colt.matrix.DoubleMatrix1D m)

loadDoubleMatrix2D

public static cern.colt.matrix.DoubleMatrix2D loadDoubleMatrix2D(java.io.File file)

printSparseMatrix

public static void printSparseMatrix(java.io.PrintStream outStream,
                                     cern.colt.matrix.DoubleMatrix2D m)

main

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