74 template<
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); };
140 template<
class Num_T>
144 setup(from, to, n_bins);
147 template<
class Num_T>
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);
157 center_vals =
linspace(from, to, num_bins);
158 lo_vals = center_vals - step / 2;
159 hi_vals = center_vals + step / 2;
163 template<
class Num_T>
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;
185 template<
class Num_T>
188 for (
int i = 0; i < values.
length(); i++)
192 template<
class Num_T>
195 for (
int i = 0; i < values.
rows(); i++)
196 for (
int j = 0; j < values.
cols(); j++)
200 template<
class Num_T>
204 for (
int j = 0; j < num_bins; j++)
205 pdf(j) =
static_cast<double>(bins(j)) / trials_cnt;
209 template<
class Num_T>
214 for (
int j = 0; j < num_bins; j++)
215 cdf(j) =
static_cast<double>(tmp(j)) / trials_cnt;
223 #endif // #ifndef HISTOGRAM_H int trials_num() const
Current trials counter.
Num_T get_bin_right(int ix) const
Access to right boundary of single bin.
Num_T get_bin_center(int ix) const
Access to bin center (single bin)
Histogram computation class.
Vec< Num_T > get_bin_lefts() const
Access to left boundary of bin intervals (all bins)
vec get_cdf() const
Experimental Cumulative Density Function (CDF) computation.
ivec get_bins() const
Access to histogram as a vector.
void update(Num_T value)
Histogram update.
Vec< Num_T > get_bin_centers() const
Access to bin center values (all bins)
int get_bin(int ix) const
Access to single bin counter.
Vec< Num_T > get_bin_rights() const
Access to right boundary of bin intervals (all bins)
int cols() const
The number of columns.
Matrix Class Definitions.
Vec< T > cumsum(const Vec< T > &v)
Cumulative sum of all elements in the vector.
int length() const
The size of the vector.
int bins_num() const
Current number of bins.
vec linspace(double from, double to, int points)
linspace (works in the same way as the MATLAB version)
Num_T get_bin_left(int ix) const
Access to left boundary of single bin.
vec get_pdf() const
Experimental Probability Density Function (PDF) computation.
int rows() const
The number of rows.
Histogram(Num_T from=Num_T(0), Num_T to=Num_T(99), int n_bins=100)
T to(double x)
Convert double to T.
void reset()
Bins reset, so accumulation can be restarted.
void setup(Num_T from, Num_T to, int n_bins)
Histogram setup.
~Histogram()
Default destructor.