Repository navigation
Report DDSketch relative value error - #164
milindsrivastava1997 merged 6 commits into
Conversation
milindsrivastava1997
left a comment
There was a problem hiding this comment.
Code review findings (inline below). Two findings fall outside the diff:
rqe-optimizer/examples/small_problem.rs:170: optimizer silently drops DD. DD rows now report onlymean_relative_value_error, but every quantile RAQE still asks formean_rank_err.accuracy_ok_fortreats a missing metric as failing, so after regenerating costs withexport_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.scripts/recommend_config.py:27: stale rationale. The docstring andgrid_pointlogic 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 listsmean_rank_errfor dd.
🤖 Generated with Claude Code
| } | ||
|
|
||
| fn quantile_value(sorted: &[f64], q: f64) -> f64 { | ||
| sorted[(q * (sorted.len() - 1) as f64).floor() as usize] |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Fixed in 4490788 (pushed on top, with tests).
🤖 Generated with Claude Code
| scored += 1; | ||
| } | ||
| let mut metrics = metrics_from([ | ||
| ("items", truth.len() as f64), |
There was a problem hiding this comment.
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.
| ("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"), |
There was a problem hiding this comment.
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>( |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
- DDSketch is never selected for quantile RAQEs. DDSketch rows provide
mean_relative_value_error, while quantile RAQEs requestmean_rank_err; missing metrics fail. Switching the RAQE to the new metric instead excludes KLL. - DDSketch-lib truth includes unsupported values.
asap_sketchlib::DDSketchskips values<= 0and non-finite values, butRelativeValueErrorGTcurrently takes truth from the whole column. Example:[0, 0, 10, 20]atq=0.75compares against 10 although the sketch targets about 20. - Zero true values are skipped. A large estimate at an exact zero is unpenalized, so data containing many zeros can look too accurate.
- Metric may be absent. If every probe is skipped,
mean_relative_value_erroris absent andstudy_saturation.pyindexes it directly. - A NaN answer poisons the mean. An empty quantile answer becomes NaN, propagates to the reported metric, and later silently rejects the sketch.
grid_pointshas inconsistent meaning. KLL reports all 101 probes; DDSketch reports only scored probes.- Duplicated comparator truth/probe logic.
RelativeValueErrorGT::{truth, probes}duplicatesRankErrorGT. - Duplicated row-builder logic.
relative_value_quantile_rowduplicatesquantile_row.
No disposition has been applied yet; the next triage step is verification and scope assignment.
- 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>
Closes #162
Summary
mean_relative_value_errorthrough the DDSketch-only comparatorValidation
cargo test --workspace --no-default-featurespython3 scripts/test_recommend_config.pypython3 scripts/test_export_autosketch_eval_table.pypython3 scripts/test_study_saturation.pyBenchmark artifact regeneration is pending access to the ignored source outputs / benchmark host.