20 Histogram<std::invoke_result_t<GroupBy,
decltype(*begin)>> histogram{};
22 while (begin != end) {
23 auto key{
std::invoke(
std::forward<GroupBy>(group_by), *begin)};
25 histogram.try_emplace(key, 0);
91 std::size_t data_point_amount{sequence.size()};
141 double scaled_margin{margin * (1.0/std::log10(data_point_amount))};
143 auto histogram{make_histogram(sequence.begin(), sequence.end(),
std::forward<GroupBy>(group_by))};
145 for (
auto& bin : histogram) {
146 auto [key, count] = bin;
148 double actual_percentage{percent_of(
static_cast<
double>(count),
static_cast<
double>(data_point_amount))};
149 double expected_percentage{std::invoke(std::forward<ProbabilityOf>(probability_of), key)};
151 if (!(actual_percentage == Approx(expected_percentage).margin(scaled_margin)))
152 return std::make_optional(DistributionError<T>{key, actual_percentage, expected_percentage});
std::optional< DistributionError< T > > respects_distribution(std::vector< T > &&sequence, GroupBy &&group_by, ProbabilityOf &&probability_of, double margin=33)
Returns true when the given sequence approximately respects a given distribution.