74template<
typename Num_T>
80 Histogram(Num_T from = Num_T(0), Num_T
to = Num_T(99),
int n_bins = 100);
85 void setup(Num_T from, Num_T
to,
int n_bins);
95 void reset() { trials_cnt = 0; bins.zeros(); };
97 int get_bin(
int ix)
const {
return bins(ix); };
151 lo_vals.set_size(n_bins);
152 hi_vals.set_size(n_bins);
153 center_vals.set_size(n_bins);
154 bins.set_size(n_bins);
156 step = (
to - from) / (num_bins - 1);
158 lo_vals = center_vals - step / 2;
159 hi_vals = center_vals + step / 2;
168 int end = num_bins - 1;
169 int test = (start + end) / 2;
171 while (start < end) {
172 if (value < lo_vals(test))
174 else if (value >= hi_vals(test))
178 test = (start + end) / 2;
188 for (
int i = 0; i < values.
length(); i++)
195 for (
int i = 0; i < values.
rows(); i++)
196 for (
int j = 0; j < values.
cols(); j++)
204 for (
int j = 0; j < num_bins; j++)
205 pdf(j) =
static_cast<double>(bins(j)) / trials_cnt;
214 for (
int j = 0; j < num_bins; j++)
215 cdf(j) =
static_cast<double>(tmp(j)) / trials_cnt;
int bins_num() const
Current number of bins.
void reset()
Bins reset, so accumulation can be restarted.
~Histogram()
Default destructor.
Vec< Num_T > get_bin_rights() const
Access to right boundary of bin intervals (all bins).
Vec< Num_T > get_bin_centers() const
Access to bin center values (all bins).
Num_T get_bin_center(int ix) const
Access to bin center (single bin).
Num_T get_bin_right(int ix) const
Access to right boundary of single bin.
Vec< Num_T > get_bin_lefts() const
Access to left boundary of bin intervals (all bins).
ivec get_bins() const
Access to histogram as a vector.
int trials_num() const
Current trials counter.
Num_T get_bin_left(int ix) const
Access to left boundary of single bin.
int get_bin(int ix) const
Access to single bin counter.
Matrix Class (Templated).
int rows() const
The number of rows.
int cols() const
The number of columns.
Vector Class (Templated).
int length() const
The size of the vector.
T to(double x)
Convert double to T.
vec get_cdf() const
Experimental Cumulative Density Function (CDF) computation.
vec get_pdf() const
Experimental Probability Density Function (PDF) computation.
void setup(Num_T from, Num_T to, int n_bins)
Histogram setup.
Histogram(Num_T from=Num_T(0), Num_T to=Num_T(99), int n_bins=100)
void update(Num_T value)
Histogram update.
Vec< T > cumsum(const Vec< T > &v)
Cumulative sum of all elements in the vector.
vec linspace(double from, double to, int points)
linspace (works in the same way as the MATLAB version)
Matrix Class Definitions.