Top Description Fields Constructors Methods
org.apache.commons.math3.stat.correlation

pack-priv Class StorelessBivariateCovariance

extends Object
Class Inheritance
Imports
org.apache.commons.math3.exception.NumberIsTooSmallException, org.apache.commons.math3.exception.util.LocalizedFormats

Bivariate 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 StorelessCovariance to estimate an entire covariance matrix.

Note

This class is package private as it is only used internally in the StorelessCovariance class.

Since
3.0

Field Summary

Modifier and TypeField and Description
private boolean
biasCorrected

flag for bias correction

private double
covarianceNumerator

the running covariance estimate

private double
meanX

the mean of variable x

private double
meanY

the mean of variable y

private double
n

number of observations

Constructor Summary

AccessConstructor and Description
pack-priv
StorelessBivariateCovariance()

Create an empty StorelessBivariateCovariance instance with bias correction.

pack-priv
StorelessBivariateCovariance(final boolean
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.
biasCorrection
)

Create an empty StorelessBivariateCovariance instance.

Method Summary

Modifier and TypeMethod and Description
public void
append(StorelessBivariateCovariance
StorelessBivariateCovariance instance to append.
cov
)

Appends another bivariate covariance calculation to this.

public double

Returns:

number of observations
getN
()

Returns the number of observations.

public double

Returns:

the current covariance
getResult
()

Return the current covariance estimate.

public void
increment(final double
the x value
x
,
final double
the y value
y
)

Update the covariance estimation with a pair of variables (x, y).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

biasCorrectedback to summary
private boolean biasCorrected

flag for bias correction

covarianceNumeratorback to summary
private double covarianceNumerator

the running covariance estimate

meanXback to summary
private double meanX

the mean of variable x

meanYback to summary
private double meanY

the mean of variable y

nback to summary
private double n

number of observations

Constructor Detail

StorelessBivariateCovarianceback to summary
pack-priv StorelessBivariateCovariance()

Create an empty StorelessBivariateCovariance instance with bias correction.

StorelessBivariateCovarianceback to summary
pack-priv StorelessBivariateCovariance(final boolean biasCorrection)

Create an empty StorelessBivariateCovariance instance.

Parameters
biasCorrection:boolean

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.

Method Detail

appendback to summary
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 the increment(double, double) operations in cov directly on this.

Parameters
cov:StorelessBivariateCovariance

StorelessBivariateCovariance instance to append.

getNback to summary
public double getN()

Returns the number of observations.

Returns:double

number of observations

getResultback to summary
public double getResult() throws NumberIsTooSmallException

Return the current covariance estimate.

Returns:double

the current covariance

Exceptions
NumberIsTooSmallException:
if the number of observations is < 2
incrementback to summary
public void increment(final double x, final double y)

Update the covariance estimation with a pair of variables (x, y).

Parameters
x:double

the x value

y:double

the y value