Skip to content

Report DDSketch relative value error - #164

Merged
milindsrivastava1997 merged 6 commits into
mainfrom
162-report-mean_relative_error-for-ddsketch-papers-relative-accuracy-metric
Oct 7, 2026
Merged

milindsrivastava1997 merged 6 commits into
mainfrom
162-report-mean_relative_error-for-ddsketch-papers-relative-accuracy-metric

Conversation

@milindsrivastava1997

Copy link
Copy Markdown
Contributor

Closes #162

Summary

  • score DDSketch with its relative-value guarantee rather than rank error
  • expose mean_relative_value_error through the DDSketch-only comparator
  • update saturation, cost-export, and recommendation pipelines

Validation

  • cargo test --workspace --no-default-features
  • python3 scripts/test_recommend_config.py
  • python3 scripts/test_export_autosketch_eval_table.py
  • python3 scripts/test_study_saturation.py

Benchmark artifact regeneration is pending access to the ignored source outputs / benchmark host.

@milindsrivastava1997 milindsrivastava1997 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review findings (inline below). Two findings fall outside the diff:

  1. rqe-optimizer/examples/small_problem.rs:170: optimizer silently drops DD. DD rows now report only mean_relative_value_error, but every quantile RAQE still asks for mean_rank_err. accuracy_ok_for treats a missing metric as failing, so after regenerating costs with export_rqe_optimizer_costs.sh, DD is never feasible and nothing reports an error. The fix belongs in the RAQE/candidate model (per-family accuracy metric, or map one SLA onto each family's metric). Swapping the string would just exclude KLL instead.
  2. scripts/recommend_config.py:27: stale rationale. The docstring and grid_point logic still choose DD's error grid point by worst_alpha_rank ("steepest tail, hardest for rank error"), which no longer applies under relative value error. docs/saturation_study.md (lines 40, 464, 486) still lists mean_rank_err for dd.

🤖 Generated with Claude Code

Comment thread aqpbm-core/src/accuracy/quantile.rs Outdated
}

