mpv2
Class SparseVectorMatrix

java.lang.Object
  extended by mpv2.AllMatrices
      extended by mpv2.SparseVectorMatrix
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class SparseVectorMatrix
extends AllMatrices
implements java.lang.Cloneable, java.io.Serializable

This class is a matrix implementation of the AllMatrices superclass, where each column is a SparseVector.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class mpv2.AllMatrices
K, N
 
Constructor Summary
SparseVectorMatrix(AllMatrices B)
          Construct a new matrix from another matrix (of any kind)
SparseVectorMatrix(double[][] A)
          Construct a matrix from a 2-D array, all values are copied.
SparseVectorMatrix(double[] vals, int m)
          Construct a matrix from a one-dimensional packed array
SparseVectorMatrix(int iN, int iK)
          Construct a N×K matrix with only zero values.
 
Method Summary
 void addColumn(int k, double factor, double[] x)
          Add a column of the matrix multiplied by a factor to a given vector.
 double get(int n, int k)
          Return an entry of the matrix.
 double[] getColumn(int k)
          Get a column in the matrix as an array
 SparseVector getSparseColumn(int k)
          Get a copy of a column in the matrix as a SparseVector
 double innerProduct(int k1, int k2)
          Returns the inner product of two matrix column vectors.
 void set(int n, int k, double val)
          Set an entry (a value) in the matrix.
 void setAll(double[] vals)
          Set all entries of to matrix to the supplied new values If argument is wrong length an IllegalArgumentException is thrown.
 void setColumn(int k, double[] c)
          Replace a column in the matrix with the given column vector.
 void setColumn(int k, SparseVector c)
          Replace a column in the matrix with a copy of the given column.
 void times(double[] y, double[] x)
          Multiplies the matrix by an array.
 void transposeTimes(double[] x, double[] y)
          Multiplies the transposed matrix by an array.
 
Methods inherited from class mpv2.AllMatrices
chol, columnNorm0, columnNorm1, columnNorm2, columnNormInf, cond, det, eig, eqConstant, eqCopy, eqCopy, eqCopy, eqCopy, eqCopy, eqDifference, eqEProduct, eqEQuotient, eqIdentity, eqInverse, eqIProduct, eqNegate, eqOnes, eqPermuteColumns, eqPermuteRows, eqProduct, eqProduct, eqRandom, eqScaleColumns, eqScaleRows, eqSum, eqTProduct, eqTranspose, eqZeros, getAll, getAll, getColumn, getColumnDimension, getK, getN, getRow, getRow, getRowDimension, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, getValue, lu, lup, norm1, norm2, normF, normInf, pluseqOuterProduct, print, print, print, print, qr, rank, setRow, setValue, sumAll, svd, times, times, times, trace, transposeTimes, transposeTimes, transposeTimes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SparseVectorMatrix

public SparseVectorMatrix(int iN,
                          int iK)
Construct a N×K matrix with only zero values.

Parameters:
iN - number of rows, i.e. length of column vectors of the matrix.
iK - number of columns

SparseVectorMatrix

public SparseVectorMatrix(double[] vals,
                          int m)
Construct a matrix from a one-dimensional packed array

Parameters:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).
m - Number of rows, i.e. length of columns.
Throws:
java.lang.IllegalArgumentException - Array length must be a multiple of m.

SparseVectorMatrix

public SparseVectorMatrix(double[][] A)
Construct a matrix from a 2-D array, all values are copied.

Parameters:
A - Two-dimensional array of doubles.
Throws:
java.lang.IllegalArgumentException - All rows must have the same length

SparseVectorMatrix

public SparseVectorMatrix(AllMatrices B)
Construct a new matrix from another matrix (of any kind)

Parameters:
B - a matrix of any kind, class is a subclass of AllMatrices
Method Detail

get

public double get(int n,
                  int k)
Return an entry of the matrix. Note that the row, i.e. position in the column, is given first, the second argument is the column number. We should have: 0 <= n < N and 0 <= k < K. If any argument is outside legal range 0.0 is returned without error or warning.

Specified by:
get in class AllMatrices
Parameters:
n - row number for the returned entry value.
k - column number for the returned entry value.
Returns:
A(i,j)

set

public void set(int n,
                int k,
                double val)
Set an entry (a value) in the matrix. Note that the row, i.e. position in the column, is given first, the second argument is the column number. We should have: 0 <= n < N and 0 <= k < K. If any argument is outside legal range nothing is done.

Specified by:
set in class AllMatrices
Parameters:
n - row number for the entry value to be changed.
k - column number for the entry value to be changed.
val - the value to be put into the given entry of the dictionary.

getColumn

public double[] getColumn(int k)
Get a column in the matrix as an array

Overrides:
getColumn in class AllMatrices
Parameters:
k - column number for the column to be returned
Returns:
c the column as an array of length N

getSparseColumn

public SparseVector getSparseColumn(int k)
Get a copy of a column in the matrix as a SparseVector

Parameters:
k - column number for the column to be returned
Returns:
copy of the column

setColumn

public void setColumn(int k,
                      double[] c)
Replace a column in the matrix with the given column vector. The column should be of length N. We should have: 0 <= k < K. If any argument is outside legal dimension or range nothing is done.

Overrides:
setColumn in class AllMatrices
Parameters:
k - column number for the column to be changed.
c - the column as an array of length N

setColumn

public void setColumn(int k,
                      SparseVector c)
Replace a column in the matrix with a copy of the given column. The column should be of length N. We should have: 0 <= k < K. If any argument is outside legal dimension or range nothing is done.

Parameters:
k - column number for the column to be changed.
c - the column as a SparseVector

addColumn

public void addColumn(int k,
                      double factor,
                      double[] x)
Add a column of the matrix multiplied by a factor to a given vector. Legal range of the integer argument is 0 <= k < K.
The corresponding Matlab expression would be: x = x+factor*D(:,k+1).

Overrides:
addColumn in class AllMatrices
Parameters:
k - number of the column in dictionary, i.e. matrix D.
factor - a factor to multiply the column vector by.
x - an array of length N.

setAll

public void setAll(double[] vals)
Set all entries of to matrix to the supplied new values If argument is wrong length an IllegalArgumentException is thrown.

Overrides:
setAll in class AllMatrices
Parameters:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).

innerProduct

public double innerProduct(int k1,
                           int k2)
Returns the inner product of two matrix column vectors. Legal range is 0 <= k1 < K and 0 <= k2 < K.
If k1 or k2 is out of range, 0.0 is returned.

Overrides:
innerProduct in class AllMatrices
Parameters:
k1 - number for the first column.
k2 - number for the second column.

times

public void times(double[] y,
                  double[] x)
Multiplies the matrix by an array. The dimensions are: A is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: x = A*y.

Overrides:
times in class AllMatrices
Parameters:
y - the input array
x - the results as an array of length N.

transposeTimes

public void transposeTimes(double[] x,
                           double[] y)
Multiplies the transposed matrix by an array. The dimensions are: A is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: y = A'*x.

Overrides:
transposeTimes in class AllMatrices
Parameters:
x - the input array
y - the results as an array of length K.