Public Types | Public Member Functions | Protected Types | Protected Attributes | List of all members
lar::util::StatCollector2D< T, W > Class Template Reference

Collects statistics on two homogeneous quantities (weighted) More...

#include <StatCollector.h>

Inheritance diagram for lar::util::StatCollector2D< T, W >:
lar::util::details::WeightTracker< W >

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...
 

Detailed Description

template<typename T, typename W = T>
class lar::util::StatCollector2D< T, W >

Collects statistics on two homogeneous quantities (weighted)


Template Parameters
Ttype of the quantities
Wtype of the weight (as T by default)

This is a convenience class, as easy to use as:

stat.add(3.0, 4.0, 2.0);
stat.add(4.0, 3.0, 2.0);
stat.add(5.0, 5.0, 1.0);
std::cout << "Statistics from " << stat.N() << " entries: "
<< stat.AverageX() << ", " << stat.AverageY() << std::endl;

or also

std::vector<std::pair<double, double>> values({
{ 3.0, 4.0, 2.0 },
{ 4.0, 3.0, 2.0 },
{ 5.0, 5.0, 1.0 },
});
stat.add_weighted(values.begin(), values.end());
std::cout << "Statistics from " << stat.N() << " entries: "
<< stat.AverageX() << ", " << stat.AverageY() << std::endl;

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.

Member Typedef Documentation

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Base_t = details::WeightTracker<W>

Definition at line 479 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Data_t = T

type of the data

Definition at line 483 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Pair_t = std::tuple<Data_t, Data_t>

Definition at line 486 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::This_t = StatCollector2D<T, W>

this type

Definition at line 482 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Variable_t = details::DataTracker2<Data_t, Weight_t>
protected

Definition at line 728 of file StatCollector.h.

template<typename T, typename W = T>
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.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::WeightedPair_t = std::tuple<Data_t, Data_t, Weight_t>

Definition at line 487 of file StatCollector.h.

Member Function Documentation

template<typename T , typename W >
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.

944 {
946  x.add(x_value, weight);
947  y.add(y_value, weight);
948  sum_xy += weight * x_value * y_value;
949 } // StatCollector2D<T, W>::add()
void add(Data_t v, Weight_t w)
Adds the specified weight to the statistics.
Weight_t sum_xy
weighted sum of xy
Variable_t x
accumulator for variable x
void add(Weight_t weight)
Adds the specified weight to the statistics.
Definition: StatCollector.h:53
weight
Definition: test.py:257
Variable_t y
accumulator for variable y
template<typename T, typename W = T>
void lar::util::StatCollector2D< T, W >::add ( Pair_t  value,
Weight_t  weight = Weight_t(1.0) 
)
inline

Definition at line 498 of file StatCollector.h.

499  { add(std::get<0>(value), std::get<1>(value), weight); }
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
weight
Definition: test.py:257
template<typename T, typename W = T>
void lar::util::StatCollector2D< T, W >::add ( WeightedPair_t  value)
inline

Definition at line 501 of file StatCollector.h.

502  { add(std::get<0>(value), std::get<1>(value), std::get<2>(value)); }
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
template<typename T, typename W = T>
template<typename Iter >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Iter  begin,
Iter  end 
)
inline

Adds entries from a sequence with weight 1.

Template Parameters
Iterforward iterator to the pairs to be added
Parameters
beginiterator pointing to the first element to be added
enditerator 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.

516  { add_unweighted(begin, end, identity()); }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void add_unweighted(Iter begin, Iter end)
Adds entries from a sequence with weight 1.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename T , typename W >
template<typename Iter , typename Pred >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Iter  begin,
Iter  end,
Pred  extractor 
)

Adds entries from a sequence with weight 1.

Template Parameters
Iterforward iterator to the elements to be added
Preda predicate to extract the element from iterator value
Parameters
beginiterator pointing to the first element to be added
enditerator pointing after the last element to be added
extractorthe predicate extracting the value to be inserted

