Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CkSampleT< real, ret > Class Template Reference

CkSampleT represents a statistical "sample" of some data values. More...

#include <ckstatistics.h>

Public Member Functions

 CkSampleT (void)
 
void add (real r)
 Add this value to the sample set. More...
 
void operator+= (real r)
 Shorthand for add function. More...
 
ret getMean (void) const
 Return the mean value of this sample–the "average" value, in (value) units. More...
 
ret getVariance (void) const
 Return the variance of this sample, in (value^2) units. More...
 
ret getStddev (void) const
 Return the standard deviation of this sample, in (value) units. More...
 
real getMin (void) const
 Return the smallest value encountered. More...
 
real getMax (void) const
 Return the largest value encountered. More...
 
int getCount (void) const
 Return the number of values in this sample. More...
 
void print (FILE *dest)
 Print a textual description of this sample to this FILE. More...
 
void printMinAveMax (FILE *dest)
 Print a terse textual description of this sample to this FILE. More...
 
void print (void)
 Print a textual description of this sample to stdout. More...
 

Private Attributes

real lo
 
real hi
 
ret sum
 
ret sq
 
int n
 

Detailed Description

template<class real, class ret>
class CkSampleT< real, ret >

CkSampleT represents a statistical "sample" of some data values.

It maintains information it can use to compute means and variances, max and min.

The REAL template parameter is the datatype of the values. The RET template parameter is the datatype of the various accumulators used, and the datatype for the derived parameters.

The CkSample typedef is just CkSampleT<double,double> Other sensible specializations might include CkSampleT<double, long double> for higher precision accumulation, or CkSampleT<int, double> for computing continuous statistics of a discrete distribution.

Definition at line 79 of file ckstatistics.h.

Constructor & Destructor Documentation

CkSampleT ( void  )
inline

Definition at line 85 of file ckstatistics.h.

References CkSampleT< real, ret >::hi, CkSampleT< real, ret >::lo, CkSampleT< real, ret >::n, CkSampleT< real, ret >::sq, and CkSampleT< real, ret >::sum.

85  {
86  lo=(real)1.0e20; hi=(real)-1.0e20;
87  sum=sq=(ret)0;
88  n=0;
89  }
float real
Definition: gridutil.h:70

Member Function Documentation

void add ( real  r)
inline

Add this value to the sample set.

This function updates the max, min, and mean and variance for this sample.

Definition at line 95 of file ckstatistics.h.

References CkSampleT< real, ret >::hi, CkSampleT< real, ret >::lo, CkSampleT< real, ret >::n, CkSampleT< real, ret >::sq, and CkSampleT< real, ret >::sum.

Referenced by checkQuality(), and CkSampleT< real, ret >::operator+=().

95  {
96  if (r<lo) lo=r;
97  if (r>hi) hi=r;
98  sum+=(ret)r;
99  sq+=(ret)(r*r);
100  n++;
101  }

Here is the caller graph for this function:

int getCount ( void  ) const
inline

Return the number of values in this sample.

Definition at line 138 of file ckstatistics.h.

References CkSampleT< real, ret >::n.

Referenced by CkSampleT< real, ret >::print().

138 {return n;}

Here is the caller graph for this function:

real getMax ( void  ) const
inline

Return the largest value encountered.

Definition at line 134 of file ckstatistics.h.

References CkSampleT< real, ret >::hi.

Referenced by CkSampleT< real, ret >::print(), and CkSampleT< real, ret >::printMinAveMax().

134 {return hi;}

Here is the caller graph for this function:

ret getMean ( void  ) const
inline

Return the mean value of this sample–the "average" value, in (value) units.

Computed as the sum of all values divided by the number of values.

Definition at line 109 of file ckstatistics.h.

References CkSampleT< real, ret >::n, and CkSampleT< real, ret >::sum.

Referenced by CkSampleT< real, ret >::print(), and CkSampleT< real, ret >::printMinAveMax().

109  {
110  return sum/n;
111  }

Here is the caller graph for this function:

real getMin ( void  ) const
inline

Return the smallest value encountered.

Definition at line 130 of file ckstatistics.h.

References CkSampleT< real, ret >::lo.

