mp
Class MPMatrix

java.lang.Object
  extended bymp.MPDictionary
      extended bymp.MPMatrix

public class MPMatrix
extends MPDictionary

This class is a simple matrix implementation of the MPDictionary superclass. The dictionary is represented columnwise as a matrix D of size N×K, i.e. as a length K array of column vectors, each is a length N array.


Constructor Summary
MPMatrix(double[][] val)
          Constructs a N×K matrix or dictionary with values from given two-dimensional array, which represents the matrix in columnwise ordering.
MPMatrix(int iN, int iK)
          Constructs a N×K matrix or dictionary with random values.
MPMatrix(int iN, int iK, double[] val)
          Constructs a N×K matrix or dictionary with values from given one-dimensional array (which represents the matrix).
 
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 getValue(int n, int k)
          Returns an entry of the matrix, i.e. a single entry of a dictionary element (atom).
 double innerProduct(int k1, int k2)
          Returns the inner product of two dictionary elements, i.e. matrix column vectors.
 double[] multiply(double[] y)
          Multiplies the dictionary D by array y.
 void multiply(double[] y, double[] x)
          Multiplies the dictionary D by array y.
 void normalize()
          Normalize the dictionary, i.e. multiply each dictionary element (matrix column vector) by a number (scalar) such that the 2-norm, i.e. sum of squares, will be 1.0.
 void setColumn(int k, double[] col)
          Replace a column in the dictionary with the given column vector.
 void setValue(int n, int k, double val)
          Set an entry (a value) in the dictionary.
 double singleInnerProduct(int k1, int k2)
          Calculates and returns the inner product of two dictionary elements.
 double[] transposeMultiply(double[] x)
          Multiplies the transposed dictionary D' by array x.
 void transposeMultiply(double[] x, double[] y)
          Multiplies the transposed dictionary D' by array x.
 
Methods inherited from class mp.MPDictionary
getColumn, getColumn, getColumns, getK, getN, getRow, getRow, getRows, isNormalized, setRow
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MPMatrix

public MPMatrix(int iN,
                int iK)
Constructs a N×K matrix or dictionary with random values.

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

MPMatrix

public MPMatrix(int iN,
                int iK,
                double[] val)
Constructs a N×K matrix or dictionary with values from given one-dimensional array (which represents the matrix). Length of the array should be N*K.

Parameters:
iN - length of dictionary elements, i.e. column vectors of the matrix
iK - number of dictionary elements
val - the values (ordered by column, i.e. by dictionary elements)

MPMatrix

public MPMatrix(double[][] val)
Constructs a N×K matrix or dictionary with values from given two-dimensional array, which represents the matrix in columnwise ordering. The input argument should thus be an array of K arrays, each with length N.

Parameters:
val - the values, a (columnwise) matrix.
Method Detail

getValue

public double getValue(int n,
                       int k)
Returns an entry of the matrix, i.e. a single entry of a dictionary element (atom). Note that the row, i.e. position in the column, is given first, the second argument is the column number i.e. the number of the dictionary atom. 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:
getValue in class MPDictionary
Parameters:
n - row number for the returned entry value.
k - column number for the returned entry value.

setValue

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

Specified by:
setValue in class MPDictionary
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.

setColumn

public void setColumn(int k,
                      double[] col)
Replace a column in the dictionary 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 MPDictionary
Parameters:
k - column number for the column to be changed.
col - the value to be put into the given entry of the dictionary.

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 MPDictionary
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.

innerProduct

public double innerProduct(int k1,
                           int k2)
Returns the inner product of two dictionary elements, i.e. matrix column vectors. In the current implementation all inner products are calculated (and stored) first time the function is called, subsequent calls to this function just look up in this precalculated table and are thus much faster than first time function was called.
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 MPDictionary
Parameters:
k1 - number for the first dictionary element.
k2 - number for the second dictionary element.

singleInnerProduct

public double singleInnerProduct(int k1,
                                 int k2)
Calculates and returns the inner product of two dictionary elements. Just the wanted inner product is calculated and the precalculated table is not used, neither for calculation nor for storing elements.
Legal range is 0 <= k1 < K and 0 <= k2 < K.
If k1 or k2 is out of range, 0.0 is returned.

Parameters:
k1 - number for the first dictionary element.
k2 - number for the second dictionary element.

normalize

public void normalize()
Normalize the dictionary, i.e. multiply each dictionary element (matrix column vector) by a number (scalar) such that the 2-norm, i.e. sum of squares, will be 1.0.

Overrides:
normalize in class MPDictionary

transposeMultiply

public double[] transposeMultiply(double[] x)
Multiplies the transposed dictionary D' by array x. D is the matrix representing the dictionary, each column is a dictionary element. An array y is returned.
The dimensions are: D is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: y = D'*x.

Overrides:
transposeMultiply in class MPDictionary
Parameters:
x - the signal (column vector) that is multiplied by the transposed dictionary.
Returns:
the results as an array of length K.

transposeMultiply

public void transposeMultiply(double[] x,
                              double[] y)
Multiplies the transposed dictionary D' by array x. D is the matrix representing the dictionary, each column is a dictionary element. An array y is returned.
The dimensions are: D is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: y = D'*x.

Overrides:
transposeMultiply in class MPDictionary
Parameters:
x - the signal (column vector) that is multiplied by the transposed dictionary.
y - the results as an array of length K.

multiply

public double[] multiply(double[] y)
Multiplies the dictionary D by array y. D is the matrix representing the dictionary, each column is a dictionary element. An array x is returned.
The dimensions are: D is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: x = D*y.

Overrides:
multiply in class MPDictionary
Parameters:
y - the coefficient vector that is multiplied by the dictionary.
Returns:
the results as an array of length N.

multiply

public void multiply(double[] y,
                     double[] x)
Multiplies the dictionary D by array y. D is the matrix representing the dictionary, each column is a dictionary element. An array x is returned.
The dimensions are: D is N×K, x is N×1, and y is K×1.
The corresponding mulitplication in Matlab would be: x = D*y.

Overrides:
multiply in class MPDictionary
Parameters:
y - the coefficient vector that is multiplied by the dictionary.
x - the results as an array of length N.