Public Member Functions | Protected Attributes | Friends | List of all members
gnsstk::Stats< T > Class Template Reference

Detailed Description

template<class T>
class gnsstk::Stats< T >

Conventional statistics for one sample, with scaling to improve numerical error in cases of very large numbers. Constructor does the same as Reset(); use it when starting a new series of input samples. Results are available at any time by calling N(), Minimum(), Maximum(), Average(), Variance() and StdDev(). Also the scale is available in Scale(). NB. Variance is normalized with 1/(N-1) and StdDev is sqrt(Variance). NB. This class is not intended to be used with non-floating types, for which it may yield incorrect results.

Definition at line 137 of file Stats.hpp.

#include <Stats.hpp>

Public Member Functions

void Add (const T &x)
 
void Add (const Vector< T > &X)
 Add gnsstk::Vector<T> of data to the statistics. More...
 
void Add (std::vector< T > &X)
 add a std::vector<T> of samples to the computation of statistics More...
 
std::string asShortString (std::string msg=std::string(), int w=0, int p=3) const
 Write Stats N,ave,sig to a short single-line string. More...
 
std::string asString (std::string msg=std::string(), int w=7, int p=4) const
 Write Stats to a single-line string. More...
 
Average (void) const
 return the average More...
 
void Dump (std::vector< unsigned int > &vuint, std::vector< T > &vT)
 
void Load (const std::vector< unsigned int > &vuint, const std::vector< T > &vT)
 
Maximum (void) const
 return maximum value More...
 
Minimum (void) const
 return minimum value More...
 
unsigned int N (void) const
 return the sample size More...
 
Stats< T > & operator+= (const Stats< T > &S)
 combine two Stats (assumed taken from the same or equivalent ensembles) More...
 
Stats< T > & operator-= (const Stats< T > &S)
 
void Reset (void)
 reset, i.e. ignore earlier data and restart sampling More...
 
Scale (void) const
 return the scale More...
 
 Stats ()
 constructor More...
 
StdDev (void) const
 return computed standard deviation More...
 
void Subtract (const T &x)
 
void Subtract (const Vector< T > &X)
 
void Subtract (std::vector< T > &X)
 
Variance (void) const
 return computed variance More...
 

Protected Attributes

max
 Maximum value. More...
 
min
 Minimum value. More...
 
unsigned int n
 number of samples added to the statistics More...
 
scale
 scale More...
 
bool setScale
 scale has been set to non-zero More...
 
sum
 sum of x More...
 
sum2
 sum of x squared More...
 

Friends

class TwoSampleStats< T >
 

Constructor & Destructor Documentation

◆ Stats()

template<class T >
gnsstk::Stats< T >::Stats ( )
inline

constructor

Definition at line 143 of file Stats.hpp.

Member Function Documentation

◆ Add() [1/3]

template<class T >
void gnsstk::Stats< T >::Add ( const T &  x)
inline

add a single sample to the computation of statistics NB this is the fundamental Add routine; all other Add's call this

Definition at line 158 of file Stats.hpp.

◆ Add() [2/3]

template<class T >
void gnsstk::Stats< T >::Add ( const Vector< T > &  X)
inline

Add gnsstk::Vector<T> of data to the statistics.

Definition at line 189 of file Stats.hpp.

◆ Add() [3/3]

template<class T >
void gnsstk::Stats< T >::Add ( std::vector< T > &  X)
inline

add a std::vector<T> of samples to the computation of statistics

Definition at line 195 of file Stats.hpp.

◆ asShortString()

template<class T >
std::string gnsstk::Stats< T >::asShortString ( std::string  msg = std::string(),
int  w = 0,
int  p = 3 
) const
inline

Write Stats N,ave,sig to a short single-line string.

Definition at line 306 of file Stats.hpp.

◆ asString()

template<class T >
std::string gnsstk::Stats< T >::asString ( std::string  msg = std::string(),
int  w = 7,
int  p = 4 
) const
inline

Write Stats to a single-line string.

Definition at line 290 of file Stats.hpp.

◆ Average()

template<class T >
T gnsstk::Stats< T >::Average ( void  ) const
inline

return the average

Definition at line 329 of file Stats.hpp.

◆ Dump()

template<class T >
void gnsstk::Stats< T >::Dump ( std::vector< unsigned int > &  vuint,
std::vector< T > &  vT 
)
inline

Dump Stats private members directly; useful in saving an object (e.g. to a file); reload with Load().

Parameters
vuintoutput vector<unsigned int> of length 2, input of Load()
vToutput vector<T> of length 5, input of Load()

Definition at line 252 of file Stats.hpp.

◆ Load()

