histogram.h
Go to the documentation of this file.
/* histogram.h
*/
#ifndef _HISTOGRAM_H
#define _HISTOGRAM_H
#include <boost/scoped_array.hpp>
#include <iosfwd>
namespace osl
{
namespace stat
{
class Histogram
{
boost::scoped_array<double> data;
size_t length_, width_;
int start_;
bool show_on_destruct;
public:
Histogram(size_t w, size_t len, int start=0, bool show_on_destruct=false);
~Histogram();
size_t safeIndex(size_t i) const
{
return (i >= length_) ? length_-1 : i;
}
double& frequency(size_t i) { return data[safeIndex(i)]; }
void add(int value, double weight=1.0)
{
if (value < start_)
value = 0;
else
value -= start_;
frequency(value/width_) += weight;
}
double frequency(size_t i) const { return data[safeIndex(i)]; }
void show(std::ostream& os) const;
size_t length() const { return length_; }
size_t width() const { return width_; }
int start() const { return start_; }
void merge(const Histogram&);
void showRatio(std::ostream& os, const Histogram& numerator) const;
};
} // namespace stat
using stat::Histogram;
} // namespace osl
#endif /* _HISTOGRAM_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::Histogram::Histogram
Histogram(size_t w, size_t len, int start=0, bool show_on_destruct=false)
Definition histogram.cc:8
osl::stat::Histogram
ヒストグラム
Definition histogram.h:16
osl::stat::Histogram::width
size_t width() const
Definition histogram.h:41
osl::stat::Histogram::~Histogram
~Histogram()
Definition histogram.cc:15
osl::stat::Histogram::start
int start() const
Definition histogram.h:42
osl::stat::Histogram::length_
size_t length_
Definition histogram.h:18
osl::stat::Histogram::frequency
double frequency(size_t i) const
Definition histogram.h:37
osl::stat::Histogram::show
void show(std::ostream &os) const
Definition histogram.cc:35
osl::stat::Histogram::add
void add(int value, double weight=1.0)
Definition histogram.h:29
osl::stat::Histogram::width_
size_t width_
Definition histogram.h:18
osl::stat::Histogram::start_
int start_
Definition histogram.h:19
osl::stat::Histogram::showRatio
void showRatio(std::ostream &os, const Histogram &numerator) const
\frac{*this}{numerator} を表示 length や width が異なっていたら何もしない
Definition histogram.cc:47
osl::stat::Histogram::data
boost::scoped_array< double > data
Definition histogram.h:17
osl::stat::Histogram::safeIndex
size_t safeIndex(size_t i) const
Definition histogram.h:24
osl::stat::Histogram::show_on_destruct
bool show_on_destruct
Definition histogram.h:20
osl::stat::Histogram::length
size_t length() const
Definition histogram.h:40
osl::stat::Histogram::Histogram
Histogram(size_t w, size_t len, int start=0, bool show_on_destruct=false)
Definition histogram.cc:8
osl::stat::Histogram::frequency
double & frequency(size_t i)
Definition histogram.h:28
osl::stat::Histogram::merge
void merge(const Histogram &)
結果を合算する length や width が異なっていたら何もしない
Definition histogram.cc:21
osl::stat
Definition rating/featureSet.h:18
osl
Definition additionalEffect.h:6