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 Types inherited from lar::util::details::WeightTracker< W > | |
using | Weight_t = W |
type of the weight More... | |
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... | |
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)) |
void | add (WeightedPair_t value) |
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... | |
Public Member Functions inherited from lar::util::details::WeightTracker< W > | |
void | add (Weight_t weight) |
Adds the specified weight to the statistics. More... | |
void | clear () |
Resets the count. More... | |
int | N () const |
Returns the number of entries added. More... | |
Weight_t | Weights () const |
Returns the sum of the weights. More... | |
Weight_t | AverageWeight () const |
Returns the arithmetic average of the weights. 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... | |
Protected Attributes inherited from lar::util::details::WeightTracker< W > | |
int | n = 0 |
number of added entries More... | |
Weight_t | w = Weight_t(0) |
total weight More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from lar::util::details::WeightTracker< W > | |
template<typename V > | |
static constexpr V | sqr (V const &v) |
Returns the square of the specified value. 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 483 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::Pair_t = std::tuple<Data_t, Data_t> |
Definition at line 486 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::This_t = StatCollector2D<T, W> |
this type
Definition at line 482 of file StatCollector.h.
|
protected |
Definition at line 728 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::Weight_t = typename Base_t::Weight_t |
type of the weight
Definition at line 484 of file StatCollector.h.
using lar::util::StatCollector2D< T, W >::WeightedPair_t = std::tuple<Data_t, Data_t, Weight_t> |
Definition at line 487 of file StatCollector.h.
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 943 of file StatCollector.h.
|
inline |
Definition at line 498 of file StatCollector.h.
|
inline |
Definition at line 501 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 515 of file StatCollector.h.
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 955 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 549 of file StatCollector.h.
|
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 562 of file StatCollector.h.
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 964 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 980 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 625 of file StatCollector.h.
|
inline |
Returns the arithmetic average of the weights.
std::range_error | if no entry was added |
Definition at line 723 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 999 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 1030 of file StatCollector.h.
|
inline |
Clears all the statistics.
Definition at line 989 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 1050 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 1071 of file StatCollector.h.
|
inline |
Returns the number of entries added.
Definition at line 637 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 1019 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 1060 of file StatCollector.h.
|
inline |
Returns the weighted sum of the square of the x values.
Definition at line 649 of file StatCollector.h.
|
inline |
Returns the weighted sum of the square of the y values.
Definition at line 652 of file StatCollector.h.
|
inline |
Returns the weighted sum of the x values.
Definition at line 643 of file StatCollector.h.
|
inline |
Returns the weighted sum of the product of x and y values.
Definition at line 655 of file StatCollector.h.
|
inline |
Returns the weighted sum of the y values.
Definition at line 646 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 1009 of file StatCollector.h.
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 1040 of file StatCollector.h.
|
inline |
Returns the sum of the weights.
Definition at line 640 of file StatCollector.h.
|
protected |
weighted sum of xy
Definition at line 732 of file StatCollector.h.
|
protected |
accumulator for variable x
Definition at line 730 of file StatCollector.h.
|
protected |
accumulator for variable y
Definition at line 731 of file StatCollector.h.