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)
 Assignment operator.
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 26 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 77 of file Stats_T.h.

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

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


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 116 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().

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

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

Access the maximum value.

: return qNaN with no data.

Definition at line 231 of file Stats_T.h.

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

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

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

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

Calculate the average value.

: return qNaN with no data.

Definition at line 190 of file Stats_T.h.

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

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

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

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

Access the minimum value.

: return qNaN with no data.

Definition at line 222 of file Stats_T.h.

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

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

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

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

Access the number of values accumulated.

Definition at line 240 of file Stats_T.h.

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

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

00241 {
00242   return this->n_;
00243 }

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

Assignment operator.

Definition at line 87 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_.

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

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

Reset statistics to nil.

Definition at line 102 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().

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

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

Calculate the variance value.

Definition at line 214 of file Stats_T.h.

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

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

00215 {
00216   return this->variance_ ;
00217 }


Member Data Documentation

template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::an_ [private]

Definition at line 69 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().

template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::bn_ [private]

Definition at line 70 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::mean(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().

template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::cn_ [private]

Definition at line 71 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().

template<typename DataType>
DataType OpenDDS::DCPS::Stats< DataType >::maximum_ [private]

Definition at line 66 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::maximum(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().

template<typename DataType>
DataType OpenDDS::DCPS::Stats< DataType >::minimum_ [private]

Definition at line 65 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::minimum(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().

template<typename DataType>
unsigned long OpenDDS::DCPS::Stats< DataType >::n_ [private]

Definition at line 64 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::mean(), OpenDDS::DCPS::Stats< DataType >::n(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().

template<typename DataType>
long double OpenDDS::DCPS::Stats< DataType >::variance_ [private]

Definition at line 72 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::operator=(), OpenDDS::DCPS::Stats< DataType >::reset(), and OpenDDS::DCPS::Stats< DataType >::var().


The documentation for this class was generated from the following file:
Generated on Fri Feb 12 20:06:25 2016 for OpenDDS by  doxygen 1.4.7