20 #ifndef KOLMOGOROV_SMIRNOV_IMPL_HPP_
21 #define KOLMOGOROV_SMIRNOV_IMPL_HPP_
28 template<
typename Sketch>
30 auto comparator = sketch1.get_comparator();
31 auto view1 = sketch1.get_sorted_view();
32 auto view2 = sketch2.get_sorted_view();
33 auto it1 = view1.begin();
34 auto it2 = view2.begin();
35 const auto n1 = sketch1.get_n();
36 const auto n2 = sketch2.get_n();
38 while (it1 != view1.end() && it2 != view2.end()) {
39 const double norm_cum_wt1 =
static_cast<double>(it1.get_cumulative_weight(
false)) / n1;
40 const double norm_cum_wt2 =
static_cast<double>(it2.get_cumulative_weight(
false)) / n2;
41 delta = std::max(
delta, std::abs(norm_cum_wt1 - norm_cum_wt2));
42 if (comparator((*it1).first, (*it2).first)) {
44 }
else if (comparator((*it2).first, (*it1).first)) {
51 const double norm_cum_wt1 = it1 == view1.end() ? 1 :
static_cast<double>(it1.get_cumulative_weight(
false)) / n1;
52 const double norm_cum_wt2 = it2 == view2.end() ? 1 :
static_cast<double>(it2.get_cumulative_weight(
false)) / n2;
53 delta = std::max(
delta, std::abs(norm_cum_wt1 - norm_cum_wt2));
57 template<
typename Sketch>
59 const double r1 = sketch1.get_num_retained();
60 const double r2 = sketch2.get_num_retained();
61 const double alpha_factor = sqrt(-0.5 * log(0.5 * p));
62 const double delta_area_threshold = alpha_factor * sqrt((r1 + r2) / (r1 * r2));
63 const double eps1 = sketch1.get_normalized_rank_error(
false);
64 const double eps2 = sketch2.get_normalized_rank_error(
false);
65 return delta_area_threshold + eps1 + eps2;
68 template<
typename Sketch>
static double delta(const Sketch &sketch1, const Sketch &sketch2)
Computes the raw delta area between two quantile sketches for the Kolmogorov-Smirnov Test.
Definition: kolmogorov_smirnov_impl.hpp:29
static bool test(const Sketch &sketch1, const Sketch &sketch2, double p)
Performs the Kolmogorov-Smirnov Test between two quantile sketches.
Definition: kolmogorov_smirnov_impl.hpp:69
static double threshold(const Sketch &sketch1, const Sketch &sketch2, double p)
Computes the adjusted delta area threshold for the Kolmogorov-Smirnov Test.
Definition: kolmogorov_smirnov_impl.hpp:58
DataSketches namespace.
Definition: binomial_bounds.hpp:38