CovarianceAccumulator class
CovarianceAccumulator computes covariance and correlation of pairs of samples by accumulating the
first two central moments and cross-moments.
Samples are added one pair at the time, using the Push method. Other members are used to retrieve the results.
The accumulator uses a stable algorithm to prevent catastrophic cancellation.
The covariance matrix is formed by
| cov.VarianceX() cov.Covariance() | | cov.Covariance() cov.VarianceY() |
The Regression method returns the parameters to the least squares fit of the equation ,
where is the first sample in each pair and is the second (this is linear regression), is the
intercept and is the slope. The Slope method computes only the slope component.
It is possible to accumulate samples in different objects (e.g. when processing with multiple threads),
and add the accumulators together using the + operator.
Aliases
- using RegressionResult = dip::RegressionParameters
- Copying type for backward compatibility.
Functions
- auto Correlation() const -> dip::dfloat
- Estimator of correlation between the two variables
- auto Covariance() const -> dip::dfloat
- Unbiased estimator of population covariance
- auto MeanX() const -> dip::dfloat
- Unbiased estimator of population mean for first variable
- auto MeanY() const -> dip::dfloat
- Unbiased estimator of population mean for second variable
- auto Number() const -> dip::uint
- Number of samples
- void Push(dip::dfloat x, dip::dfloat y)
- Add a pair of samples to the accumulator
- auto Regression() const -> dip::CovarianceAccumulator::RegressionResult
- Computes the slope and intercept of the regression line
- void Reset()
- Reset the accumulator, leaving it as if newly allocated.
- auto Slope() const -> dip::dfloat
- Computes the slope of the regression line
- auto StandardDeviationX() const -> dip::dfloat
- Estimator of population standard deviation for first variable (it is not possible to derive an unbiased estimator)
- auto StandardDeviationY() const -> dip::dfloat
- Estimator of population standard deviation for second variable (it is not possible to derive an unbiased estimator)
- auto VarianceX() const -> dip::dfloat
- Unbiased estimator of population variance for first variable
- auto VarianceY() const -> dip::dfloat
- Unbiased estimator of population variance for second variable
Operators
- auto operator+=(dip::CovarianceAccumulator const& other) -> dip::CovarianceAccumulator&
- Combine two accumulators
Alias documentation
using RegressionResult = dip::RegressionParameters
Copying type for backward compatibility.
Function documentation
void Reset( )
Reset the accumulator, leaving it as if newly allocated.
void Push( dip::dfloat x, dip::dfloat y)
Add a pair of samples to the accumulator
dip::dfloat MeanX( ) const
Unbiased estimator of population mean for first variable
dip::dfloat MeanY( ) const
Unbiased estimator of population mean for second variable
dip::dfloat VarianceX( ) const
Unbiased estimator of population variance for first variable
dip::dfloat VarianceY( ) const
Unbiased estimator of population variance for second variable
dip::dfloat StandardDeviationX( ) const
Estimator of population standard deviation for first variable (it is not possible to derive an unbiased estimator)
dip::dfloat StandardDeviationY( ) const
Estimator of population standard deviation for second variable (it is not possible to derive an unbiased estimator)
dip::dfloat Covariance( ) const
Unbiased estimator of population covariance
dip::dfloat Correlation( ) const
Estimator of correlation between the two variables
dip::dfloat Slope( ) const
Computes the slope of the regression line
dip::CovarianceAccumulator::RegressionResult Regression( ) const
Computes the slope and intercept of the regression line
dip::CovarianceAccumulator& operator+=( dip::CovarianceAccumulator const& other)
Combine two accumulators