public class StorelessCovariance extends Covariance
This class is based on a paper written by Philippe Pébay: Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments, 2008, Technical Report SAND2008-6212, Sandia National Laboratories.
Note: the underlying covariance matrix is symmetric, thus only the upper triangular part of the matrix is stored and updated each increment.
| Modifier and Type | Field and Description |
|---|---|
private StorelessBivariateCovariance[] |
covMatrix
the square covariance matrix (upper triangular part)
|
private int |
dimension
dimension of the square covariance matrix
|
| Constructor and Description |
|---|
StorelessCovariance(int dim)
Create a bias corrected covariance matrix with a given dimension.
|
StorelessCovariance(int dim,
boolean biasCorrected)
Create a covariance matrix with a given number of rows and columns and the
indicated bias correction.
|
| Modifier and Type | Method and Description |
|---|---|
double |
getCovariance(int xIndex,
int yIndex)
Get the covariance for an individual element of the covariance matrix.
|
RealMatrix |
getCovarianceMatrix()
Returns the covariance matrix
|
double[][] |
getData()
Return the covariance matrix as two-dimensional array.
|
private StorelessBivariateCovariance |
getElement(int i,
int j)
Gets the element at index (i, j) from the covariance matrix
|
int |
getN()
This
Covariance method is not supported by a StorelessCovariance,
since the number of bivariate observations does not have to be the same for different
pairs of covariates - i.e., N as defined in Covariance.getN() is undefined. |
void |
increment(double[] data)
Increment the covariance matrix with one row of data.
|
private int |
indexOf(int i,
int j)
Returns the index (i, j) translated into the one-dimensional
array used to store the upper triangular part of the symmetric
covariance matrix.
|
private void |
initializeMatrix(boolean biasCorrected)
Initialize the internal two-dimensional array of
StorelessBivariateCovariance instances. |
private void |
setElement(int i,
int j,
StorelessBivariateCovariance cov)
Sets the covariance element at index (i, j) in the covariance matrix
|
computeCovarianceMatrix, computeCovarianceMatrix, computeCovarianceMatrix, computeCovarianceMatrix, covariance, covarianceprivate StorelessBivariateCovariance[] covMatrix
private int dimension
public StorelessCovariance(int dim)
dim - the dimension of the square covariance matrixpublic StorelessCovariance(int dim,
boolean biasCorrected)
dim - the dimension of the covariance matrixbiasCorrected - if true the covariance estimate is corrected
for bias, i.e. n-1 in the denominator, otherwise there is no bias correction,
i.e. n in the denominator.private void initializeMatrix(boolean biasCorrected)
StorelessBivariateCovariance instances.biasCorrected - if the covariance estimate shall be corrected for biasprivate int indexOf(int i,
int j)
i - the row indexj - the column indexprivate StorelessBivariateCovariance getElement(int i, int j)
i - the row indexj - the column indexStorelessBivariateCovariance element at the given indexprivate void setElement(int i,
int j,
StorelessBivariateCovariance cov)
i - the row indexj - the column indexcov - the StorelessBivariateCovariance element to be setpublic double getCovariance(int xIndex,
int yIndex)
throws NumberIsTooSmallException
xIndex - row index in the covariance matrixyIndex - column index in the covariance matrixNumberIsTooSmallException - if the number of observations
in the cell is < 2public void increment(double[] data)
throws DimensionMismatchException
data - array representing one row of data.DimensionMismatchException - if the length of rowData
does not match with the covariance matrixpublic RealMatrix getCovarianceMatrix() throws NumberIsTooSmallException
getCovarianceMatrix in class CovarianceNumberIsTooSmallException - if the number of observations
in a cell is < 2public double[][] getData()
throws NumberIsTooSmallException
NumberIsTooSmallException - if the number of observations
for a cell is < 2public int getN()
throws MathUnsupportedOperationException
Covariance method is not supported by a StorelessCovariance,
since the number of bivariate observations does not have to be the same for different
pairs of covariates - i.e., N as defined in Covariance.getN() is undefined.getN in class CovarianceMathUnsupportedOperationExceptionMathUnsupportedOperationException - in all casesCopyright (c) 2003-2013 Apache Software Foundation