MCPcopy Create free account
hub / github.com/alandefreitas/matplotplusplus / fd_rule

Method fd_rule

source/matplot/axes_objects/histogram.cpp:379–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377 }
378
379 std::vector<double> histogram::fd_rule(const std::vector<double> &x,
380 double minx, double maxx,
381 bool hard_limits) {
382 size_t n = x.size();
383 double xrange = *std::max_element(x.begin(), x.end()) -
384 *std::min_element(x.begin(), x.end());
385 double bin_width = 1.0;
386 bool iqr_not_too_small = n > 1;
387 if (iqr_not_too_small) {
388 size_t q1_index = static_cast<size_t>(n * 0.25);
389 size_t q3_index = n - static_cast<size_t>(n * 0.25);
390 auto x_copy = x;
391 std::nth_element(x_copy.begin(), x_copy.begin() + q1_index,
392 x_copy.end());
393 std::nth_element(x_copy.begin(), x_copy.begin() + q3_index,
394 x_copy.end());
395 double interquartile_range = x_copy[q3_index] - x_copy[q1_index];
396 double iq = std::max(interquartile_range, xrange / 10.);
397 bin_width = 2 * iq * pow(n, -1. / 3.);
398 }
399 if (!hard_limits) {
400 return bin_picker(minx, maxx, 0, bin_width);
401 } else {
402 double max_x = *std::max_element(x.begin(), x.end());
403 double min_x = *std::min_element(x.begin(), x.end());
404 return bin_pickerbl(min_x, max_x, minx, maxx, bin_width);
405 }
406 }
407
408 std::vector<double> histogram::integers_rule(const std::vector<double> &x,
409 double minx, double maxx,

Callers

nothing calls this directly

Calls 5

bin_pickerblFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
maxFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected