LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
Collects statistics on two homogeneous quantities (weighted) More...
#include "StatCollector.h"
Public Types | |
using | Base_t = details::WeightTracker< W > |
using | This_t = StatCollector2D< T, W > |
this type More... | |
using | Data_t = T |
type of the data More... | |
using | Weight_t = typename Base_t::Weight_t |
type of the weight More... | |
using | Pair_t = std::tuple< Data_t, Data_t > |
using | WeightedPair_t = std::tuple< Data_t, Data_t, Weight_t > |
Public Member Functions | |
template<typename Iter > | |
void | add_unweighted (Iter begin, Iter end) |
Adds entries from a sequence with weight 1. More... | |
template<typename Iter , typename Pred > | |
void | add_unweighted (Iter begin, Iter end, Pred extractor) |
Adds entries from a sequence with weight 1. More... | |
template<typename Cont , typename Pred > | |
void | add_unweighted (Cont cont, Pred extractor) |
Adds all entries from a container, with weight 1. More... | |
template<typename Cont > | |
void | add_unweighted (Cont cont) |
Adds all entries from a container, with weight 1. More... | |
template<typename VIter , typename WIter , typename VPred , typename WPred = identity> | |
void | add_weighted (VIter begin_value, VIter end_value, WIter begin_weight, VPred value_extractor, WPred weight_extractor=WPred()) |
Adds entries from a sequence with individually specified weights. More... | |
template<typename Iter > | |
void | add_weighted (Iter begin, Iter end) |
Adds entries from a sequence with individually specified weights. More... | |
template<typename Cont > | |
void | add_weighted (Cont cont) |
Adds entries from a sequence with individually specified weights. More... | |
void | clear () |
Clears all the statistics. More... | |
void | add (Weight_t weight) |
Adds the specified weight to the statistics. More... | |
Add elements | |
void | add (Data_t x, Data_t y, Weight_t weight=Weight_t(1.0)) |
Adds one entry with specified values and weight. More... | |
void | add (Pair_t value, Weight_t weight=Weight_t(1.0)) |
Adds one entry with specified values and weight. More... | |
void | add (WeightedPair_t value) |
Adds one entry with specified values and weight. More... | |
Statistic retrieval | |
int | N () const |
Returns the number of entries added. More... | |
Weight_t | Weights () const |
Returns the sum of the weights. More... | |
Weight_t | SumX () const |
Returns the weighted sum of the x values. More... | |
Weight_t | SumY () const |
Returns the weighted sum of the y values. More... | |
Weight_t | SumSqX () const |
Returns the weighted sum of the square of the x values. More... | |
Weight_t | SumSqY () const |
Returns the weighted sum of the square of the y values. More... | |
Weight_t | SumXY () const |
Returns the weighted sum of the product of x and y values. More... | |
Weight_t | AverageX () const |
Returns the x value average. More... | |
Weight_t | AverageY () const |
Returns the y value average. More... | |
Weight_t | VarianceX () const |
Returns the variance of the x values. More... | |
Weight_t | VarianceY () const |
Returns the variance of the y values. More... | |
Weight_t | Covariance () const |
Returns the covariance of the (x, y) pair. More... | |
Weight_t | RMSx () const |
Returns the standard deviation of the x sample. More... | |
Weight_t | RMSy () const |
Returns the standard deviation of the y sample. More... | |
Weight_t | LinearCorrelation () const |
Returns the linear correlation. More... | |
Weight_t | AverageWeight () const |
Returns the arithmetic average of the weights. More... | |
Static Public Member Functions | |
template<typename V > | |
static constexpr V | sqr (V const &v) |
Returns the square of the specified value. More... | |
Protected Types | |
using | Variable_t = details::DataTracker2< Data_t, Weight_t > |
Protected Attributes | |
Variable_t | x |
accumulator for variable x More... | |
Variable_t | y |
accumulator for variable y More... | |
Weight_t | sum_xy = Weight_t(0) |
weighted sum of xy More... | |
int | n = 0 |
number of added entries More... | |
Weight_t | w = Weight_t(0) |
total weight More... | |
Collects statistics on two homogeneous quantities (weighted)
T | type of the quantities |
W | type of the weight (as T by default) |
This is a convenience class, as easy to use as:
or also
that should both print: "Statistics from 3 entries: 3.8, 3.8".
Other functions are available allowing addition of weighted and unweighted data from collections. For additional examples, see the unit test StatCollector_test.cc .
Definition at line 477 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::Base_t = details::WeightTracker<W> |
Definition at line 479 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::Data_t = T |
type of the data
Definition at line 484 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::Pair_t = std::tuple<Data_t, Data_t> |
Definition at line 487 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::This_t = StatCollector2D<T, W> |
this type
Definition at line 483 of file StatCollector.h.
|
protected |
Definition at line 733 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::Weight_t = typename Base_t::Weight_t |
type of the weight
Definition at line 485 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::WeightedPair_t = std::tuple<Data_t, Data_t, Weight_t> |
Definition at line 488 of file StatCollector.h.
|
inlineinherited |
Adds the specified weight to the statistics.
Definition at line 49 of file StatCollector.h.
Referenced by lar::util::details::FitDataCollector< T, D >::add().
void lar::util::StatCollector2D< T, W >::add | ( | Data_t | x, |
Data_t | y, | ||
Weight_t | weight = Weight_t(1.0) |
||
) |
Adds one entry with specified values and weight.
Definition at line 923 of file StatCollector.h.
|
inline |
Adds one entry with specified values and weight.
Definition at line 499 of file StatCollector.h.
References weight.
|
inline |
Adds one entry with specified values and weight.
Definition at line 504 of file StatCollector.h.
|
inline |
Adds entries from a sequence with weight 1.
Iter | forward iterator to the pairs to be added |
begin | iterator pointing to the first element to be added |
end | iterator pointing after the last element to be added |
The value pointed by the iterator must be a tuple with types compatible with Pair_t.
Definition at line 520 of file StatCollector.h.
References util::begin(), and util::end().
void lar::util::StatCollector2D< T, W >::add_unweighted | ( | Iter | begin, |
Iter | end, | ||
Pred | extractor | ||
) |
Adds entries from a sequence with weight 1.
Iter | forward iterator to the elements to be added |
Pred | a predicate to extract the element from iterator value |
begin | iterator pointing to the first element to be added |
end | iterator pointing after the last element to be added |
extractor | the predicate extracting the value to be inserted |
The predicate is required to react to a call like with:
Definition at line 935 of file StatCollector.h.
|
inline |
Adds all entries from a container, with weight 1.
Cont | type of container of the elements to be added |
Pred | a predicate to extract the element from iterator value |
cont | container of the elements to be added |
extractor | the predicate extracting the value to be inserted |
The predicate is required to react to a call like with:
The container must support the range-based for loop syntax, that is is must have std::begin<Cont>() and std::end<Cont>() defined.
Definition at line 556 of file StatCollector.h.
References util::begin(), and util::end().
|
inline |
Adds all entries from a container, with weight 1.
Cont | type of container of the elements to be added |
cont | container of the elements to be added |
The container must support the range-based for loop syntax, that is is must have std::begin<Cont>() and std::end<Cont>() defined. The value in the container must be convertible to the Data_t type.
Definition at line 571 of file StatCollector.h.
References util::begin(), and util::end().
void lar::util::StatCollector2D< T, W >::add_weighted | ( | VIter | begin_value, |
VIter | end_value, | ||
WIter | begin_weight, | ||
VPred | value_extractor, | ||
WPred | weight_extractor = WPred() |
||
) |
Adds entries from a sequence with individually specified weights.
VIter | forward iterator to the elements to be added |
WIter | forward iterator to the weights |
VPred | a predicate to extract the element from iterator value |
WPred | a predicate to extract the weight from iterator value |
begin_value | iterator pointing to the first element to be added |
end_value | iterator pointing after the last element to be added |
begin_weight | iterator pointing to the weight of first element |
value_extractor | predicate extracting the value to be inserted |
weight_extractor | predicate extracting the weight to be inserted |
Each element is added with the weight pointed by the matching element in the list pointed by begin_weight: the element *(begin_value)
will have weight *(begin_weight)
, the next element *(begin_value + 1)
will have weight *(begin_weight + 1)
, etc.
The predicates are required to react to a call like with:
Definition at line 942 of file StatCollector.h.
void lar::util::StatCollector2D< T, W >::add_weighted | ( | Iter | begin, |
Iter | end | ||
) |
Adds entries from a sequence with individually specified weights.
Iter | forward iterator to WeightedPair_t elements to be added |
begin | iterator pointing to the first element to be added |
end | iterator pointing after the last element to be added |
The value pointed by the iterator must be a WeightedPair_t or something with elements convertible to its own (Data_t, Data_t and Weight_t). For more complicate structures, use the version with two predicates (using the weight iterator the same as the value iterator).
Definition at line 958 of file StatCollector.h.
|
inline |
Adds entries from a sequence with individually specified weights.
Cont | type of container of WeightedPair_t elements to be added |
cont | container of (x, y, weight) pairs to be added |
The values in the container must be tuples with first and second element convertible to the Data_t and the third element convertible to Weight_t.
Definition at line 630 of file StatCollector.h.
References util::begin(), clear(), and util::end().
|
inline |
Returns the arithmetic average of the weights.
std::range_error | if no entry was added |
Definition at line 728 of file StatCollector.h.
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::AverageX | ( | ) | const |
Returns the x value average.
std::range_error | if the total weight is 0 (usually: no data) |
Definition at line 975 of file StatCollector.h.
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::AverageY | ( | ) | const |
Returns the y value average.
std::range_error | if the total weight is 0 (usually: no data) |
Definition at line 1002 of file StatCollector.h.
|
inline |
Clears all the statistics.
Definition at line 966 of file StatCollector.h.
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::Covariance | ( | ) | const |
Returns the covariance of the (x, y) pair.
std::range_error | if the total weight is 0 (usually: no data) |
Definition at line 1020 of file StatCollector.h.
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::LinearCorrelation | ( | ) | const |
Returns the linear correlation.
std::range_error | if the total weight is 0 (see Covariance()) |
std::range_error | if any variance is non-positive |
Definition at line 1039 of file StatCollector.h.
|
inline |
Returns the number of entries added.
Definition at line 644 of file StatCollector.h.
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::RMSx | ( | ) | const |
Returns the standard deviation of the x sample.
std::range_error | if the total weight is 0 (see VarianceX()) |
std::range_error | if VarianceX() is negative (due to rounding errors) |
Definition at line 993 of file StatCollector.h.
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::RMSy | ( | ) | const |
Returns the standard deviation of the y sample.
std::range_error | if the total weight is 0 (see VarianceY()) |
std::range_error | if VarianceY() is negative (due to rounding errors) |
Definition at line 1029 of file StatCollector.h.
|
inlinestaticinherited |
Returns the square of the specified value.
Definition at line 77 of file StatCollector.h.
|
inline |
Returns the weighted sum of the square of the x values.
Definition at line 656 of file StatCollector.h.
|
inline |
Returns the weighted sum of the square of the y values.
Definition at line 659 of file StatCollector.h.
|
inline |
Returns the weighted sum of the x values.
Definition at line 650 of file StatCollector.h.
|
inline |
Returns the weighted sum of the product of x and y values.
Definition at line 662 of file StatCollector.h.
|
inline |
Returns the weighted sum of the y values.
Definition at line 653 of file StatCollector.h.
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::VarianceX | ( | ) | const |
Returns the variance of the x values.
std::range_error | if the total weight is 0 (usually: no data) |
Definition at line 984 of file StatCollector.h.
References sqr().
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::VarianceY | ( | ) | const |
Returns the variance of the y values.
std::range_error | if the total weight is 0 (usually: no data) |
Definition at line 1011 of file StatCollector.h.
References sqr().
|
inline |
Returns the sum of the weights.
Definition at line 647 of file StatCollector.h.
|
protectedinherited |
number of added entries
Definition at line 83 of file StatCollector.h.
|
protected |
weighted sum of xy
Definition at line 737 of file StatCollector.h.
|
protectedinherited |
total weight
Definition at line 84 of file StatCollector.h.
|
protected |
accumulator for variable x
Definition at line 735 of file StatCollector.h.
|
protected |
accumulator for variable y
Definition at line 736 of file StatCollector.h.