OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Private Attributes | List of all members
OpenDDS::DCPS::Stats< DataType > Class Template Reference

#include <Stats_T.h>

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

Public Member Functions

 Stats (unsigned int amount=0, typename DataCollector< DataType >::OnFull type=DataCollector< DataType >::KeepOldest)
 Default constructor. More...
 
 Stats (const Stats &)
 
Statsoperator= (const Stats &rhs)
 Default bitwise copy is sufficient. More...
 
void reset ()
 Reset statistics to nil. More...
 
void add (DataType value)
 
long double mean () const
 Calculate the average value. More...
 
long double var () const
 Calculate the variance value. More...
 
DataType minimum () const
 Access the minimum value. More...
 
DataType maximum () const
 Access the maximum value. More...
 
unsigned long n () const
 Access the number of values accumulated. More...
 
- Public Member Functions inherited from OpenDDS::DCPS::DataCollector< DataType >
 DataCollector (unsigned int bound=0, OnFull onFull=KeepOldest)
 
virtual ~DataCollector ()
 Allow the class to be extended. More...
 
void collect (const DataType &datum)
 Implement data collection. More...
 
unsigned int size () const
 Amount of data actually stored. More...
 
DataCollector< DataType > & operator<< (DataType datum)
 
std::ostreaminsert (std::ostream &str) const
 Implement insertion of collected data onto an ostream. More...
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from OpenDDS::DCPS::DataCollector< DataType >
enum  OnFull
 Selectors for behavior when buffer fills. More...
 

Detailed Description

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

Definition at line 28 of file Stats_T.h.

Constructor & Destructor Documentation

◆ Stats() [1/2]

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 81 of file Stats_T.h.

83  : DataCollector<DataType>(amount, type)
84 {
85  this->reset();
86 }
void reset()
Reset statistics to nil.
Definition: Stats_T.h:119

◆ Stats() [2/2]

template<typename DataType>
OpenDDS::DCPS::Stats< DataType >::Stats ( const Stats< DataType > &  )

Member Function Documentation

◆ add()

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

Accumulate a new value.

Parameters
valuethe new value to be accumulated.

Definition at line 133 of file Stats_T.h.

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

134 {
135  // Save the raw value if configured to.
136  this->collect(value);
137 
138  // Slide rule style calculations.
139  long double term;
140 
141  //
142  // V(N+1) = V(N) * N^2 / (N+1)^2
143  // + A(N)
144  // - B(N) * X(N+1)
145  // + C(N) * X(N+1)^2
146  //
147  this->variance_ /= (this->n_ + 1);
148  this->variance_ *= this->n_;
149  this->variance_ /= (this->n_ + 1);
150  this->variance_ *= this->n_;
151 
152  term = static_cast<long double>(value);
153  this->variance_ += this->an_;
154  this->variance_ -= this->bn_ * term;
155  this->variance_ += this->cn_ * term * term;
156 
157  // The internal variable updates _must_ follow the variance update.
158 
159  //
160  // A(N+1) = (A(N) * (N+1)^2 / (N+2)^2) + (X(N+1) / (N+2)^2)
161  //
162  this->an_ /= (this->n_ + 2);
163  this->an_ *= (this->n_ + 1);
164  this->an_ /= (this->n_ + 2);
165  this->an_ *= (this->n_ + 1);
166 
167  // term = static_cast<long double>( value);
168  term *= term;
169  term /= (this->n_ + 2);
170  term /= (this->n_ + 2);
171  this->an_ += term;
172 
173  //
174  // B(N+1) = (B(N) * (N+1)^2 / (N+2)^2) + (2 * X(N+1) / (N+2)^2)
175  //
176  this->bn_ /= (this->n_ + 2);
177  this->bn_ *= (this->n_ + 1);
178  this->bn_ /= (this->n_ + 2);
179  this->bn_ *= (this->n_ + 1);
180 
181  term = static_cast<long double>(value * 2);
182  term /= (this->n_ + 2);
183  term /= (this->n_ + 2);
184  this->bn_ += term;
185 
186  //
187  // C(N+1) = (N+1) / (N+2)^2
188  //
189  this->cn_ = this->n_ + 1;
190  this->cn_ /= (this->n_ + 2);
191  this->cn_ /= (this->n_ + 2);
192 
193  if ((this->n_ == 0) || (value < this->minimum_)) {
194  this->minimum_ = value;
195  }
196 
197  if ((this->n_ == 0) || (value > this->maximum_)) {
198  this->maximum_ = value;
199  }
200 
201  this->n_ += 1; // Must follow internal variable updates.
202 }
const LogLevel::Value value
Definition: debug.cpp:61
DataType minimum_
Definition: Stats_T.h:69
long double cn_
Definition: Stats_T.h:75
unsigned long n_
Definition: Stats_T.h:68
long double variance_
Definition: Stats_T.h:76
DataType maximum_
Definition: Stats_T.h:70
long double bn_
Definition: Stats_T.h:74
long double an_
Definition: Stats_T.h:73
void collect(const DataType &datum)
Implement data collection.

