public class CovarianceMatrix extends Object
DatabaseUtil
for
easier to use APIs.
For use in algorithms, it is more appropriate to use
StandardCovarianceMatrixBuilder
since this class can be overridden with a
stabilized covariance matrix builder!Modifier and Type | Field and Description |
---|---|
(package private) double[][] |
elements
The covariance matrix.
|
static String |
ERR_TOO_LITTLE_WEIGHT
Error message reported when too little data (weight <= 1) in matrix.
|
(package private) double[] |
mean
The means.
|
(package private) double[] |
nmea
Temporary storage, to avoid reallocations.
|
protected double |
wsum
The current weight.
|
Constructor and Description |
---|
CovarianceMatrix(int dim)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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<?>> |
getMeanVector(Relation<? extends F> relation)
Get the mean as vector.
|
double |
getWeight()
Get the weight sum, to test whether the covariance matrix can be
materialized.
|
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,
DBIDs 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.
|
public static final String ERR_TOO_LITTLE_WEIGHT
double[] mean
double[][] elements
double[] nmea
protected double wsum
public CovarianceMatrix(int dim)
dim
- Dimensionalitypublic void put(double[] val)
val
- Valuepublic void put(double[] val, double weight)
val
- dataweight
- weightpublic final void put(Vector val)
val
- Valuepublic final void put(Vector val, double weight)
val
- dataweight
- weightpublic void put(NumberVector<?> val)
val
- Valuepublic double getWeight()
public void put(NumberVector<?> val, double weight)
val
- dataweight
- weightpublic Vector getMeanVector()
public <F extends NumberVector<?>> F getMeanVector(Relation<? extends F> relation)
F
- vector typerelation
- Data relationpublic Matrix makeSampleMatrix()
destroyToSampleMatrix()
if you do not need further
updates.public Matrix makeNaiveMatrix()
destroyToNaiveMatrix()
if you do not need further
updates.public Matrix destroyToSampleMatrix()
makeSampleMatrix()
if
you want to perform further updates.public Matrix destroyToNaiveMatrix()
makeNaiveMatrix()
if
you want to perform further updates.public static CovarianceMatrix make(Matrix mat)
mat
- Matrix to use the columns ofpublic static CovarianceMatrix make(Relation<? extends NumberVector<?>> relation)
relation
- Relation to use.public static CovarianceMatrix make(Relation<? extends NumberVector<?>> relation, DBIDs ids)
relation
- Relation to use.ids
- IDs to add