de.lmu.ifi.dbs.elki.math.linearalgebra
Class CovarianceMatrix

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.math.linearalgebra.CovarianceMatrix

public class CovarianceMatrix
extends Object

Class for computing covariance matrixes using stable mean and variance computations. This class encapsulates the mathematical aspects of computing this matrix. See DatabaseUtil for easier to use APIs. For use in algorithms, it is more appropriate to use StandardCovarianceMatrixBuilder since this class can be overriden with a stabilized covariance matrix builder!


Field Summary
(package private)  double[][] elements
          The covariance matrix
(package private)  double[] mean
          The means
(package private)  double[] nmea
          Temporary storage, to avoid reallocations
protected  double wsum
          The current weight
 
Constructor Summary
CovarianceMatrix(int dim)
          Constructor.
 
Method Summary
 Matrix destroyToNaiveMatrix()
          Obtain the covariance matrix according to the population statistics: n degrees of freedom.
 Matrix destroyToSampleMatrix()
          Obtain the covariance matrix according to the sample statistics: (n-1) degrees of freedom.
 Vector getMeanVector()
          Get the mean as vector.
<F extends NumberVector<? extends F,?>>
F
getMeanVector(Relation<? extends F> relation)
          Get the mean as vector.
static CovarianceMatrix make(Matrix mat)
          Static Constructor.
static CovarianceMatrix make(Relation<? extends NumberVector<?,?>> relation)
          Static Constructor from a full relation.
static CovarianceMatrix make(Relation<? extends NumberVector<?,?>> relation, Iterable<DBID> ids)
          Static Constructor from a full relation.
 Matrix makeNaiveMatrix()
          Obtain the covariance matrix according to the population statistics: n degrees of freedom.
 Matrix makeSampleMatrix()
          Obtain the covariance matrix according to the sample statistics: (n-1) degrees of freedom.
 void put(double[] val)
          Add a single value with weight 1.0
 void put(double[] val, double weight)
          Add data with a given weight.
 void put(NumberVector<?,?> val)
          Add a single value with weight 1.0
 void put(NumberVector<?,?> val, double weight)
          Add data with a given weight.
 void put(Vector val)
          Add a single value with weight 1.0
 void put(Vector val, double weight)
          Add data with a given weight.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mean

double[] mean
The means


elements

double[][] elements
The covariance matrix


nmea

double[] nmea
Temporary storage, to avoid reallocations


wsum

protected double wsum
The current weight

Constructor Detail

CovarianceMatrix

public CovarianceMatrix(int dim)
Constructor.

Parameters:
dim - Dimensionality
Method Detail

put

public void put(double[] val)
Add a single value with weight 1.0

Parameters:
val - Value

put

public void put(double[] val,
                double weight)
Add data with a given weight.

Parameters:
val - data
weight - weight

put

public final void put(Vector val)
Add a single value with weight 1.0

Parameters:
val - Value

put

public final void put(Vector val,
                      double weight)
Add data with a given weight.

Parameters:
val - data
weight - weight

put

public void put(NumberVector<?,?> val)
Add a single value with weight 1.0

Parameters:
val - Value

put

public void put(NumberVector<?,?> val,
                double weight)
Add data with a given weight.

Parameters:
val - data
weight - weight

getMeanVector

public Vector getMeanVector()
Get the mean as vector.

Returns:
Mean vector

getMeanVector

public <F extends NumberVector<? extends F,?>> F getMeanVector(Relation<? extends F> relation)
Get the mean as vector.

Returns:
Mean vector

makeSampleMatrix

public Matrix makeSampleMatrix()
Obtain the covariance matrix according to the sample statistics: (n-1) degrees of freedom. This method duplicates the matrix contents, so it does allow further updates. Use destroyToSampleMatrix() if you do not need further updates.

Returns:
New matrix

makeNaiveMatrix

public Matrix makeNaiveMatrix()
Obtain the covariance matrix according to the population statistics: n degrees of freedom. This method duplicates the matrix contents, so it does allow further updates. Use destroyToNaiveMatrix() if you do not need further updates.

Returns:
New matrix

destroyToSampleMatrix

public Matrix destroyToSampleMatrix()
Obtain the covariance matrix according to the sample statistics: (n-1) degrees of freedom. This method doesn't require matrix duplication, but will not allow further updates, the object should be discarded. Use makeSampleMatrix() if you want to perform further updates.

Returns:
New matrix

destroyToNaiveMatrix

public Matrix destroyToNaiveMatrix()
Obtain the covariance matrix according to the population statistics: n degrees of freedom. This method doesn't require matrix duplication, but will not allow further updates, the object should be discarded. Use makeNaiveMatrix() if you want to perform further updates.

Returns:
New matrix

make

public static CovarianceMatrix make(Matrix mat)
Static Constructor.

Parameters:
mat - Matrix to use the columns of

make

public static CovarianceMatrix make(Relation<? extends NumberVector<?,?>> relation)
Static Constructor from a full relation.

Parameters:
relation - Relation to use.

make

public static CovarianceMatrix make(Relation<? extends NumberVector<?,?>> relation,
                                    Iterable<DBID> ids)
Static Constructor from a full relation.

Parameters:
relation - Relation to use.
ids - IDs to add

Release 0.4.0 (2011-09-20_1324)