KrisLibrary  1.0.0
DistributionCollector.h
1 #ifndef STATISTICS_DISTRIBUTION_COLLECTOR_H
2 #define STATISTICS_DISTRIBUTION_COLLECTOR_H
3 
4 #include "statistics.h"
5 
6 namespace Statistics {
7 
15 {
17  void operator << (Real x) { collect(x); }
18  void collect (Real x);
19  void weightedCollect (Real x,Real weight);
20 
21  Real number() const { return n; }
22  Real minimum() const { return xmin; }
23  Real maximum() const { return xmax; }
24  Real average() const { return sum/n; }
25  Real mean() const { return sum/n; }
26  Real variance() const {
27  Real avg=mean();
28  return Max(sumsquared/n - avg*avg,Zero); //may have small numerical errors
29  }
30  Real stddev() const { return Sqrt(variance()); }
31  Real skewness() const;
32  Real moment(int i,Real center) const;
33  void clear();
34 
35  Real n;
36  Real xmin,xmax;
37  Real sum,sumsquared,sumcubed;
38 };
39 
47 {
48  public:
50  void operator << (const Vector& x) { collect(x); }
51  void collect (const Vector& x);
52  void weightedCollect (const Vector& x,Real weight);
53 
54  //convenience functions
55  void collect (Real x1);
56  void collect (Real x1,Real x2);
57  void collect (Real x1,Real x2,Real x3);
58  void collect (Real x1,Real x2,Real x3,Real x4);
59 
60  Real number() const { return n; }
61  const Vector& minimum() const { return xmin; }
62  const Vector& maximum() const { return xmax; }
63  void getMean(Vector& mean) const;
64  void getVariance(Vector& var) const;
65  void getCovariance(Matrix& covar) const;
66  void getStddev(Vector& stddev) const;
67  void clear();
68 
69  Real n;
70  Vector xmin,xmax;
71  Vector sum;
72  Matrix sumouterproduct;
73 };
74 
75 } //namespace Statistics
76 
77 #endif
Incrementally collects samples from a multivariate distribution.
Definition: DistributionCollector.h:46
Incrementally collects samples from a univariate distribution.
Definition: DistributionCollector.h:14
Contains all definitions in the statistics directory.
Definition: BernoulliDistribution.h:6
Basic statistical utilities.