KrisLibrary  1.0.0
Histogram.h
1 #ifndef STATISTICS_HISTOGRAM_H
2 #define STATISTICS_HISTOGRAM_H
3 
4 #include "statistics.h"
5 
6 namespace Statistics {
7 
11 class Histogram
12 {
13  public:
14  Histogram();
16  void Clear();
18  void Resize(Real split);
20  void Resize(size_t n,Real a,Real b);
22  void ResizeToFit(const std::vector<Real>& data,size_t n);
24  void Fill(Real val=0);
26  void Calculate(const std::vector<Real>& data);
27 
28  void GetRange(int bucket,Real& min,Real& max) const;
29  int GetBucket(Real val) const;
30  void AddBucket(Real val,Real num=1);
31  Real GetBucketCount(int bucket) const { return buckets[bucket]; }
32  Real NumObservations() const;
33 
34  std::vector<Real> divs;
36  std::vector<Real> buckets;
37 };
38 
39 } //namespace Statistics
40 
41 #endif
1-D histogram class
Definition: Histogram.h:11
void Calculate(const std::vector< Real > &data)
Calculates the histogram of the data.
Definition: Histogram.cpp:62
std::vector< Real > buckets
divs.size()+1 buckets (-inf,x0),[x1,x2),...,[xn-1,xn),[xn,inf)
Definition: Histogram.h:36
void Clear()
Creates one big bucket.
Definition: Histogram.cpp:16
Contains all definitions in the statistics directory.
Definition: BernoulliDistribution.h:6
void ResizeToFit(const std::vector< Real > &data, size_t n)
Creates n uniformly spaced buckets between the min and max of the data.
Definition: Histogram.cpp:46
Basic statistical utilities.
void Resize(Real split)
Creates buckets (-inf,split],(split,inf)
Definition: Histogram.cpp:22
void Fill(Real val=0)
Fills all buckets with the given value.
Definition: Histogram.cpp:57