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++)
197 update(values(i, 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