Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches

Description

Author
Juan-Antonio Fernandez-Madrigal. http://jafma.net
Date
2019
Collaboration diagram for statistic:

Classes

class  elementa::math::stats::Statistic< Calc >
 A statistic, i.e., a numerical function of a sample of data. More...
 
class  elementa::math::stats::StaPol_BaseOnInc
 An incomplete base policy for Statistic that uses incCalc() to do calcs. More...
 
class  elementa::math::stats::StaPol_Min
 Policy for Statistic that calculates the minimum. More...
 
class  elementa::math::stats::StaPol_Max
 Policy for Statistic that calculates the maximum. More...
 
class  elementa::math::stats::StaPol_Mean
 Policy for Statistic that calculates the mean. More...
 
class  elementa::math::stats::StaPol_Var
 Policy for Statistic that calculates the variance. More...
 
class  elementa::math::stats::StaGroup_MinMax
 A group of statistics consisting of min and max. More...
 
class  elementa::math::stats::StaGroup_MeanVar
 A group of statistics consisting of mean and var. More...
 
class  elementa::math::stats::StaGroup_MinMaxMeanVar
 A group of statistics consisting of min, max, mean and var. More...
 

Functions

virtual StaDatum elementa::math::stats::StaPol_BaseOnInc::incCalc (StaDatum prev, StaDatum v, SampleSize n)=0
 
StaDatum elementa::math::stats::StaPol_Min::incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
StaDatum elementa::math::stats::StaPol_Max::incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
StaDatum elementa::math::stats::StaPol_Mean::incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
 elementa::math::stats::StaPol_Var::StaPol_Var (Statistic< StaPol_Mean > &meanstat)
 Construct the policy for using incremental calculations. More...
 
StaDatum elementa::math::stats::StaPol_Var::incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
 elementa::math::stats::Statistic< Calc >::Statistic (const Calc c)
 Constructor: a statistic not calculated ever. More...
 
void elementa::math::stats::Statistic< Calc >::reset (void)
 Set the statistic to the previous-to-calculated state. More...
 
bool elementa::math::stats::Statistic< Calc >::calculated (void) const noexcept
 Return whether the statistic has been calculated. More...
 
StaDatum elementa::math::stats::Statistic< Calc >::value (void) const
 Return its current calculated value, or throw if none. More...
 
SampleSize elementa::math::stats::Statistic< Calc >::domainSize (void) const noexcept
 Return the number of data that has produced the current value. More...
 
template<class TIt >
void elementa::math::stats::StaGroup_MinMax::calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on all members of the group at once. More...
 
void elementa::math::stats::StaGroup_MinMax::update (StaDatum v)
 Update statistic on all members of the group at once. More...
 
void elementa::math::stats::StaGroup_MinMax::reset (void)
 Reset all statistics. More...
 
template<class TIt >
void elementa::math::stats::StaGroup_MeanVar::calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on all members of the group at once. More...
 
void elementa::math::stats::StaGroup_MeanVar::update (StaDatum v)
 Update statistic on all members of the group at once. More...
 
void elementa::math::stats::StaGroup_MeanVar::reset (void)
 Reset all statistics. More...
 
template<class TIt >
void elementa::math::stats::StaGroup_MinMaxMeanVar::calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on all members of the group at once. More...
 
void elementa::math::stats::StaGroup_MinMaxMeanVar::update (StaDatum v)
 Update statistic on all members of the group at once. More...
 
void elementa::math::stats::StaGroup_MinMaxMeanVar::reset (void)
 Reset all statistics. More...
 

Variables

Statistic< StaPol_Minelementa::math::stats::StaGroup_MinMax::stamin {StaPol_Min{}}
 The min statistic. More...
 
Statistic< StaPol_Maxelementa::math::stats::StaGroup_MinMax::stamax {StaPol_Max{}}
 The max statistic. More...
 
Statistic< StaPol_Meanelementa::math::stats::StaGroup_MeanVar::stamean {StaPol_Mean{}}
 The mean statistic. More...
 
Statistic< StaPol_Varelementa::math::stats::StaGroup_MeanVar::stavar {StaPol_Var{stamean}}
 The var statistic. More...
 
Statistic< StaPol_Minelementa::math::stats::StaGroup_MinMaxMeanVar::stamin {StaPol_Min{}}
 The min statistic. More...
 
Statistic< StaPol_Maxelementa::math::stats::StaGroup_MinMaxMeanVar::stamax {StaPol_Max{}}
 The max statistic. More...
 
