8 #ifndef OPENDDS_DCPS_STATS_T_H 9 #define OPENDDS_DCPS_STATS_T_H 11 #if !defined (ACE_LACKS_PRAGMA_ONCE) 27 template<
typename DataType>
31 Stats(
unsigned int amount = 0,
52 long double mean()
const;
55 long double var()
const;
64 unsigned long n()
const;
79 template<
typename DataType>
88 template<
typename DataType>
97 variance_(v.variance_)
101 template<
typename DataType>
109 this->an_ = rhs.
an_ ;
110 this->bn_ = rhs.
bn_ ;
111 this->cn_ = rhs.
cn_ ;
116 template<
typename DataType>
122 this->minimum_ =
static_cast<DataType
>(0);
123 this->maximum_ =
static_cast<DataType
>(0);
127 this->variance_ = 0.0;
130 template<
typename DataType>
136 this->collect(value);
147 this->variance_ /= (this->n_ + 1);
148 this->variance_ *= this->n_;
149 this->variance_ /= (this->n_ + 1);
150 this->variance_ *= this->n_;
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;
162 this->an_ /= (this->n_ + 2);
163 this->an_ *= (this->n_ + 1);
164 this->an_ /= (this->n_ + 2);
165 this->an_ *= (this->n_ + 1);
169 term /= (this->n_ + 2);
170 term /= (this->n_ + 2);
176 this->bn_ /= (this->n_ + 2);
177 this->bn_ *= (this->n_ + 1);
178 this->bn_ /= (this->n_ + 2);
179 this->bn_ *= (this->n_ + 1);
181 term =
static_cast<long double>(value * 2);
182 term /= (this->n_ + 2);
183 term /= (this->n_ + 2);
189 this->cn_ = this->n_ + 1;
190 this->cn_ /= (this->n_ + 2);
191 this->cn_ /= (this->n_ + 2);
193 if ((this->n_ == 0) || (value < this->minimum_)) {
194 this->minimum_ =
value;
197 if ((this->n_ == 0) || (value > this->maximum_)) {
198 this->maximum_ =
value;
204 template<
typename DataType>
219 long double average = this->bn_ / 2.0 ;
221 average *= (this->n_ + 1) ;
222 average /= this->n_ ;
223 average *= (this->n_ + 1) ;
228 template<
typename DataType>
233 return this->variance_ ;
236 template<
typename DataType>
242 return (this->n_ == 0)? 0: this->minimum_;
245 template<
typename DataType>
251 return (this->n_ == 0)? 0: this->maximum_;
254 template<
typename DataType>
267 #endif // OPENDDS_DCPS_STATS_T_H
const LogLevel::Value value
Stats & operator=(const Stats &rhs)
Default bitwise copy is sufficient.
DataType minimum() const
Access the minimum value.
unsigned long n() const
Access the number of values accumulated.
long double mean() const
Calculate the average value.
void reset()
Reset statistics to nil.
Accumulates average, n, variance, minimum, and maximum statistics.
long double var() const
Calculate the variance value.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
Stats(unsigned int amount=0, typename DataCollector< DataType >::OnFull type=DataCollector< DataType >::KeepOldest)
Default constructor.
The Internal API and Implementation of OpenDDS.
DataType maximum() const
Access the maximum value.