Belle II Software light-2406-ragdoll
|
Class to calculate mean and and covariance between a number of parameters on running data without storing the actual values, also for weighted entries. More...
#include <CalcMeanCov.h>
Public Types | |
typedef RealType | value_type |
type of float variable to use for calculations and storage | |
Public Member Functions | |
CalcMeanCov () | |
default constructor. | |
void | clear () |
Clear all values. | |
template<class... T> | |
void | addWeighted (value_type weight, T... values) |
Update mean and covariance by adding a new, weighted entry. | |
template<class... T> | |
void | add (T... values) |
Update mean and covariance by adding a new entry. | |
void | add (const CalcMeanCov< N, RealType > &other) |
Merge the data set in 'other' into this one. | |
void | addWeightedArray (value_type weight, value_type *values) |
Update mean and covarianced by adding a new weighted entry. | |
void | addArray (value_type *values) |
Update mean and covariance by adding a new entry. | |
Getters | |
No range check if performed on indicies i and j | |
value_type | getEntries () const |
Return the number of entries. | |
value_type | getMean (int i) const |
Return the mean for parameter i. | |
value_type | getCovariance (int i, int j) const |
Return the covariance between parameters i and j. | |
value_type | getCorrelation (int i, int j) const |
Return the correlation coefficient between parameters i and j. | |
value_type | getVariance (int i) const |
Return the variance for paramter i. | |
value_type | getStddev (int i) const |
Return the standard deviation for parameter i. | |
value_type | getSum (int i) const |
Return the weighted sum values for parameter i. | |
Templated getters | |
These getters are templated and provide compile time range checking for the parameter indices | |
template<int i = 0> | |
value_type | getMean () const |
Return the mean for parameter i. | |
template<int i, int j> | |
value_type | getCovariance () const |
Return the covariance between parameters i and j. | |
template<int i, int j> | |
value_type | getCorrelation () const |
Return the correlation coefficient between parameters i and j. | |
template<int i = 0> | |
value_type | getVariance () const |
Return the variance for paramter i. | |
template<int i = 0> | |
value_type | getStddev () const |
Return the standard deviation for parameter i. | |
template<int i = 0> | |
value_type | getSum () const |
Return the weighted sum values for parameter i. | |
Private Member Functions | |
template<int i, class... T> | |
void | addValue (value_type weight, value_type x, T... values) |
Add a single value for parameter i and update mean and covariance. | |
template<int i> | |
void | addValue (value_type) |
Break recursion of addValue when no parameters are left. | |
template<int i, int j, class... T> | |
void | updateCov (value_type weight, value_type delta, value_type x, T... values) |
Update covariance between parameters i and j. | |
template<int i, int j> | |
void | updateCov (value_type, value_type) |
Break recursion of updateCov once all parameters are consumed. | |
void | addArrayValues (value_type weight, value_type *x) |
Add a new set of values and update mean and covariance. | |
constexpr int | getIndex (unsigned int i, unsigned int j) const |
Access element in triangular matrix including diagonal elements. | |
Private Attributes | |
value_type | m_entries |
Store the sum of weights. | |
value_type | m_mean [N] |
Store the mean values for all parameters. | |
value_type | m_covariance [N *(N+1)/2] |
Store the triangular covariance matrix for all parameters in continous memory. | |
Class to calculate mean and and covariance between a number of parameters on running data without storing the actual values, also for weighted entries.
It can store more than one value per entry, e.g. x,y,z values but will not calculate correlations, only mean and standard deviation for all values. Also works with weighted entries.
See Philippe Pébay, Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments, SANDIA REPORT SAND2008-6212
N | number of parameters |
RealType | floating point type to be used |
Definition at line 35 of file CalcMeanCov.h.
typedef RealType value_type |
type of float variable to use for calculations and storage
Definition at line 42 of file CalcMeanCov.h.
|
inline |
|
inline |
Merge the data set in 'other' into this one.
Definition at line 77 of file CalcMeanCov.h.
|
inline |
Update mean and covariance by adding a new entry.
values | values for all parameters. The number of Parameters must be equal to N |
Definition at line 71 of file CalcMeanCov.h.
|
inline |
Update mean and covariance by adding a new entry.
values | pointer to the first value |
Definition at line 109 of file CalcMeanCov.h.
|
inlineprivate |
Add a new set of values and update mean and covariance.
This function does the same as addValue and updateCov but in a non-templated way.
weight | weight of the entry |
x | pointer to the actual values |
Definition at line 240 of file CalcMeanCov.h.
|
inlineprivate |
Add a single value for parameter i and update mean and covariance.
i | index of the parameter |
weight | weight of the entry |
x | actual value |
values | remaining values to be added recursively |
Definition at line 199 of file CalcMeanCov.h.
|
inlineprivate |
Break recursion of addValue when no parameters are left.
Definition at line 210 of file CalcMeanCov.h.
|
inline |
Update mean and covariance by adding a new, weighted entry.
weight | weight of the entry |
values | values for all parameters. The number of parameters must be equal to N |
Definition at line 59 of file CalcMeanCov.h.
|
inline |
Update mean and covarianced by adding a new weighted entry.
weight | weight of entry |
values | pointer to the first value |
Definition at line 100 of file CalcMeanCov.h.
|
inline |
Clear all values.
Definition at line 45 of file CalcMeanCov.h.
|
inline |
Return the correlation coefficient between parameters i and j.
Definition at line 166 of file CalcMeanCov.h.
|
inline |
Return the correlation coefficient between parameters i and j.
Definition at line 130 of file CalcMeanCov.h.
|
inline |
Return the covariance between parameters i and j.
Definition at line 158 of file CalcMeanCov.h.
|
inline |
Return the covariance between parameters i and j.
Definition at line 124 of file CalcMeanCov.h.
|
inline |
|
inlineconstexprprivate |
Access element in triangular matrix including diagonal elements.
This function returns the storage index of an element (i,j) in a symmetric matrix including diagonal elements if the elements are stored in a continous array of size n(n+1)/2
Definition at line 260 of file CalcMeanCov.h.
|
inline |
Return the mean for parameter i.
Definition at line 152 of file CalcMeanCov.h.
|
inline |
|
inline |
Return the standard deviation for parameter i.
Definition at line 178 of file CalcMeanCov.h.
|
inline |
Return the standard deviation for parameter i.
Definition at line 139 of file CalcMeanCov.h.
|
inline |
Return the weighted sum values for parameter i.
Definition at line 183 of file CalcMeanCov.h.
|
inline |
Return the weighted sum values for parameter i.
Definition at line 141 of file CalcMeanCov.h.
|
inline |
Return the variance for paramter i.
Definition at line 173 of file CalcMeanCov.h.
|
inline |
|
inlineprivate |
Update covariance between parameters i and j.
i | first index |
j | second index |
weight | weight of the entry |
delta | difference between parameter i and mean of i |
x | value of parameter j |
values | remaining values with index >j |
Definition at line 222 of file CalcMeanCov.h.
|
inlineprivate |
Break recursion of updateCov once all parameters are consumed.
Definition at line 232 of file CalcMeanCov.h.
|
private |
Store the triangular covariance matrix for all parameters in continous memory.
Actual covariance is m_covariance[getIndex(i,j)]/m_entries
Definition at line 272 of file CalcMeanCov.h.
|
private |
Store the sum of weights.
Definition at line 267 of file CalcMeanCov.h.
|
private |
Store the mean values for all parameters.
Definition at line 269 of file CalcMeanCov.h.