cc.mallet.types
Class SparseMatrixn

java.lang.Object
  extended by cc.mallet.types.SparseMatrixn
All Implemented Interfaces:
ConstantMatrix, Matrix, java.io.Serializable, java.lang.Cloneable

public class SparseMatrixn
extends java.lang.Object
implements Matrix, java.lang.Cloneable, java.io.Serializable

Implementation of Matrix that allows arbitrary number of dimensions. This implementation simply uses a flat array. Created: Tue Sep 16 14:52:37 2003

Version:
$Id: SparseMatrixn.java,v 1.1 2007/10/22 21:37:39 mccallum Exp $
Author:
Charles Sutton
See Also:
Serialized Form

Constructor Summary
SparseMatrixn(double[] vals)
          Create a 1-d dense matrix with the given values.
SparseMatrixn(int[] szs)
          Create a dense matrix with the given dimensions.
SparseMatrixn(int[] szs, double[] vals)
           
SparseMatrixn(int[] szs, int[] idxs, double[] vals)
          Create a sparse matrix with the given dimensions and the given values.
 
Method Summary
 double absNorm()
           
 double absNormalize()
           
 java.lang.Object clone()
           
 ConstantMatrix cloneMatrix()
           
 void divideEquals(double factor)
           
 double dotProduct(ConstantMatrix m)
           
 void elementwiseDivideEquals(ConstantMatrix m)
           
 void elementwiseDivideEquals(ConstantMatrix m, double factor)
           
 void elementwiseTimesEquals(ConstantMatrix m)
           
 void elementwiseTimesEquals(ConstantMatrix m, double factor)
           
 boolean equals(java.lang.Object o)
           
 void equalsPlus(double factor, ConstantMatrix m)
           
 int getDimensions(int[] szs)
           
 int[] getIndices()
          Returns an array of all the present indices.
 int getNumDimensions()
           
 void incrementSingleValue(int i, double delta)
           
 int indexAtLocation(int location)
           
 double infinityNorm()
           
 double infinityNormalize()
           
 boolean isNaN()
           
 int location(int index)
           
 int numLocations()
           
 double oneNorm()
           
 double oneNormalize()
           
 void plusEquals(ConstantMatrix m)
           
 void plusEquals(ConstantMatrix m, double factor)
           
 void print()
           
 void set(ConstantMatrix m)
           
 void setAll(double v)
           
 void setSingleValue(int i, double value)
           
 void setValue(int[] indices, double value)
           
 void setValueAtLocation(int location, double value)
           
 void setWithAddend(ConstantMatrix m, double addend)
           
 void setWithFactor(ConstantMatrix m, double factor)
           
 int singleIndex(int[] indices)
           
static int singleIndex(int[] szs, int[] indices)
           
 int singleSize()
           
 void singleToIndices(int single, int[] indices)
           
 double singleValue(int i)
           
 void timesEquals(double factor)
           
 double[] toArray()
          Returns a one-dimensional array representation of the matrix.
 double twoNorm()
           
 double twoNormalize()
           
 double value(int[] indices)
           
 double valueAtLocation(int location)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SparseMatrixn

public SparseMatrixn(double[] vals)
Create a 1-d dense matrix with the given values.


SparseMatrixn

public SparseMatrixn(int[] szs)
Create a dense matrix with the given dimensions.

Parameters:
szs - An array containing the maximum for each dimension.

SparseMatrixn

public SparseMatrixn(int[] szs,
                     double[] vals)

SparseMatrixn

public SparseMatrixn(int[] szs,
                     int[] idxs,
                     double[] vals)
Create a sparse matrix with the given dimensions and the given values.

Parameters:
szs - An array containing the maximum for each dimension.
idxs - An array containing the single index for each entry of the matrix. A single index is an integer computed from the indices of each dimension. as returned by Matrixn.singleIndex(int[]).
vals - A flat array of the entries of the matrix, in row-major order.
Method Detail

getNumDimensions

public int getNumDimensions()
Specified by:
getNumDimensions in interface ConstantMatrix

getDimensions

public int getDimensions(int[] szs)
Specified by:
getDimensions in interface ConstantMatrix

value

public double value(int[] indices)
Specified by:
value in interface ConstantMatrix

setValue

public void setValue(int[] indices,
                     double value)
Specified by:
setValue in interface Matrix

getIndices

