4 template <
typename VarType,
typename WeightType>
5 template <
typename BinType>
11 auto min_bin = m_binning.getBinIndex(min);
12 if (min_bin > m_clip_left && min_bin <= m_clip_right)
13 m_clip_left = min_bin;
15 auto max_bin = m_binning.getBinIndex(max);
16 if (max_bin >= m_clip_left && max_bin < m_clip_right)
17 m_clip_right = max_bin;
20 template <
typename VarType,
typename WeightType>
21 template <
typename BinType>
23 VarType total = 0, total_count = 0;
27 for (
auto i = m_clip_left; i <= m_clip_right; ++i) {
28 auto center = m_binning.getBin(i);
29 total += (*m_counts)[i] * center;
30 total_count += (*m_counts)[i];
31 sigma += (*m_counts)[i] * center * center;
34 VarType mean = total / total_count;
35 sigma = sigma / total_count - mean * mean;
42 WeightType low_sum = 0., high_sum = 0.;
43 auto low_i = m_clip_left, high_i = m_clip_right;
44 while (low_i <= high_i) {
45 if (low_sum < high_sum) {
46 low_sum += (*m_counts)[low_i++];
48 high_sum += (*m_counts)[high_i--];
52 assert(low_sum + high_sum == total_count);
56 auto edges = m_binning.getBinEdges(high_i + 1);
57 auto bin_width = (edges.second - edges.first);
58 auto max_counts =
std::max((*m_counts)[low_i], (*m_counts)[high_i]);
59 median = edges.first + bin_width * (high_sum - low_sum) / (2.0 * max_counts);
61 median = m_binning.getBin(0);
73 template <
typename BinType,
typename IterType>
75 template <
typename U,
typename = decltype(std::declval<U>().computeBins(std::declval<IterType>(), std::declval<IterType>()))>
81 static constexpr
bool value =
sizeof(Test<BinType>(0)) ==
sizeof(char);
87 template <
typename BinType,
typename IterType>
89 binning.computeBins(begin, end);
95 template <
typename BinType,
typename IterType>
98 template <
typename VarType,
typename WeightType>
99 template <
typename BinType>
100 template <
typename IterType,
typename WeightIterType>
107 m_clip_right = m_binning.getBinCount() - 1;
108 m_counts->resize(m_binning.getBinCount());
110 ssize_t nbins = m_counts->size();
113 for (; i != end; ++i, ++wi) {
114 auto bin = m_binning.getBinIndex(*i);
115 if (bin >= 0 && bin < nbins) {
116 (*m_counts)[bin] += *wi;
void computeBinsForwarder(BinType &binning, IterType begin, IterType end, std::true_type)
static constexpr bool value
static char Test(SFINAE< U > *)