template<class T >
void gnsstk::Stats< T >::Load ( const std::vector< unsigned int > &  vuint,
const std::vector< T > &  vT 
)
inline

Define Stats private members directly; useful in continuing with an object that was earlier saved (e.g. to a file) using Dump().

Parameters
vuintinput vector<unsigned int> of length 2, output of Dump()
vTinput vector<T> of length 5, output of Dump() NB no checking at all - caller has burden of validity NB zero-fill rather than throwing

Definition at line 269 of file Stats.hpp.

◆ Maximum()

template<class T >
T gnsstk::Stats< T >::Maximum ( void  ) const
inline

return maximum value

Definition at line 325 of file Stats.hpp.

◆ Minimum()

template<class T >
T gnsstk::Stats< T >::Minimum ( void  ) const
inline

return minimum value

Definition at line 321 of file Stats.hpp.

◆ N()

template<class T >
unsigned int gnsstk::Stats< T >::N ( void  ) const
inline

return the sample size

Definition at line 318 of file Stats.hpp.

◆ operator+=()

template<class T >
Stats<T>& gnsstk::Stats< T >::operator+= ( const Stats< T > &  S)
inline

combine two Stats (assumed taken from the same or equivalent ensembles)

Definition at line 219 of file Stats.hpp.

◆ operator-=()

template<class T >
Stats<T>& gnsstk::Stats< T >::operator-= ( const Stats< T > &  S)
inline

remove one Stats from another, assumed to be taken from the same or equivalent ensembles. NB. Assumes that these samples were previously added. NB. Minimum() and Maximum() may no longer be valid.

Definition at line 237 of file Stats.hpp.

◆ Reset()

template<class T >
void gnsstk::Stats< T >::Reset ( void  )
inline

reset, i.e. ignore earlier data and restart sampling

Definition at line 146 of file Stats.hpp.

◆ Scale()

template<class T >
T gnsstk::Stats< T >::Scale ( void  ) const
inline

return the scale

Definition at line 351 of file Stats.hpp.

◆ StdDev()

template<class T >
T gnsstk::Stats< T >::StdDev ( void  ) const
inline

return computed standard deviation

Definition at line 347 of file Stats.hpp.

◆ Subtract() [1/3]

template<class T >
void gnsstk::Stats< T >::Subtract ( const T &  x)
inline

remove a sample from the computation of statistics. NB this is the fundamental Subtract routine; all others call this NB. Assumes that this sample was previously added. NB. Minimum() and Maximum() may no longer be valid.

Definition at line 178 of file Stats.hpp.

◆ Subtract() [2/3]

template<class T >
void gnsstk::Stats< T >::Subtract ( const Vector< T > &  X)
inline

Subtract gnsstk::Vector<T> of data to the statistics NB. Assumes that these samples were previously added. NB. Minimum() and Maximum() may no longer be valid.

Definition at line 203 of file Stats.hpp.

◆ Subtract() [3/3]

template<class T >
void gnsstk::Stats< T >::Subtract ( std::vector< T > &  X)
inline

remove a std::vector<T> of samples to the computation of statistics NB. Assumes that these samples were previously added. NB. Minimum() and Maximum() may no longer be valid.

Definition at line 211 of file Stats.hpp.

◆ Variance()

template<class T >
T gnsstk::Stats< T >::Variance ( void  ) const
inline

return computed variance

Definition at line 338 of file Stats.hpp.

Friends And Related Function Documentation

◆ TwoSampleStats< T >

template<class T >
friend class TwoSampleStats< T >
friend

Definition at line 140 of file Stats.hpp.

Member Data Documentation

◆ max

template<class T >
T gnsstk::Stats< T >::max
protected

Maximum value.

Definition at line 359 of file Stats.hpp.

◆ min

template<class T >
T gnsstk::Stats< T >::min
protected

Minimum value.

Definition at line 358 of file Stats.hpp.

◆ n

template<class T >
unsigned int gnsstk::Stats< T >::n
protected

number of samples added to the statistics

Definition at line 355 of file Stats.hpp.

◆ scale

template<class T >
T gnsstk::Stats< T >::scale
protected

scale

Definition at line 357 of file Stats.hpp.

◆ setScale

template<class T >
bool gnsstk::Stats< T >::setScale
protected

scale has been set to non-zero

Definition at line 356 of file Stats.hpp.

◆ sum

template<class T >
T gnsstk::Stats< T >::sum
protected

sum of x

Definition at line 360 of file Stats.hpp.

◆ sum2

template<class T >
T gnsstk::Stats< T >::sum2
protected

sum of x squared

Definition at line 361 of file Stats.hpp.


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


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:46