◆ maximum()

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

Access the maximum value.

: return qNaN with no data.

Definition at line 248 of file Stats_T.h.

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

249 {
250  /// @TODO: return qNaN with no data.
251  return (this->n_ == 0)? 0: this->maximum_;
252 }
unsigned long n_
Definition: Stats_T.h:68
DataType maximum_
Definition: Stats_T.h:70

◆ mean()

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

Calculate the average value.

: return qNaN with no data.

Definition at line 207 of file Stats_T.h.

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

208 {
209  if (this->n_ == 0) {
210  /// @TODO: return qNaN with no data.
211  return 0.0;
212  }
213 
214  // Slide rule style calculations.
215 
216  //
217  // MEAN = B(N) * (N+1)^2 / (2 * N)
218  //
219  long double average = this->bn_ / 2.0 ;
220 
221  average *= (this->n_ + 1) ;
222  average /= this->n_ ;
223  average *= (this->n_ + 1) ;
224 
225  return average ;
226 }
unsigned long n_
Definition: Stats_T.h:68
long double bn_
Definition: Stats_T.h:74

◆ minimum()

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

Access the minimum value.

: return qNaN with no data.

Definition at line 239 of file Stats_T.h.

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

240 {
241  /// @TODO: return qNaN with no data.
242  return (this->n_ == 0)? 0: this->minimum_;
243 }
DataType minimum_
Definition: Stats_T.h:69
unsigned long n_
Definition: Stats_T.h:68

◆ n()

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

Access the number of values accumulated.

Definition at line 257 of file Stats_T.h.

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

258 {
259  return this->n_;
260 }
unsigned long n_
Definition: Stats_T.h:68

◆ operator=()

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 104 of file Stats_T.h.

105 {
106  this->n_ = rhs.n_;
107  this->minimum_ = rhs.minimum_;
108  this->maximum_ = rhs.maximum_;
109  this->an_ = rhs.an_ ;
110  this->bn_ = rhs.bn_ ;
111  this->cn_ = rhs.cn_ ;
112  this->variance_ = rhs.variance_ ;
113  return *this;
114 }
DataType minimum_
Definition: Stats_T.h:69
long double cn_
Definition: Stats_T.h:75
unsigned long n_
Definition: Stats_T.h:68
long double variance_
Definition: Stats_T.h:76
DataType maximum_
Definition: Stats_T.h:70
long double bn_
Definition: Stats_T.h:74
long double an_
Definition: Stats_T.h:73

◆ reset()

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

Reset statistics to nil.

Definition at line 119 of file Stats_T.h.

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

120 {
121  this->n_ = 0;
122  this->minimum_ = static_cast<DataType>(0);
123  this->maximum_ = static_cast<DataType>(0);
124  this->an_ = 0.0;
125  this->bn_ = 0.0;
126  this->cn_ = 0.0;
127  this->variance_ = 0.0;
128 }
DataType minimum_
Definition: Stats_T.h:69
long double cn_
Definition: Stats_T.h:75
unsigned long n_
Definition: Stats_T.h:68
long double variance_
Definition: Stats_T.h:76
DataType maximum_
Definition: Stats_T.h:70
long double bn_
Definition: Stats_T.h:74
long double an_
Definition: Stats_T.h:73

◆ var()

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

Calculate the variance value.

Definition at line 231 of file Stats_T.h.

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

232 {
233  return this->variance_ ;
234 }
long double variance_
Definition: Stats_T.h:76

Member Data Documentation

◆ an_

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

Definition at line 73 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< double >::operator=().

◆ bn_

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

Definition at line 74 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< double >::operator=().

◆ cn_

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

Definition at line 75 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< double >::operator=().

◆ maximum_

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

Definition at line 70 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< double >::operator=().

◆ minimum_

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

Definition at line 69 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< double >::operator=().

◆ n_

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

Definition at line 68 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< double >::operator=().

◆ variance_

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

Definition at line 76 of file Stats_T.h.

Referenced by OpenDDS::DCPS::Stats< double >::operator=().


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