average.h
Go to the documentation of this file.
/* average.h
*/
#ifndef _AVERAGE_H
#define _AVERAGE_H
namespace osl
{
namespace stat
{
class Average
{
double mean;
int elements;
public:
// CREATORS
Average() : mean(0), elements(0)
{
}
// MANIPULATORS
double add(const double& x)
{
++elements;
const double diff = x - mean;
mean += diff/elements;
return diff;
}
void merge(const Average& r)
{
if (r.elements == 0)
return;
const double sum = mean*elements + r.mean*r.elements;
elements += r.elements;
mean = sum / elements;
}
void clear(double a=0.0, int e=0)
{
mean = a;
elements = e;
}
// ACCESSORS
double average() const { return mean; }
int numElements() const { return elements; }
};
} // namespace stat
using stat::Average;
} // namespace osl
#endif /* _AVERAGE_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Average::Average
Average()
Definition average.h:19
osl::stat::Average::clear
void clear(double a=0.0, int e=0)
Definition average.h:42
osl::stat::Average::merge
void merge(const Average &r)
Definition average.h:34
osl::stat::Average::add
double add(const double &x)
Add an element x.
Definition average.h:27
osl::stat::Average::Average
Average()
Definition average.h:19
osl::stat::Average::mean
double mean
Definition average.h:15
osl::stat::Average::average
double average() const
Definition average.h:48
osl::stat::Average::numElements
int numElements() const
Definition average.h:49
osl::stat::Average::elements
int elements
Definition average.h:16
osl::stat
Definition rating/featureSet.h:18
osl
Definition additionalEffect.h:6