Statistic< StaPol_Meanelementa::math::stats::StaGroup_MinMaxMeanVar::stamean {StaPol_Mean{}}
 The mean statistic. More...
 
Statistic< StaPol_Varelementa::math::stats::StaGroup_MinMaxMeanVar::stavar {StaPol_Var{stamean}}
 The var statistic. More...
 
using elementa::math::stats::SampleSize = size_t
 The number of elements in a sample. More...
 
using elementa::math::stats::StaDatum = double
 Type of data to allow for statistic calculation. More...
 
template<class DatumIterator >
using elementa::math::stats::GetStaDatumFun = std::function< StaDatum(const DatumIterator &) >
 A function type that gets a datum from an iterator. More...
 
template<class DatumIterator >
constexpr StaDatum elementa::math::stats::getstadatum_direct (const DatumIterator &ti)
 A simple GetStaDatumFun that gets directly the datum from the iterator. More...
 
template<class TIt >
StaDatum elementa::math::stats::StaPol_BaseOnInc::calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 
template<class TIt >
StaDatum elementa::math::stats::StaPol_Mean::calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 
template<class TIt >
StaDatum elementa::math::stats::StaPol_Var::calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 
StaDatum elementa::math::stats::Statistic< Calc >::previous (void) const
 Return the value of the statistic previous to the current one. More...
 
template<class TIt >
StaDatum elementa::math::stats::Statistic< Calc >::calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on a sample and return its value. More...
 
StaDatum elementa::math::stats::Statistic< Calc >::update (StaDatum v)
 Calculate the statistic incrementally from its previous value. More...
 

Class Documentation

◆ elementa::math::stats::Statistic

class elementa::math::stats::Statistic
template<class Calc>
class elementa::math::stats::Statistic< Calc >

A statistic, i.e., a numerical function of a sample of data.

A statistic is calculated from a sample and, sometimes, can be calculated incrementally as the sample is collected.

Template Parameters
Calcis a policy to calculate the statistic. It must be copy constructible and have these methods:
template <class TIt>
StaDatum calc(const TIt & first, const TIt & pastend, SampleSize & n,
const GetStaDatum<TIt> & getdatum)
StaDatum incCalc(StaDatum prev, StaDatum v, SampleSize & n)
size_t SampleSize
The number of elements in a sample.
Definition: statistic.h:51
double StaDatum
Type of data to allow for statistic calculation.
Definition: statistic.h:54
where the first calculates the statistic on the entire sample given by the iterators (it will be guaranteed to be non-empty), fill n with the number of data and return the result, and the second calculates the new statistic from its previous value prev and the new datum v, knowing that the number of data so far (before this update) is n > 1.
Note
- It cannot have a base class for Statistic since there is a template method and that cannot be made virtual.

Definition at line 193 of file statistic.h.

Public Member Functions

 Statistic (const Calc c)
 Constructor: a statistic not calculated ever. More...
 
void reset (void)
 Set the statistic to the previous-to-calculated state. More...
 
bool calculated (void) const noexcept
 Return whether the statistic has been calculated. More...
 
StaDatum value (void) const
 Return its current calculated value, or throw if none. More...
 
SampleSize domainSize (void) const noexcept
 Return the number of data that has produced the current value. More...
 
StaDatum previous (void) const
 Return the value of the statistic previous to the current one. More...
 
template<class TIt >
StaDatum calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on a sample and return its value. More...
 
StaDatum update (StaDatum v)
 Calculate the statistic incrementally from its previous value. More...
 

◆ elementa::math::stats::StaPol_BaseOnInc

class elementa::math::stats::StaPol_BaseOnInc

An incomplete base policy for Statistic that uses incCalc() to do calcs.

Note
- It cannot have a base class for statistic policies since there is a template method and that cannot be made virtual.

Definition at line 81 of file statistic.h.

Inheritance diagram for elementa::math::stats::StaPol_BaseOnInc:

Public Member Functions

virtual StaDatum incCalc (StaDatum prev, StaDatum v, SampleSize n)=0
 
template<class TIt >
StaDatum calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 

◆ elementa::math::stats::StaPol_Min

class elementa::math::stats::StaPol_Min

Policy for Statistic that calculates the minimum.

Note
- It cannot have a base class for statistic policies since there is a template method and that cannot be made virtual.

Definition at line 97 of file statistic.h.

Inheritance diagram for elementa::math::stats::StaPol_Min:
Collaboration diagram for elementa::math::stats::StaPol_Min:

Public Member Functions

StaDatum incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
template<class TIt >
StaDatum calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 

◆ elementa::math::stats::StaPol_Max

