Class StorelessBivariateCovariance
- java.lang.Object
-
- org.apache.commons.math3.stat.correlation.StorelessBivariateCovariance
-
class StorelessBivariateCovariance extends java.lang.ObjectBivariate Covariance implementation that does not require input data to be stored in memory.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. It computes the covariance for a pair of variables. Use
StorelessCovarianceto estimate an entire covariance matrix.Note: This class is package private as it is only used internally in the
StorelessCovarianceclass.- Since:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description private booleanbiasCorrectedflag for bias correctionprivate doublecovarianceNumeratorthe running covariance estimateprivate doublemeanXthe mean of variable xprivate doublemeanYthe mean of variable yprivate doublennumber of observations
-
Constructor Summary
Constructors Constructor Description StorelessBivariateCovariance()Create an emptyStorelessBivariateCovarianceinstance with bias correction.StorelessBivariateCovariance(boolean biasCorrection)Create an emptyStorelessBivariateCovarianceinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(StorelessBivariateCovariance cov)Appends another bivariate covariance calculation to this.doublegetN()Returns the number of observations.doublegetResult()Return the current covariance estimate.voidincrement(double x, double y)Update the covariance estimation with a pair of variables (x, y).
-
-
-
Field Detail
-
meanX
private double meanX
the mean of variable x
-
meanY
private double meanY
the mean of variable y
-
n
private double n
number of observations
-
covarianceNumerator
private double covarianceNumerator
the running covariance estimate
-
biasCorrected
private boolean biasCorrected
flag for bias correction
-
-
Constructor Detail
-
StorelessBivariateCovariance
StorelessBivariateCovariance()
Create an emptyStorelessBivariateCovarianceinstance with bias correction.
-
StorelessBivariateCovariance
StorelessBivariateCovariance(boolean biasCorrection)
Create an emptyStorelessBivariateCovarianceinstance.- Parameters:
biasCorrection- iftruethe 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.
-
-
Method Detail
-
increment
public void increment(double x, double y)Update the covariance estimation with a pair of variables (x, y).- Parameters:
x- the x valuey- the y value
-
append
public void append(StorelessBivariateCovariance cov)
Appends another bivariate covariance calculation to this. After this operation, statistics returned should be close to what would have been obtained by by performing all of theincrement(double, double)operations incovdirectly on this.- Parameters:
cov- StorelessBivariateCovariance instance to append.
-
getN
public double getN()
Returns the number of observations.- Returns:
- number of observations
-
getResult
public double getResult() throws NumberIsTooSmallExceptionReturn the current covariance estimate.- Returns:
- the current covariance
- Throws:
NumberIsTooSmallException- if the number of observations is < 2
-
-