Referenced by CkSampleT< real, ret >::print(), and CkSampleT< real, ret >::printMinAveMax().

130 {return lo;}

Here is the caller graph for this function:

ret getStddev ( void  ) const
inline

Return the standard deviation of this sample, in (value) units.

Computed as the square root of the variance.

Definition at line 124 of file ckstatistics.h.

References CkSampleT< real, ret >::getVariance(), and sqrt().

Referenced by CkSampleT< real, ret >::print().

124  {
125  return (ret)sqrt(getVariance());
126  }
double sqrt(double d)
Definition: double.h:73
ret getVariance(void) const
Return the variance of this sample, in (value^2) units.
Definition: ckstatistics.h:117

Here is the call graph for this function:

Here is the caller graph for this function:

ret getVariance ( void  ) const
inline

Return the variance of this sample, in (value^2) units.

Computed as the sum of the squares of the diffences between each value and the mean, divided by the number of values minus 1.

Definition at line 117 of file ckstatistics.h.

References CkSampleT< real, ret >::n, CkSampleT< real, ret >::sq, and CkSampleT< real, ret >::sum.

Referenced by CkSampleT< real, ret >::getStddev().

117  {
118  return (sq-sum*sum/n)/(n-1);
119  }

Here is the caller graph for this function:

void operator+= ( real  r)
inline

Shorthand for add function.

Definition at line 103 of file ckstatistics.h.

References CkSampleT< real, ret >::add().

103 { add(r); }
void add(real r)
Add this value to the sample set.
Definition: ckstatistics.h:95

Here is the call graph for this function:

void print ( FILE *  dest)
inline

Print a textual description of this sample to this FILE.

For example, a 1,000,000-value sample of a uniform distribution on [0,1] might give: ave= 0.500367 stddev= 0.288663 min= 1.27012e-06 max= 0.999999 n= 1000000

Definition at line 145 of file ckstatistics.h.

References CkSampleT< real, ret >::getCount(), CkSampleT< real, ret >::getMax(), CkSampleT< real, ret >::getMean(), CkSampleT< real, ret >::getMin(), and CkSampleT< real, ret >::getStddev().

145  {
146  fprintf(dest,"ave= %g stddev= %g min= %g max= %g n= %d\n",
147  (double)getMean(), (double)getStddev(), (double)getMin(), (double)getMax(), (int)getCount());
148  }
ret getStddev(void) const
Return the standard deviation of this sample, in (value) units.
Definition: ckstatistics.h:124
real getMin(void) const
Return the smallest value encountered.
Definition: ckstatistics.h:130
real getMax(void) const
Return the largest value encountered.
Definition: ckstatistics.h:134
ret getMean(void) const
Return the mean value of this sample–the &quot;average&quot; value, in (value) units.
Definition: ckstatistics.h:109
int getCount(void) const
Return the number of values in this sample.
Definition: ckstatistics.h:138

Here is the call graph for this function:

void print ( void  )
inline

Print a textual description of this sample to stdout.

Definition at line 161 of file ckstatistics.h.

References CkSampleT< real, ret >::print().

Referenced by CkSampleT< real, ret >::print().

161 {print(stdout);}
void print(void)
Print a textual description of this sample to stdout.
Definition: ckstatistics.h:161

Here is the call graph for this function:

Here is the caller graph for this function:

void printMinAveMax ( FILE *  dest)
inline

Print a terse textual description of this sample to this FILE.

Definition at line 153 of file ckstatistics.h.

References CkSampleT< real, ret >::getMax(), CkSampleT< real, ret >::getMean(), and CkSampleT< real, ret >::getMin().

Referenced by checkQuality().

153  {
154  fprintf(dest,"min= %g ave= %g max= %g \n",
155  (double)getMin(), (double)getMean(), (double)getMax());
156  }
real getMin(void) const
Return the smallest value encountered.
Definition: ckstatistics.h:130
real getMax(void) const
Return the largest value encountered.
Definition: ckstatistics.h:134
ret getMean(void) const
Return the mean value of this sample–the &quot;average&quot; value, in (value) units.
Definition: ckstatistics.h:109

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation


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