fn quantile_value(sorted: &[f64], q: f64) -> f64 {
sorted[(q * (sorted.len() - 1) as f64).floor() as usize]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rank mismatch with DDSketch. quantile_value uses zero-based rank floor(q*(n-1)), but DDSketch::get_value_at_quantile targets one-based rank ceil(q*n). With n=10, q=0.95 the sketch targets index 9 (the max) while exact is index 8; on Pareto data those can differ several-fold, so the reported error far exceeds alpha even when the sketch is within guarantee. Inflates the low-N end of saturation curves.

let exact = quantile_value(truth, *q);
if exact == 0.0 {
continue;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NaN poisons the mean. DD wrappers answer unwrap_or(f64::NAN) when get_value_at_quantile returns None; (estimate - exact).abs() propagates NaN into sum. An empty merged sketch makes mean_relative_value_error NaN, and recommend_config's est <= target silently evaluates False.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4490788 (pushed on top, with tests).

🤖 Generated with Claude Code

let mut sum = 0.0;
let mut scored = 0usize;
for (q, estimate) in probes.iter().zip(answers) {
let exact = quantile_value(truth, *q);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only exact zeros are skipped. Tiny nonzero exact values below DDSketch's min indexable value land in the zero bucket, giving unbounded relative error (≈1 or 1e+N) that dominates the mean, though the guarantee excludes them. Consider skipping |exact| below the sketch's min indexable value.

continue;
}
sum += (estimate - exact).abs() / exact.abs();
scored += 1;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mean only, no max. DDSketch's guarantee is per-quantile (worst case), but this reports only a mean, unlike RankErrorGT's max_rank_err. One probe at 5% among 100 at 0.1% averages ~0.15%, so a 1% target is marked met while the guarantee is violated. Suggest adding max_relative_value_error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4490788 (pushed on top, with tests).

🤖 Generated with Claude Code

scored += 1;
}
let mut metrics = metrics_from([
("items", truth.len() as f64),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grid_points semantics diverge. RankErrorGT always reports 101; this reports the number of non-zero probes scored. A consumer checking for a full grid can't distinguish an incomplete run from excluded zero quantiles. Maybe a separate scored_points key.

Comment thread scripts/study_saturation.py Outdated
("quantile", "kll-percall", ["k=50", "k=200", "k=800"], "rank-error", "mean_rank_err"),
("quantile", "dd", ["alpha=0.005", "alpha=0.01", "alpha=0.02", "alpha=0.05"],
"rank-error", "mean_rank_err"),
"relative-value-error", "mean_relative_value_error"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeyError on all-zero data. RelativeValueErrorGT omits mean_relative_value_error when every exact quantile is zero, but error() does acc[metric] with no fallback, so one dd point on an all-zero stream aborts the whole saturation run.

/// A row answering **quantile**, scored by relative value error. DDSketch's
/// paper guarantees this metric, unlike rank error.
#[allow(clippy::too_many_arguments)]
pub(super) fn relative_value_quantile_row<T: ColumnItem>(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of quantile_row. relative_value_quantile_row is a line-for-line copy differing only in the ground-truth struct. Consider one quantile_row taking the comparator (G: GroundTruth<Probe=f64, Answer=f64>), or calling scored_row directly.

description: "asap_sketchlib::DDSketch: relative-error buckets, alpha in (0, 1)",
capability: Capability::Quantile,
comparator: Some("rank-error"),
comparator: Some("relative-value-error"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaks --comparator rank-error for dd. Replacing (rather than adding) the comparator means existing scripts passing rank-error for dd/lib or dd/oxide now fail, and the DD-vs-KLL rank-error tables in the docs can no longer be reproduced. Consider keeping both comparators.

@milindsrivastava1997
milindsrivastava1997 marked this pull request as ready for review October 7, 2026 13:01

@milindsrivastava1997 milindsrivastava1997 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Review findings

The review found eight issues. The first two can yield wrong DDSketch results without an explicit error; the remainder are robustness or cleanup concerns.

  1. DDSketch is never selected for quantile RAQEs. DDSketch rows provide mean_relative_value_error, while quantile RAQEs request mean_rank_err; missing metrics fail. Switching the RAQE to the new metric instead excludes KLL.
  2. DDSketch-lib truth includes unsupported values. asap_sketchlib::DDSketch skips values <= 0 and non-finite values, but RelativeValueErrorGT currently takes truth from the whole column. Example: [0, 0, 10, 20] at q=0.75 compares against 10 although the sketch targets about 20.
  3. Zero true values are skipped. A large estimate at an exact zero is unpenalized, so data containing many zeros can look too accurate.
  4. Metric may be absent. If every probe is skipped, mean_relative_value_error is absent and study_saturation.py indexes it directly.
  5. A NaN answer poisons the mean. An empty quantile answer becomes NaN, propagates to the reported metric, and later silently rejects the sketch.
  6. grid_points has inconsistent meaning. KLL reports all 101 probes; DDSketch reports only scored probes.
  7. Duplicated comparator truth/probe logic. RelativeValueErrorGT::{truth, probes} duplicates RankErrorGT.
  8. Duplicated row-builder logic. relative_value_quantile_row duplicates quantile_row.

No disposition has been applied yet; the next triage step is verification and scope assignment.

zzylol and others added 2 commits October 7, 2026 13:35
- max_relative_value_error beside the mean: DDSketch's bound holds per
  quantile, so a mean can pass while one quantile breaks it.
- A NaN answer (no value from the sketch) is counted in unanswered_points
  instead of turning the mean into NaN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DDSketch's bound holds per quantile, so the saturation curve, N_sat and the
recommendation read max_relative_value_error rather than the mean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report mean_relative_error for DDSketch (paper's relative-accuracy metric)

2 participants