Skip to content

Commit

Permalink
test inclusive PMF and CDF
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSaydakov committed Jan 11, 2022
1 parent c8c2742 commit 310da28
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions kll/test/kll_sketch_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,38 @@ TEST_CASE("kll sketch", "[kll_sketch]") {
sketch.update(static_cast<float>(i));
values[i] = static_cast<float>(i);
}

const auto ranks(sketch.get_CDF(values, n));
const auto pmf(sketch.get_PMF(values, n));

double subtotal_pmf(0);
for (int i = 0; i < n; i++) {
if (sketch.get_rank(values[i]) != ranks[i]) {
std::cerr << "checking rank vs CDF for value " << i << std::endl;
REQUIRE(sketch.get_rank(values[i]) == ranks[i]);
{ // inclusive=false (default)
const auto ranks(sketch.get_CDF(values, n));
const auto pmf(sketch.get_PMF(values, n));

double subtotal_pmf = 0;
for (int i = 0; i < n; i++) {
if (sketch.get_rank(values[i]) != ranks[i]) {
std::cerr << "checking rank vs CDF for value " << i << std::endl;
REQUIRE(sketch.get_rank(values[i]) == ranks[i]);
}
subtotal_pmf += pmf[i];
if (abs(ranks[i] - subtotal_pmf) > NUMERIC_NOISE_TOLERANCE) {
std::cerr << "CDF vs PMF for value " << i << std::endl;
REQUIRE(ranks[i] == Approx(subtotal_pmf).margin(NUMERIC_NOISE_TOLERANCE));
}
}
subtotal_pmf += pmf[i];
if (abs(ranks[i] - subtotal_pmf) > NUMERIC_NOISE_TOLERANCE) {
std::cerr << "CDF vs PMF for value " << i << std::endl;
REQUIRE(ranks[i] == Approx(subtotal_pmf).margin(NUMERIC_NOISE_TOLERANCE));
}
{ // inclusive=true
const auto ranks(sketch.get_CDF<true>(values, n));
const auto pmf(sketch.get_PMF<true>(values, n));

double subtotal_pmf = 0;
for (int i = 0; i < n; i++) {
if (sketch.get_rank<true>(values[i]) != ranks[i]) {
std::cerr << "checking rank vs CDF for value " << i << std::endl;
REQUIRE(sketch.get_rank(values[i]) == ranks[i]);
}
subtotal_pmf += pmf[i];
if (abs(ranks[i] - subtotal_pmf) > NUMERIC_NOISE_TOLERANCE) {
std::cerr << "CDF vs PMF for value " << i << std::endl;
REQUIRE(ranks[i] == Approx(subtotal_pmf).margin(NUMERIC_NOISE_TOLERANCE));
}
}
}
}
Expand Down

0 comments on commit 310da28

Please sign in to comment.