The predicate is required to react to a call like with:

Pair_t Pred::operator() (typename Iter::value_type);

Definition at line 955 of file StatCollector.h.

956 {
957  std::for_each
958  (begin, end, [this, extractor](auto item) { this->add(extractor(item)); });
959 } // StatCollector2D<T, W>::add_unweighted(Iter, Iter, Pred)
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename T, typename W = T>
template<typename Cont , typename Pred >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Cont  cont,
Pred  extractor 
)
inline

Adds all entries from a container, with weight 1.

Template Parameters
Conttype of container of the elements to be added
Preda predicate to extract the element from iterator value
Parameters
contcontainer of the elements to be added
extractorthe predicate extracting the value to be inserted

The predicate is required to react to a call like with:

Pair_t Pred::operator() (typename Cont::value_type);

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.

550  { add_unweighted(std::begin(cont), std::end(cont), extractor); }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void add_unweighted(Iter begin, Iter end)
Adds entries from a sequence with weight 1.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename T, typename W = T>
template<typename Cont >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Cont  cont)
inline

Adds all entries from a container, with weight 1.

Template Parameters
Conttype of container of the elements to be added
Parameters
contcontainer 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.

563  { add_unweighted(std::begin(cont), std::end(cont)); }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void add_unweighted(Iter begin, Iter end)
Adds entries from a sequence with weight 1.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename T , typename W >
template<typename VIter , typename WIter , typename VPred , typename WPred >
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.

Template Parameters
VIterforward iterator to the elements to be added
WIterforward iterator to the weights
VPreda predicate to extract the element from iterator value
WPreda predicate to extract the weight from iterator value
Parameters
begin_valueiterator pointing to the first element to be added
end_valueiterator pointing after the last element to be added
begin_weightiterator pointing to the weight of first element
value_extractorpredicate extracting the value to be inserted
weight_extractorpredicate 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:

Pair_t VPred::operator() (typename VIter::value_type);
Weight_t WPred::operator() (typename WIter::value_type);

Definition at line 964 of file StatCollector.h.

969  {
970  while (begin_value != end_value) {
971  add(value_extractor(*begin_value), weight_extractor(*begin_weight));
972  ++begin_value;
973  ++begin_weight;
974  } // while
975 } // StatCollector2D<T, W>::add_weighted(VIter, VIter, WIter, VPred, WPred)
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
template<typename T , typename W >
template<typename Iter >
void lar::util::StatCollector2D< T, W >::add_weighted ( Iter  begin,
Iter  end 
)

Adds entries from a sequence with individually specified weights.

Template Parameters
Iterforward iterator to WeightedPair_t elements to be added
Parameters
beginiterator pointing to the first element to be added
enditerator 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.

980  {
981 
982  std::for_each(begin, end, [this](auto p) { this->add(p); });
983 
984 } // StatCollector2D<T, W>::add_weighted(Iter, Iter)
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
p
Definition: test.py:223
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename T, typename W = T>
template<typename Cont >
void lar::util::StatCollector2D< T, W >::add_weighted ( Cont  cont)
inline

Adds entries from a sequence with individually specified weights.

Template Parameters
Conttype of container of WeightedPair_t elements to be added
Parameters
contcontainer 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.

626  { add_weighted(std::begin(cont), std::end(cont)); }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::AverageWeight ( ) const
inline

Returns the arithmetic average of the weights.

Returns
the weight average
Exceptions
std::range_errorif no entry was added

Definition at line 723 of file StatCollector.h.

723 { return Base_t::AverageWeight(); }
Weight_t AverageWeight() const
Returns the arithmetic average of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::AverageX ( ) const

Returns the x value average.

Returns
the x value average
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 999 of file StatCollector.h.