class elementa::math::stats::StaPol_Max

Policy for Statistic that calculates the maximum.

Note
- It cannot have a base class for statistic policies since there is a template method and that cannot be made virtual.

Definition at line 109 of file statistic.h.

Inheritance diagram for elementa::math::stats::StaPol_Max:
Collaboration diagram for elementa::math::stats::StaPol_Max:

Public Member Functions

StaDatum incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
template<class TIt >
StaDatum calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 

◆ elementa::math::stats::StaPol_Mean

class elementa::math::stats::StaPol_Mean

Policy for Statistic that calculates the mean.

Note
- It cannot have a base class for statistic policies since there is a template method and that cannot be made virtual.

Definition at line 121 of file statistic.h.

Public Member Functions

StaDatum incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
template<class TIt >
StaDatum calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 

◆ elementa::math::stats::StaPol_Var

class elementa::math::stats::StaPol_Var

Policy for Statistic that calculates the variance.

This policy needs the existence of a Statistic with StaPol_Mean policy that is updated previously to using this one.

Note
- It cannot have a base class for statistic policies since there is a template method and that cannot be made virtual.

Definition at line 142 of file statistic.h.

Public Member Functions

 StaPol_Var (Statistic< StaPol_Mean > &meanstat)
 Construct the policy for using incremental calculations. More...
 
StaDatum incCalc (StaDatum prev, StaDatum v, SampleSize n)
 
