histogram.h
Go to the documentation of this file.
1 /* histogram.h
2  */
3 #ifndef _HISTOGRAM_H
4 #define _HISTOGRAM_H
5 
6 #include <boost/scoped_array.hpp>
7 #include <iosfwd>
8 namespace osl
9 {
10  namespace stat
11  {
15  class Histogram
16  {
17  boost::scoped_array<double> data;
18  size_t length_, width_;
19  int start_;
21  public:
22  Histogram(size_t w, size_t len, int start=0, bool show_on_destruct=false);
23  ~Histogram();
24  size_t safeIndex(size_t i) const
25  {
26  return (i >= length_) ? length_-1 : i;
27  }
28  double& frequency(size_t i) { return data[safeIndex(i)]; }
29  void add(int value, double weight=1.0)
30  {
31  if (value < start_)
32  value = 0;
33  else
34  value -= start_;
35  frequency(value/width_) += weight;
36  }
37  double frequency(size_t i) const { return data[safeIndex(i)]; }
38  void show(std::ostream& os) const;
39 
40  size_t length() const { return length_; }
41  size_t width() const { return width_; }
42  int start() const { return start_; }
43 
45  void merge(const Histogram&);
47  void showRatio(std::ostream& os, const Histogram& numerator) const;
48  };
49  } // namespace stat
50  using stat::Histogram;
51 } // namespace osl
52 
53 #endif /* _HISTOGRAM_H */
54 // ;;; Local Variables:
55 // ;;; mode:c++
56 // ;;; c-basic-offset:2
57 // ;;; End:
void merge(const Histogram &)
結果を合算する length や width が異なっていたら何もしない
Definition: histogram.cc:21
size_t safeIndex(size_t i) const
Definition: histogram.h:24
boost::scoped_array< double > data
Definition: histogram.h:17
void show(std::ostream &os) const
Definition: histogram.cc:35
void showRatio(std::ostream &os, const Histogram &numerator) const
{*this}{numerator} を表示 length や width が異なっていたら何もしない
Definition: histogram.cc:47
ヒストグラム
Definition: histogram.h:15
size_t length() const
Definition: histogram.h:40
double & frequency(size_t i)
Definition: histogram.h:28
int start() const
Definition: histogram.h:42
void add(int value, double weight=1.0)
Definition: histogram.h:29
Histogram(size_t w, size_t len, int start=0, bool show_on_destruct=false)
Definition: histogram.cc:8
double frequency(size_t i) const
Definition: histogram.h:37
size_t width() const
Definition: histogram.h:41