OpenDDS::DCPS::Stats< DataType > Class Template Reference

Accumulates average, n, variance, minimum, and maximum statistics. More...

#include <Stats_T.h>

Inheritance diagram for OpenDDS::DCPS::Stats< DataType >:
Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::Stats< DataType >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Stats (unsigned int amount=0, typename DataCollector< DataType >::OnFull type=DataCollector< DataType >::KeepOldest)
 Default constructor.
Statsoperator= (const Stats &rhs)
 Default bitwise copy is sufficient.
void reset ()
 Reset statistics to nil.
void add (DataType value)
long double mean () const
 Calculate the average value.
long double var () const
 Calculate the variance value.
DataType minimum () const
 Access the minimum value.
DataType maximum () const
 Access the maximum value.
unsigned long n () const
 Access the number of values accumulated.

Private Attributes

unsigned long n_
DataType minimum_
DataType maximum_
long double an_
long double bn_
long double cn_
long double variance_

Detailed Description

template<typename DataType>
class OpenDDS::DCPS::Stats< DataType >

Accumulates average, n, variance, minimum, and maximum statistics.

Definition at line 28 of file Stats_T.h.


Constructor & Destructor Documentation

template<typename DataType>
OpenDDS::DCPS::Stats< DataType >::Stats ( unsigned int  amount = 0,
typename DataCollector< DataType >::OnFull  type = DataCollector<DataType>::KeepOldest 
) [inline]

Default constructor.

Definition at line 79 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::reset().

00081                                                : DataCollector<DataType>(amount, type)
00082 {
00083   this->reset();
00084 }

Here is the call graph for this function:


Member Function Documentation

template<typename DataType>
void OpenDDS::DCPS::Stats< DataType >::add ( DataType  value  )  [inline]

Accumulate a new value.

Parameters:
value the new value to be accumulated.

Definition at line 118 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::an_, OpenDDS::DCPS::Stats< DataType >::bn_, OpenDDS::DCPS::Stats< DataType >::cn_, OpenDDS::DCPS::DataCollector< DataType >::collect(), OpenDDS::DCPS::Stats< DataType >::maximum_, OpenDDS::DCPS::Stats< DataType >::minimum_, OpenDDS::DCPS::Stats< DataType >::n_, and OpenDDS::DCPS::Stats< DataType >::variance_.

Referenced by OpenDDS::DCPS::WriterStats::add_stat().

00119 {
00120   // Save the raw value if configured to.
00121   this->collect(value);
00122 
00123   // Slide rule style calculations.
00124   long double term;
00125 
00126   //
00127   // V(N+1) = V(N) * N^2 / (N+1)^2
00128   //        + A(N)
00129   //        - B(N) * X(N+1)
00130   //        + C(N) * X(N+1)^2
00131   //
00132   this->variance_ /= (this->n_ + 1);
00133   this->variance_ *=  this->n_;
00134   this->variance_ /= (this->n_ + 1);
00135   this->variance_ *=  this->n_;
00136 
00137   term = static_cast<long double>(value);
00138   this->variance_ +=  this->an_;
00139   this->variance_ -=  this->bn_ * term;
00140   this->variance_ +=  this->cn_ * term * term;
00141 
00142   // The internal variable updates _must_ follow the variance update.
00143 
00144   //
00145   // A(N+1) = (A(N) * (N+1)^2 / (N+2)^2) + (X(N+1) / (N+2)^2)
00146   //
00147   this->an_ /= (this->n_ + 2);
00148   this->an_ *= (this->n_ + 1);
00149   this->an_ /= (this->n_ + 2);
00150   this->an_ *= (this->n_ + 1);
00151 
00152   // term = static_cast<long double>( value);
00153   term *= term;
00154   term /= (this->n_ + 2);
00155   term /= (this->n_ + 2);
00156   this->an_ += term;
00157 
00158   //
00159   // B(N+1) = (B(N) * (N+1)^2 / (N+2)^2) + (2 * X(N+1) / (N+2)^2)
00160   //
00161   this->bn_ /= (this->n_ + 2);
00162   this->bn_ *= (this->n_ + 1);
00163   this->bn_ /= (this->n_ + 2);
00164   this->bn_ *= (this->n_ + 1);
00165 
00166   term = static_cast<long double>(value * 2);
00167   term /= (this->n_ + 2);
00168   term /= (this->n_ + 2);
00169   this->bn_ += term;
00170 
00171   //
00172   // C(N+1) = (N+1) / (N+2)^2
00173   //
00174   this->cn_  =  this->n_ + 1;
00175   this->cn_ /= (this->n_ + 2);
00176   this->cn_ /= (this->n_ + 2);
00177 
00178   if ((this->n_ == 0) || (value < this->minimum_)) {
00179     this->minimum_ = value;
00180   }
00181 
00182   if ((this->n_ == 0) || (value > this->maximum_)) {
00183     this->maximum_ = value;
00184   }
00185 
00186   this->n_ += 1; // Must follow internal variable updates.
00187 }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename DataType >
DataType OpenDDS::DCPS::Stats< DataType >::maximum (  )  const [inline]

Access the maximum value.

: return qNaN with no data.