template<class TIt >
StaDatum calc (const TIt &first, const TIt &pastend, SampleSize &n, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 

◆ elementa::math::stats::StaGroup_MinMax

class elementa::math::stats::StaGroup_MinMax

A group of statistics consisting of min and max.

Note
- It cannot have a base class for group of statistics since there is a template method and that cannot be made virtual.

Definition at line 251 of file statistic.h.

Collaboration diagram for elementa::math::stats::StaGroup_MinMax:

Public Attributes

Statistic< StaPol_Minstamin {StaPol_Min{}}
 The min statistic. More...
 
Statistic< StaPol_Maxstamax {StaPol_Max{}}
 The max statistic. More...
 

Public Member Functions

template<class TIt >
void calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on all members of the group at once. More...
 
void update (StaDatum v)
 Update statistic on all members of the group at once. More...
 
void reset (void)
 Reset all statistics. More...
 

◆ elementa::math::stats::StaGroup_MeanVar

class elementa::math::stats::StaGroup_MeanVar

A group of statistics consisting of mean and var.

Note
- It cannot have a base class for group of statistics since there is a template method and that cannot be made virtual.

Definition at line 277 of file statistic.h.

Collaboration diagram for elementa::math::stats::StaGroup_MeanVar:

Public Attributes

Statistic< StaPol_Meanstamean {StaPol_Mean{}}
 The mean statistic. More...
 
Statistic< StaPol_Varstavar {StaPol_Var{stamean}}
 The var statistic. More...
 

Public Member Functions

template<class TIt >
void calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on all members of the group at once. More...
 
void update (StaDatum v)
 Update statistic on all members of the group at once. More...
 
void reset (void)
 Reset all statistics. More...
 

◆ elementa::math::stats::StaGroup_MinMaxMeanVar

class elementa::math::stats::StaGroup_MinMaxMeanVar

A group of statistics consisting of min, max, mean and var.

Note
- It cannot have a base class for group of statistics since there is a template method and that cannot be made virtual.

Definition at line 303 of file statistic.h.

Collaboration diagram for elementa::math::stats::StaGroup_MinMaxMeanVar:

Public Attributes

Statistic< StaPol_Minstamin {StaPol_Min{}}
 The min statistic. More...
 
Statistic< StaPol_Maxstamax {StaPol_Max{}}
 The max statistic. More...
 
Statistic< StaPol_Meanstamean {StaPol_Mean{}}
 The mean statistic. More...
 
Statistic< StaPol_Varstavar {StaPol_Var{stamean}}
 The var statistic. More...
 

Public Member Functions

template<class TIt >
void calculate (const TIt &first, const TIt &pastend, const GetStaDatumFun< TIt > &getdatum=getstadatum_direct< TIt >)
 Calculate the statistic on all members of the group at once. More...
 
void update (StaDatum v)
 Update statistic on all members of the group at once. More...
 
void reset (void)
 Reset all statistics. More...
 

Typedef Documentation

◆ SampleSize

using elementa::math::stats::SampleSize = typedef size_t

#include <elementa/math/stats/statistic.h>

The number of elements in a sample.

Definition at line 51 of file statistic.h.

◆ StaDatum

using elementa::math::stats::StaDatum = typedef double

#include <elementa/math/stats/statistic.h>

Type of data to allow for statistic calculation.

Definition at line 54 of file statistic.h.

◆ GetStaDatumFun

template<class DatumIterator >
using elementa::math::stats::GetStaDatumFun = typedef std::function< StaDatum(const DatumIterator &) >

#include <elementa/math/stats/statistic.h>

A function type that gets a datum from an iterator.

Definition at line 58 of file statistic.h.

Function Documentation

◆ getstadatum_direct()

template<class DatumIterator >
constexpr StaDatum elementa::math::stats::getstadatum_direct ( const DatumIterator &  ti)
constexpr

#include <elementa/math/stats/statistic.h>

A simple GetStaDatumFun that gets directly the datum from the iterator.

Definition at line 62 of file statistic.h.

◆ calc() [1/3]

template<class TIt >
StaDatum elementa::math::stats::StaPol_BaseOnInc::calc ( const TIt &  first,
const TIt &  pastend,
SampleSize n,
const GetStaDatumFun< TIt > &  getdatum = getstadatum_direct<TIt> 
)

#include <elementa/math/stats/statistic.h>

Definition at line 397 of file statistic.h.

◆ incCalc() [1/3]

StaDatum elementa::math::stats::StaPol_Min::incCalc ( StaDatum  prev,
StaDatum  v,
SampleSize  n 
)
inlinevirtual

#include <elementa/math/stats/statistic.h>

Implements elementa::math::stats::StaPol_BaseOnInc.

Definition at line 101 of file statistic.h.

◆ incCalc() [2/3]

StaDatum elementa::math::stats::StaPol_Max::incCalc ( StaDatum  prev,
StaDatum  v,
SampleSize  n 
)
inlinevirtual

#include <elementa/math/stats/statistic.h>

Implements elementa::math::stats::StaPol_BaseOnInc.

Definition at line 113 of file statistic.h.

◆ calc() [2/3]

template<class TIt >
StaDatum elementa::math::stats::StaPol_Mean::calc ( const TIt &  first,
const TIt &  pastend,
SampleSize n,
const GetStaDatumFun< TIt > &  getdatum = getstadatum_direct<TIt> 
)

#include <elementa/math/stats/statistic.h>

Definition at line 422 of file statistic.h.

◆ incCalc() [3/3]

StaDatum elementa::math::stats::StaPol_Mean::incCalc ( StaDatum  prev,
StaDatum  v,
SampleSize  n 
)
inline

#include <elementa/math/stats/statistic.h>

Definition at line 130 of file statistic.h.

◆ StaPol_Var()

elementa::math::stats::StaPol_Var::StaPol_Var ( Statistic< StaPol_Mean > &  meanstat)
inline

#include <elementa/math/stats/statistic.h>

Construct the policy for using incremental calculations.

meanstat must outlive this object, since a reference to it is held.

Definition at line 148 of file statistic.h.

◆ calc() [3/3]

template<class TIt >
StaDatum elementa::math::stats::StaPol_Var::calc ( const TIt &  first,
const TIt &  pastend,
SampleSize n,
const GetStaDatumFun< TIt > &  getdatum = getstadatum_direct<TIt> 
)

#include <elementa/math/stats/statistic.h>

Definition at line 446 of file statistic.h.

◆ Statistic()

template<class Calc >
elementa::math::stats::Statistic< Calc >::Statistic ( const Calc  c)
inline

#include <elementa/math/stats/statistic.h>

Constructor: a statistic not calculated ever.

Definition at line 198 of file statistic.h.

References elementa::math::stats::Statistic< Calc >::reset().

◆ reset() [1/4]

template<class Calc >
void elementa::math::stats::Statistic< Calc >::reset ( void  )
inline

#include <elementa/math/stats/statistic.h>

Set the statistic to the previous-to-calculated state.

Definition at line 202 of file statistic.h.

Referenced by elementa::math::stats::Statistic< Calc >::Statistic().

◆ calculated()

template<class Calc >
bool elementa::math::stats::Statistic< Calc >::calculated ( void  ) const
inlinenoexcept

#include <elementa/math/stats/statistic.h>

Return whether the statistic has been calculated.

Definition at line 205 of file statistic.h.

◆ value()

template<class Calc >
StaDatum elementa::math::stats::Statistic< Calc >::value ( void  ) const
inline

#include <elementa/math/stats/statistic.h>

Return its current calculated value, or throw if none.

Definition at line 208 of file statistic.h.

◆ previous()

template<class Calc >
StaDatum elementa::math::stats::Statistic< Calc >::previous ( void  ) const

#include <elementa/math/stats/statistic.h>

Return the value of the statistic previous to the current one.

Only has meaning if the statistic is being calculated incrementally. Throw if none.

Definition at line 349 of file statistic.h.

References ELE_CODE_INVSTATE.

◆ domainSize()

template<class Calc >
SampleSize elementa::math::stats::Statistic< Calc >::domainSize ( void  ) const
inlinenoexcept

#include <elementa/math/stats/statistic.h>

Return the number of data that has produced the current value.

If it is not calculated, return 0.

Definition at line 217 of file statistic.h.

◆ calculate() [1/4]

template<class Calc >
template<class TIt >
StaDatum elementa::math::stats::Statistic< Calc >::calculate ( const TIt &  first,
const TIt &  pastend,
const GetStaDatumFun< TIt > &  getdatum = getstadatum_direct<TIt> 
)

#include <elementa/math/stats/statistic.h>

Calculate the statistic on a sample and return its value.

Definition at line 358 of file statistic.h.

References ELE_CODE_INVARG.

◆ update() [1/4]

template<class Calc >
StaDatum elementa::math::stats::Statistic< Calc >::update ( StaDatum  v)

#include <elementa/math/stats/statistic.h>

Calculate the statistic incrementally from its previous value.

In the first call, return v.

Definition at line 370 of file statistic.h.

References ELE_CODE_INVSTATE.

◆ calculate() [2/4]

template<class TIt >
void elementa::math::stats::StaGroup_MinMax::calculate ( const TIt &  first,
const TIt &  pastend,
const GetStaDatumFun< TIt > &  getdatum = getstadatum_direct<TIt> 
)
inline

#include <elementa/math/stats/statistic.h>

Calculate the statistic on all members of the group at once.

Definition at line 260 of file statistic.h.

References elementa::math::stats::StaGroup_MinMax::stamax, and elementa::math::stats::StaGroup_MinMax::stamin.

◆ update() [2/4]

void elementa::math::stats::StaGroup_MinMax::update ( StaDatum  v)
inline

#include <elementa/math/stats/statistic.h>

Update statistic on all members of the group at once.

Definition at line 267 of file statistic.h.

References elementa::math::stats::StaGroup_MinMax::stamax, and elementa::math::stats::StaGroup_MinMax::stamin.

◆ reset() [2/4]

void elementa::math::stats::StaGroup_MinMax::reset ( void  )
inline

◆ calculate() [3/4]

template<class TIt >
void elementa::math::stats::StaGroup_MeanVar::calculate ( const TIt &  first,
const TIt &  pastend,
const GetStaDatumFun< TIt > &  getdatum = getstadatum_direct<TIt> 
)
inline

#include <elementa/math/stats/statistic.h>

Calculate the statistic on all members of the group at once.

Definition at line 286 of file statistic.h.

References elementa::math::stats::StaGroup_MeanVar::stamean, and elementa::math::stats::StaGroup_MeanVar::stavar.

◆ update() [3/4]

void elementa::math::stats::StaGroup_MeanVar::update ( StaDatum  v)
inline

#include <elementa/math/stats/statistic.h>

Update statistic on all members of the group at once.

Definition at line 293 of file statistic.h.

References elementa::math::stats::StaGroup_MeanVar::stamean, and elementa::math::stats::StaGroup_MeanVar::stavar.

◆ reset() [3/4]

void elementa::math::stats::StaGroup_MeanVar::reset ( void  )
inline

◆ calculate() [4/4]

template<class TIt >
void elementa::math::stats::StaGroup_MinMaxMeanVar::calculate ( const TIt &  first,
const TIt &  pastend,
const GetStaDatumFun< TIt > &  getdatum = getstadatum_direct<TIt> 
)
inline

◆ update() [4/4]

void elementa::math::stats::StaGroup_MinMaxMeanVar::update ( StaDatum  v)
inline

◆ reset() [4/4]

Variable Documentation

◆ stamin [1/2]

Statistic<StaPol_Min> elementa::math::stats::StaGroup_MinMax::stamin {StaPol_Min{}}

◆ stamax [1/2]

Statistic<StaPol_Max> elementa::math::stats::StaGroup_MinMax::stamax {StaPol_Max{}}

◆ stamean [1/2]

Statistic<StaPol_Mean> elementa::math::stats::StaGroup_MeanVar::stamean {StaPol_Mean{}}

◆ stavar [1/2]

◆ stamin [2/2]

◆ stamax [2/2]

◆ stamean [2/2]

◆ stavar [2/2]