Accumulates average, n, variance, minimum, and maximum statistics. More...
#include <Stats_T.h>
Public Member Functions | |
Stats (unsigned int amount=0, typename DataCollector< DataType >::OnFull type=DataCollector< DataType >::KeepOldest) | |
Default constructor. | |
Stats & | operator= (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_ |
Accumulates average, n, variance, minimum, and maximum statistics.
Definition at line 28 of file Stats_T.h.
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 }
void OpenDDS::DCPS::Stats< DataType >::add | ( | DataType | value | ) | [inline] |
Accumulate a new value.
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 }
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 }
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 }
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 }
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 }
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_.
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 }
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 }
long double OpenDDS::DCPS::Stats< DataType >::an_ [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().
long double OpenDDS::DCPS::Stats< DataType >::bn_ [private] |
Definition at line 72 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().
long double OpenDDS::DCPS::Stats< DataType >::cn_ [private] |
Definition at line 73 of file Stats_T.h.
Referenced by OpenDDS::DCPS::Stats< DataType >::add(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().
DataType OpenDDS::DCPS::Stats< DataType >::maximum_ [private] |
Definition at line 68 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().
DataType OpenDDS::DCPS::Stats< DataType >::minimum_ [private] |
Definition at line 67 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().
unsigned long OpenDDS::DCPS::Stats< DataType >::n_ [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 >::mean(), OpenDDS::DCPS::Stats< DataType >::minimum(), OpenDDS::DCPS::Stats< DataType >::n(), OpenDDS::DCPS::Stats< DataType >::operator=(), and OpenDDS::DCPS::Stats< DataType >::reset().
long double OpenDDS::DCPS::Stats< DataType >::variance_ [private] |
Definition at line 74 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().