1000 {
1001  if (Weights() == Weight_t(0))
1002  throw std::range_error("StatCollector2D<>::AverageX(): divide by 0");
1003  return SumX() / Weights();
1004 } // StatCollector2D<T, W>::AverageX()
Weight_t SumX() const
Returns the weighted sum of the x values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::AverageY ( ) const

Returns the y value average.

Returns
the y value average
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 1030 of file StatCollector.h.

1031 {
1032  if (Weights() == Weight_t(0))
1033  throw std::range_error("StatCollector2D<>::AverageY(): divide by 0");
1034  return SumY() / Weights();
1035 } // StatCollector2D<T, W>::AverageY()
Weight_t SumY() const
Returns the weighted sum of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
void lar::util::StatCollector2D< T, W >::clear ( )
inline

Clears all the statistics.

Definition at line 989 of file StatCollector.h.

989  {
990  Base_t::clear();
991  x.clear();
992  y.clear();
993  sum_xy = Weight_t(0);
994 } // StatCollector<T, W>::clear()
Weight_t sum_xy
weighted sum of xy
Variable_t x
accumulator for variable x
Variable_t y
accumulator for variable y
void clear()
Resets the count.
Definition: StatCollector.h:56
void clear()
Resets the count.
typename Base_t::Weight_t Weight_t
type of the weight
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::Covariance ( ) const

Returns the covariance of the (x, y) pair.

Returns
the square of the RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 1050 of file StatCollector.h.

1051 {
1052  if (Weights() == Weight_t(0))
1053  throw std::range_error("StatCollector2D<>::Covariance(): divide by 0");
1054  return (SumXY() - SumX() * SumY() / Weights()) / Weights();
1055 } // StatCollector2D<T, W>::VarianceY()
Weight_t SumXY() const
Returns the weighted sum of the product of x and y values.
Weight_t SumX() const
Returns the weighted sum of the x values.
Weight_t SumY() const
Returns the weighted sum of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::LinearCorrelation ( ) const

Returns the linear correlation.

Returns
the linear correlation RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (see Covariance())
std::range_errorif any variance is non-positive

Definition at line 1071 of file StatCollector.h.

1072 {
1073  if (Weights() == Data_t(0))
1074  throw std::range_error("StatCollector2D<>::LinearCorrelation(): divide by 0");
1075 
1076  const Weight_t var_prod = VarianceX() * VarianceY();
1077  if (var_prod <= Weight_t(0))
1078  throw std::range_error("StatCollector2D<>::LinearCorrelation(): variance is 0");
1079 
1080  return Covariance() / std::sqrt(var_prod);
1081 } // StatCollector2D<T, W>::LinearCorrelation()
Weight_t Covariance() const
Returns the covariance of the (x, y) pair.
Weight_t VarianceY() const
Returns the variance of the y values.
T Data_t
type of the data
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
Weight_t VarianceX() const
Returns the variance of the x values.
template<typename T, typename W = T>
int lar::util::StatCollector2D< T, W >::N ( void  ) const
inline

Returns the number of entries added.

Definition at line 637 of file StatCollector.h.

637 { return Base_t::N(); }
int N() const
Returns the number of entries added.
Definition: StatCollector.h:59
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::RMSx ( ) const

Returns the standard deviation of the x sample.

Returns
the RMS of the x values
Exceptions
std::range_errorif the total weight is 0 (see VarianceX())
std::range_errorif VarianceX() is negative (due to rounding errors)

Definition at line 1019 of file StatCollector.h.

1020 {
1021  const Weight_t rms2 = VarianceX();
1022  if (rms2 < Weight_t(0)) return 0.;
1023 // throw std::range_error("StatCollector2D<>::RMSx(): negative RMS^2");
1024  return std::sqrt(rms2);
1025 } // StatCollector2D<T, W>::RMSx()
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t VarianceX() const
Returns the variance of the x values.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::RMSy ( ) const

Returns the standard deviation of the y sample.

Returns
the RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (see VarianceY())
std::range_errorif VarianceY() is negative (due to rounding errors)