public int[] getIndices()
Returns an array of all the present indices. Callers must not modify the return value.


cloneMatrix

public ConstantMatrix cloneMatrix()
Specified by:
cloneMatrix in interface ConstantMatrix

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

singleIndex

public int singleIndex(int[] indices)
Specified by:
singleIndex in interface ConstantMatrix

singleIndex

public static int singleIndex(int[] szs,
                              int[] indices)

singleToIndices

public void singleToIndices(int single,
                            int[] indices)
Specified by:
singleToIndices in interface ConstantMatrix

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toArray

public double[] toArray()
Returns a one-dimensional array representation of the matrix. Caller must not modify the return value.

Returns:
An array of the values where index 0 is the major index, etc.

singleValue

public double singleValue(int i)
Specified by:
singleValue in interface ConstantMatrix

singleSize

public int singleSize()
Specified by:
singleSize in interface ConstantMatrix

numLocations

public int numLocations()
Specified by:
numLocations in interface ConstantMatrix

location

public int location(int index)
Specified by:
location in interface ConstantMatrix

valueAtLocation

public double valueAtLocation(int location)
Specified by:
valueAtLocation in interface ConstantMatrix

setValueAtLocation

public void setValueAtLocation(int location,
                               double value)
Specified by:
setValueAtLocation in interface Matrix

indexAtLocation

public int indexAtLocation(int location)
Specified by:
indexAtLocation in interface ConstantMatrix

dotProduct

public double dotProduct(ConstantMatrix m)
Specified by:
dotProduct in interface ConstantMatrix

absNorm

public double absNorm()
Specified by:
absNorm in interface ConstantMatrix

oneNorm

public double oneNorm()
Specified by:
oneNorm in interface ConstantMatrix

twoNorm

public double twoNorm()
Specified by:
twoNorm in interface ConstantMatrix

infinityNorm

public double infinityNorm()
Specified by:
infinityNorm in interface ConstantMatrix

print

public void print()
Specified by:
print in interface ConstantMatrix

isNaN

public boolean isNaN()
Specified by:
isNaN in interface ConstantMatrix

setSingleValue

public void setSingleValue(int i,
                           double value)
Specified by:
setSingleValue in interface Matrix

incrementSingleValue

public void incrementSingleValue(int i,
                                 double delta)
Specified by:
incrementSingleValue in interface Matrix

setAll

public void setAll(double v)
Specified by:
setAll in interface Matrix

set

public void set(ConstantMatrix m)
Specified by:
set in interface Matrix

setWithAddend

public void setWithAddend(ConstantMatrix m,
                          double addend)
Specified by:
setWithAddend in interface Matrix

setWithFactor

public void setWithFactor(ConstantMatrix m,
                          double factor)
Specified by:
setWithFactor in interface Matrix

plusEquals

public void plusEquals(ConstantMatrix m)
Specified by:
plusEquals in interface Matrix

plusEquals

public void plusEquals(ConstantMatrix m,
                       double factor)
Specified by:
plusEquals in interface Matrix

equalsPlus

public void equalsPlus(double factor,
                       ConstantMatrix m)
Specified by:
equalsPlus in interface Matrix

timesEquals

public void timesEquals(double factor)
Specified by:
timesEquals in interface Matrix

elementwiseTimesEquals

public void elementwiseTimesEquals(ConstantMatrix m)
Specified by:
elementwiseTimesEquals in interface Matrix

elementwiseTimesEquals

public void elementwiseTimesEquals(ConstantMatrix m,
                                   double factor)
Specified by:
elementwiseTimesEquals in interface Matrix

divideEquals

public void divideEquals(double factor)
Specified by:
divideEquals in interface Matrix

elementwiseDivideEquals

public void elementwiseDivideEquals(ConstantMatrix m)
Specified by:
elementwiseDivideEquals in interface Matrix

elementwiseDivideEquals

public void elementwiseDivideEquals(ConstantMatrix m,
                                    double factor)
Specified by:
elementwiseDivideEquals in interface Matrix

oneNormalize

public double oneNormalize()
Specified by:
oneNormalize in interface Matrix

twoNormalize

public double twoNormalize()
Specified by:
twoNormalize in interface Matrix

absNormalize

public double absNormalize()
Specified by:
absNormalize in interface Matrix

infinityNormalize

public double infinityNormalize()
Specified by:
infinityNormalize in interface Matrix