171template <
typename Container>
174 using T = std::decay_t<
decltype(*std::begin(data))>;
176 for (
const auto &x : data)
189template <
typename Container>
192 using T = std::decay_t<
decltype(*std::begin(data))>;
195 for (
const auto &x : data)
201 return s /
static_cast<T>(n);
219template <
typename Container>
221 bool population =
false) -> std::decay_t<
decltype(*std::begin(data))>
223 using T = std::decay_t<
decltype(*std::begin(data))>;
230 for (
const auto &x : data)
234 m += delta /
static_cast<T>(n);
242 return m2 /
static_cast<T>(n);
245 return m2 /
static_cast<T>(n - 1);
256template <
typename Container>
258 bool population =
false) -> std::decay_t<
decltype(*std::begin(data))>
260 return std::sqrt(
variance(data, population));
271template <
typename Container>
274 auto it = std::begin(data);
275 auto end = std::end(data);
279 for (++it; it != end; ++it)
293template <
typename Container>
296 auto it = std::begin(data);
297 auto end = std::end(data);
301 for (++it; it != end; ++it)
315template <
typename Container>
317 -> std::pair<std::decay_t<
decltype(*std::begin(data))>, std::decay_t<
decltype(*std::begin(data))>>
319 using T = std::decay_t<
decltype(*std::begin(data))>;
320 auto it = std::begin(data);
321 auto end = std::end(data);
326 for (++it; it != end; ++it)
333 return {min_val, max_val};
351template <
typename Container>
353 double p) -> std::decay_t<
decltype(*std::begin(data))>
355 using T = std::decay_t<
decltype(*std::begin(data))>;
360 for (
const auto &x : data)
372 const double index = (p / 100.0) * (
sorted.size() - 1);
373 auto lower =
static_cast<size_t>(std::floor(index));
374 auto upper =
static_cast<size_t>(std::ceil(index));
392template <
typename Container>
405template <
typename Container>
407 -> std::tuple<std::decay_t<
decltype(*std::begin(data))>,
408 std::decay_t<
decltype(*std::begin(data))>,
409 std::decay_t<
decltype(*std::begin(data))>>
411 using T = std::decay_t<
decltype(*std::begin(data))>;
425template <
typename Container>
446template <
typename Container>
449 using T = std::decay_t<
decltype(*std::begin(data))>;
450 auto it = std::begin(data);
451 auto end = std::end(data);
456 for (
const auto &x : data)
459 T mode_val = freq.
begin()->first;
462 for (
const auto &[val,
count] : freq)
479template <
typename Container>
482 using T = std::decay_t<
decltype(*std::begin(data))>;
485 for (
const auto &x : data)
492 for (
const auto &[val,
count] : freq)
497 for (
const auto &[val,
count] : freq)
522template <
typename Container>
525 using T = std::decay_t<
decltype(*std::begin(data))>;
535 for (
const auto &x : data)
545 T factor =
static_cast<T>(n) / ((n - 1) * (n - 2));
546 return factor *
sum3;
563template <
typename Container>
566 using T = std::decay_t<
decltype(*std::begin(data))>;
576 for (
const auto &x : data)
587 T n_t =
static_cast<T>(n);
604template <
typename Container>
606 -> std::decay_t<
decltype(*std::begin(data))>
608 using T = std::decay_t<
decltype(*std::begin(data))>;
611 return stddev(data) / std::abs(
m);
629template <
typename Container1,
typename Container2>
632 bool population =
false) -> std::decay_t<
decltype(*std::begin(x))>
634 using T = std::decay_t<
decltype(*std::begin(x))>;
636 auto it_x = std::begin(x);
637 auto it_y = std::begin(
y);
638 auto end_x = std::end(x);
651 mean_x += dx /
static_cast<T>(n);
652 T dy = *
it_y - mean_y;
653 mean_y += dy /
static_cast<T>(n);
654 c += dx * (*
it_y - mean_y);
661 <<
"covariance: containers have different sizes";
666 return c /
static_cast<T>(n);
669 return c /
static_cast<T>(n - 1);
687template <
typename Container1,
typename Container2>
689 const Container2 &
y) -> std::decay_t<
decltype(*std::begin(x))>
691 using T = std::decay_t<
decltype(*std::begin(x))>;
698 <<
"correlation: one or both datasets have zero variance";
700 return cov / (sx * sy);
716template <
typename Container>
718 -> std::vector<std::pair<std::decay_t<
decltype(*std::begin(data))>,
size_t>>
720 using T = std::decay_t<
decltype(*std::begin(data))>;
724 auto [min_val, max_val] =
min_max(data);
725 T range = max_val - min_val;
730 return {{min_val, std::distance(std::begin(data), std::end(data))}};
735 std::vector<size_t> counts(
num_bins, 0);
737 for (
const auto &x : data)
739 auto bin =
static_cast<size_t>((x - min_val) /
bin_width);
745 std::vector<std::pair<T, size_t>> result;
748 for (
size_t i = 0; i <
num_bins; ++i)
751 result.emplace_back(center, counts[i]);
768template <
typename Container>
770 ->
Stats<std::decay_t<
decltype(*std::begin(data))>>
772 using T = std::decay_t<
decltype(*std::begin(data))>;
776 for (
const auto &x : data)
785 s.mean = s.sum /
static_cast<T>(s.count);
788 auto [min_val, max_val] =
min_max(data);
796 s.stddev = std::sqrt(s.variance);
800 s.coef_variation = s.stddev / std::abs(s.mean);
856 std::sort(data +
l, data +
r + 1);
872 for (
int i =
l; i <=
r; ++i)
875 T delta = data[i] -
m;
876 m += delta /
static_cast<T>(
k);
882 var = (n > 1) ?
m2 /
static_cast<T>(n - 1) :
T();
898template <
typename Container>
900 std::decay_t<
decltype(*std::begin(data))> &avg,
901 std::decay_t<
decltype(*std::begin(data))> &var,
902 std::decay_t<
decltype(*std::begin(data))> &
med,
903 std::decay_t<
decltype(*std::begin(data))> &
_min,
904 std::decay_t<
decltype(*std::begin(data))> &
_max)
906 using T = std::decay_t<
decltype(*std::begin(data))>;
909 for (
const auto &x : data)
922 const size_t n =
sorted.size();
923 const size_t mid = n / 2;
933 for (
size_t si = 0;
si < n; ++
si)
938 m += delta /
static_cast<T>(
k);
944 var = (n > 1) ?
m2 /
static_cast<T>(n - 1) :
T();
Exception handling system with formatted messages for Aleph-w.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
High-level sorting functions for Aleph containers.
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Generic key-value map implemented on top of a binary search tree.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
auto percentile(const Container &data, double p) -> std::decay_t< decltype(*std::begin(data))>
Compute a percentile value.
auto histogram(const Container &data, size_t num_bins) -> std::vector< std::pair< std::decay_t< decltype(*std::begin(data))>, size_t > >
Compute a histogram of the data.
auto variance(const Container &data, bool population=false) -> std::decay_t< decltype(*std::begin(data))>
Compute variance using Welford's numerically stable algorithm.
auto kurtosis(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute excess kurtosis (measure of tailedness).
const T * median(const T &a, const T &b, const T &c, const Compare &cmp=Compare())
Return a pointer to the median value among three elements.
and
Check uniqueness with explicit hash + equality functors.
std::decay_t< typename HeadC::Item_Type > T
DynArray< T > & in_place_sort(DynArray< T > &c, Cmp cmp=Cmp())
Sorts a DynArray in place.
auto covariance(const Container1 &x, const Container2 &y, bool population=false) -> std::decay_t< decltype(*std::begin(x))>
Compute covariance between two datasets.
auto stddev(const Container &data, bool population=false) -> std::decay_t< decltype(*std::begin(data))>
Compute standard deviation.
auto mean(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute the arithmetic mean.
bool diff(const C1 &c1, const C2 &c2, Eq e=Eq())
Check if two containers differ.
auto min_max(const Container &data) -> std::pair< std::decay_t< decltype(*std::begin(data))>, std::decay_t< decltype(*std::begin(data))> >
Compute minimum and maximum values in one pass.
auto min_value(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute minimum value.
auto skewness(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute skewness (measure of asymmetry).
auto iqr(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute the interquartile range (IQR = Q3 - Q1).
auto compute_all_stats(const Container &data) -> Stats< std::decay_t< decltype(*std::begin(data))> >
Compute all statistics for a dataset.
auto correlation(const Container1 &x, const Container2 &y) -> std::decay_t< decltype(*std::begin(x))>
Compute Pearson correlation coefficient.
Container< T > range(const T start, const T end, const T step=1)
Generate a range of values [start, end] with a given step.
bool is_multimodal(const Container &data)
Check if data is multimodal.
auto coefficient_of_variation(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute coefficient of variation (CV = stddev / mean).
auto mode(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute the mode (most frequent value).
auto quartiles(const Container &data) -> std::tuple< std::decay_t< decltype(*std::begin(data))>, std::decay_t< decltype(*std::begin(data))>, std::decay_t< decltype(*std::begin(data))> >
Compute quartiles (Q1, Q2, Q3).
auto max_value(const Container &data) -> std::decay_t< decltype(*std::begin(data))>
Compute maximum value.
void compute_stats(T *data, int l, int r, T &avg, T &var, T &med, T &_min, T &_max)
Compute basic descriptive statistics for an array range.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Container for comprehensive statistical results.
T q1
First quartile (25th percentile)
size_t count
Number of elements.
T skewness
Skewness (asymmetry)
T q3
Third quartile (75th percentile)
T variance
Sample variance.
T coef_variation
Coefficient of variation (stddev/mean)
T median
Median (50th percentile)
bool is_valid() const noexcept
Check if statistics are valid.
T iqr
Interquartile range (Q3 - Q1)
T range() const noexcept
Get the range (max - min).
T kurtosis
Excess kurtosis (tailedness)
T stddev
Standard deviation.
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
Lazy and scalable dynamic array implementation.
Dynamic key-value map based on balanced binary search trees.
Comprehensive sorting algorithms and search utilities for Aleph-w.