Definition at line 233 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::maximum_, and OpenDDS::DCPS::Stats< DataType >::n_.

Referenced by OpenDDS::DCPS::WriterStats::get_stats().

00234 {
00235   /// @TODO: return qNaN with no data.
00236   return (this->n_ == 0)? 0: this->maximum_;
00237 }

Here is the caller graph for this function:

template<typename DataType >
long double OpenDDS::DCPS::Stats< DataType >::mean (  )  const [inline]

Calculate the average value.

: return qNaN with no data.

Definition at line 192 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::bn_, and OpenDDS::DCPS::Stats< DataType >::n_.

Referenced by OpenDDS::DCPS::WriterStats::get_stats().

00193 {
00194   if (this->n_ == 0) {
00195     /// @TODO: return qNaN with no data.
00196     return 0.0;
00197   }
00198 
00199   // Slide rule style calculations.
00200 
00201   //
00202   // MEAN = B(N) * (N+1)^2 / (2 * N)
00203   //
00204   long double average = this->bn_ / 2.0 ;
00205 
00206   average *= (this->n_ + 1) ;
00207   average /=  this->n_ ;
00208   average *= (this->n_ + 1) ;
00209 
00210   return average ;
00211 }

Here is the caller graph for this function:

template<typename DataType >
DataType OpenDDS::DCPS::Stats< DataType >::minimum (  )  const [inline]

Access the minimum value.

: return qNaN with no data.

Definition at line 224 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::minimum_, and OpenDDS::DCPS::Stats< DataType >::n_.

Referenced by OpenDDS::DCPS::WriterStats::get_stats().

00225 {
00226   /// @TODO: return qNaN with no data.
00227   return (this->n_ == 0)? 0: this->minimum_;
00228 }

Here is the caller graph for this function:

template<typename DataType >
unsigned long OpenDDS::DCPS::Stats< DataType >::n (  )  const [inline]

Access the number of values accumulated.

Definition at line 242 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::n_.

Referenced by OpenDDS::DCPS::WriterStats::get_stats(), and OpenDDS::DCPS::WriterStats::raw_data().

00243 {
00244   return this->n_;
00245 }

Here is the caller graph for this function:

template<typename DataType >
Stats< DataType > & OpenDDS::DCPS::Stats< DataType >::operator= ( const Stats< DataType > &  rhs  )  [inline]

Default bitwise copy is sufficient.

Assignment operator

Definition at line 89 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::an_, OpenDDS::DCPS::Stats< DataType >::bn_, OpenDDS::DCPS::Stats< DataType >::cn_, OpenDDS::DCPS::Stats< DataType >::maximum_, OpenDDS::DCPS::Stats< DataType >::minimum_, OpenDDS::DCPS::Stats< DataType >::n_, and OpenDDS::DCPS::Stats< DataType >::variance_.

00090 {
00091   this->n_        = rhs.n_;
00092   this->minimum_  = rhs.minimum_;
00093   this->maximum_  = rhs.maximum_;
00094   this->an_       = rhs.an_ ;
00095   this->bn_       = rhs.bn_ ;
00096   this->cn_       = rhs.cn_ ;
00097   this->variance_ = rhs.variance_ ;
00098   return *this;
00099 }

template<typename DataType >
void OpenDDS::DCPS::Stats< DataType >::reset ( void   )  [inline]

Reset statistics to nil.

Definition at line 104 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::an_, OpenDDS::DCPS::Stats< DataType >::bn_, OpenDDS::DCPS::Stats< DataType >::cn_, OpenDDS::DCPS::Stats< DataType >::maximum_, OpenDDS::DCPS::Stats< DataType >::minimum_, OpenDDS::DCPS::Stats< DataType >::n_, and OpenDDS::DCPS::Stats< DataType >::variance_.

Referenced by OpenDDS::DCPS::WriterStats::reset_stats(), and OpenDDS::DCPS::Stats< DataType >::Stats().

00105 {
00106   this->n_        = 0;
00107   this->minimum_  = static_cast<DataType>(0);
00108   this->maximum_  = static_cast<DataType>(0);
00109   this->an_       = 0.0;
00110   this->bn_       = 0.0;
00111   this->cn_       = 0.0;
00112   this->variance_ = 0.0;
00113 }

Here is the caller graph for this function:

template<typename DataType >
long double OpenDDS::DCPS::Stats< DataType >::var (  )  const [inline]

Calculate the variance value.

Definition at line 216 of file Stats_T.h.

References OpenDDS::DCPS::Stats< DataType >::variance_.

Referenced by OpenDDS::DCPS::WriterStats::get_stats().

00217 {
00218   return this->variance_ ;
00219 }

Here is the caller graph for this function:


Member Data Documentation

template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::an_ [private]
template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::bn_ [private]
template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::cn_ [private]
template<typename DataType>
DataType OpenDDS::DCPS::Stats< DataType >::maximum_ [private]
template<typename DataType>
DataType OpenDDS::DCPS::Stats< DataType >::minimum_ [private]
template<typename DataType>
unsigned long OpenDDS::DCPS::Stats< DataType >::n_ [private]
template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::variance_ [private]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1