Definition at line 1060 of file StatCollector.h.

1061 {
1062  const Weight_t rms2 = VarianceY();
1063  if (rms2 < Weight_t(0)) return 0.;
1064 // throw std::range_error("StatCollector2D<>::RMSy(): negative RMS^2");
1065  return std::sqrt(rms2);
1066 } // StatCollector2D<T, W>::RMSy()
Weight_t VarianceY() const
Returns the variance of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumSqX ( ) const
inline

Returns the weighted sum of the square of the x values.

Definition at line 649 of file StatCollector.h.

649 { return x.SumSq(); }
Weight_t SumSq() const
Returns the weighted sum of the square of the entries.
Variable_t x
accumulator for variable x
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumSqY ( ) const
inline

Returns the weighted sum of the square of the y values.

Definition at line 652 of file StatCollector.h.

652 { return y.SumSq(); }
Weight_t SumSq() const
Returns the weighted sum of the square of the entries.
Variable_t y
accumulator for variable y
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumX ( ) const
inline

Returns the weighted sum of the x values.

Definition at line 643 of file StatCollector.h.

643 { return x.Sum(); }
Variable_t x
accumulator for variable x
Weight_t Sum(unsigned int n) const
Returns the sum of the values to the power n (1 <= n <= 2, no check)
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumXY ( ) const
inline

Returns the weighted sum of the product of x and y values.

Definition at line 655 of file StatCollector.h.

655 { return sum_xy; }
Weight_t sum_xy
weighted sum of xy
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumY ( ) const
inline

Returns the weighted sum of the y values.

Definition at line 646 of file StatCollector.h.

646 { return y.Sum(); }
Variable_t y
accumulator for variable y
Weight_t Sum(unsigned int n) const
Returns the sum of the values to the power n (1 <= n <= 2, no check)
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::VarianceX ( ) const

Returns the variance of the x values.

Returns
the square of the RMS of the x values
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 1009 of file StatCollector.h.

1010 {
1011  if (Weights() == Weight_t(0))
1012  throw std::range_error("StatCollector2D<>::VarianceX(): divide by 0");
1013  return (SumSqX() - sqr(SumX()) / Weights()) / Weights();
1014 } // StatCollector2D<T, W>::VarianceX()
static constexpr V sqr(V const &v)
Returns the square of the specified value.
Definition: StatCollector.h:74
Weight_t SumSqX() const
Returns the weighted sum of the square of the x values.
Weight_t SumX() const
Returns the weighted sum of the x values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::VarianceY ( ) const

Returns the variance of the y values.

Returns
the square of the RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 1040 of file StatCollector.h.

1041 {
1042  if (Weights() == Weight_t(0))
1043  throw std::range_error("StatCollector2D<>::VarianceY(): divide by 0");
1044  return (SumSqY() - sqr(SumY()) / Weights()) / Weights();
1045 } // StatCollector2D<T, W>::VarianceY()
Weight_t SumSqY() const
Returns the weighted sum of the square of the y values.
static constexpr V sqr(V const &v)
Returns the square of the specified value.
Definition: StatCollector.h:74
Weight_t SumY() const
Returns the weighted sum of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::Weights ( ) const
inline

Returns the sum of the weights.

Definition at line 640 of file StatCollector.h.

640 { return Base_t::Weights(); }
Weight_t Weights() const
Returns the sum of the weights.
Definition: StatCollector.h:62

Member Data Documentation

template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::sum_xy = Weight_t(0)
protected

weighted sum of xy

Definition at line 732 of file StatCollector.h.

template<typename T, typename W = T>
Variable_t lar::util::StatCollector2D< T, W >::x
protected

accumulator for variable x

Definition at line 730 of file StatCollector.h.

template<typename T, typename W = T>
Variable_t lar::util::StatCollector2D< T, W >::y
protected

accumulator for variable y

Definition at line 731 of file StatCollector.h.


The documentation for this class was generated from the following file: