Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/geo_filters/evaluation/accuracy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

![geo_diff_7](./accuracy/geo_diff_7.png)

![geo_diff_10](./accuracy/geo_diff_10.png)

![geo_diff_13](./accuracy/geo_diff_13.png)

## Geometric Distinct Count
Expand Down
7 changes: 6 additions & 1 deletion crates/geo_filters/evaluation/accuracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use once_cell::sync::Lazy;
use regex::{Captures, Regex};
use std::sync::Arc;

use geo_filters::diff_count::{GeoDiffCount, GeoDiffCount13, GeoDiffCount7};
use geo_filters::diff_count::{GeoDiffCount, GeoDiffCount10, GeoDiffCount13, GeoDiffCount7};
use geo_filters::distinct_count::{GeoDistinctCount, GeoDistinctCount13, GeoDistinctCount7};
use geo_filters::evaluation::hll::{Hll, Hll14, Hll8, VariableHllConfig};
use geo_filters::evaluation::simulation::{
Expand All @@ -30,6 +30,7 @@ fn main() {
#[clap(after_help = "\x1b[1;4;37mConfigurations:\x1b[0;37m
geo_diff/BUCKET_TYPE/b=N/bytes=N/msb=N
geo_diff_7
geo_diff_10
geo_diff_13
geo_distinct/BUCKET_TYPE/b=N/bytes=N/msb=N
geo_distinct_7
Expand All @@ -44,6 +45,7 @@ fn main() {
#[clap(after_long_help = "\x1b[1;4;37mConfigurations:\x1b[0;37m
geo_diff/BUCKET_TYPE/b=N/bytes=N/msb=N Diff count with the given parameters
geo_diff_7 Predefined configuration for b=7
geo_diff_10 Predefined configuration for b=10
geo_diff_13 Predefined configuration for b=13

geo_distinct/BUCKET_TYPE/b=N/bytes=N/msb=N Distinct count with the given parameters
Expand Down Expand Up @@ -180,6 +182,9 @@ static SIMULATION_CONFIG_FROM_STR: Lazy<Vec<SimulationConfigParser>> = Lazy::new
SimulationConfigParser::new(r#"geo_diff_7"#, |_| {
Box::new(|| Box::new(GeoDiffCount7::default()))
}),
SimulationConfigParser::new(r#"geo_diff_10"#, |_| {
Box::new(|| Box::new(GeoDiffCount10::default()))
}),
SimulationConfigParser::new(r#"geo_diff_13"#, |_| {
Box::new(|| Box::new(GeoDiffCount13::default()))
}),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/geo_filters/evaluation/accuracy/geo_diff_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/geo_filters/evaluation/accuracy/geo_diff_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/geo_filters/evaluation/accuracy/geo_distinct_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/geo_filters/evaluation/accuracy/geo_distinct_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/geo_filters/evaluation/accuracy/hll_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified crates/geo_filters/evaluation/accuracy/hll_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions crates/geo_filters/scripts/generate-accuracy-plots
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ set -eu
plots_dir=evaluation/accuracy

cargo run --release --features evaluation --bin accuracy -- \
-o accuracy.csv -n 10000 -m 5000000 geo_diff_{7,13} geo_distinct_{7,13} hll_{8,14} "$@"
-o accuracy.csv -n 10000 -m 5000000 geo_diff_{7,10,13} geo_distinct_{7,13} hll_{8,14} "$@"

evaluation/plot-accuracy.r accuracy.csv

rm -f "$plots_dir"/*

idx=0
for c in geo_diff_{7,13} geo_distinct_{7,13} hll_{8,14}; do
for c in geo_diff_{7,10,13} geo_distinct_{7,13} hll_{8,14}; do
Comment on lines +10 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to include this configuration the geo distinct plots here too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mmm. I don't need those yet...
We could do it in a separate run (it was burning quite a lot of my CPU for quite some time to rerun all these evaluations)

echo "plot $c"
convert -density 300 accuracy.pdf[$idx] -resize 1024x1024 -alpha remove -alpha off "$plots_dir/$c.png"
idx=$(($idx + 1))
Expand Down
5 changes: 4 additions & 1 deletion crates/geo_filters/src/diff_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ mod config;
mod sim_hash;

use bitvec::*;
pub use config::{GeoDiffConfig13, GeoDiffConfig7};
pub use config::{GeoDiffConfig10, GeoDiffConfig13, GeoDiffConfig7};
pub use sim_hash::SimHash;

/// Diff count filter with a relative error standard deviation of ~0.125.
pub type GeoDiffCount7<'a> = GeoDiffCount<'a, GeoDiffConfig7>;

/// Diff count filter with a relative error standard deviation of ~0.04.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if copilot read the evals to get the relative error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know. But you can see from the graphs that it is slightly above 0.04

pub type GeoDiffCount10<'a> = GeoDiffCount<'a, GeoDiffConfig10>;

/// Diff count filter with a relative error standard deviation of ~0.015.
pub type GeoDiffCount13<'a> = GeoDiffCount<'a, GeoDiffConfig13>;

Expand Down
31 changes: 31 additions & 0 deletions crates/geo_filters/src/diff_count/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ use crate::Diff;
//
pub type GeoDiffConfig7<H = UnstableDefaultBuildHasher> = FixedConfig<Diff, u16, 7, 112, 12, H>;

/// Diff count configuration with a relative error standard deviation of ~0.04.
//
// Precision evaluation:
//
// scripts/accuracy -n 5000 geo_diff/u32/b=10/bytes={768,832,896,960,1024}/msb=64
//
// Most-significant bytes evaluation:
//
// scripts/accuracy -n 5000 geo_diff/u32/b=10/bytes=896/msb={32,48,64,80,96,128}
//
pub type GeoDiffConfig10<H = UnstableDefaultBuildHasher> = FixedConfig<Diff, u32, 10, 896, 64, H>;

/// Diff count configuration with a relative error standard deviation of ~0.015.
//
// Precision evaluation:
Expand Down Expand Up @@ -187,6 +199,25 @@ mod tests {
);
}

#[test]
fn test_estimation_lut_10() {
let c = GeoDiffConfig10::<UnstableDefaultBuildHasher>::default();
let err = (0..5000)
.step_by(10)
.map(|i| {
let a = c.expected_items(i); // uses estimation lookup
let b = estimate_count(c.phi_f64(), i as f64, expected_diff_buckets).0 as f32;
(a - b).abs() / a.max(1.0)
})
.reduce(f32::max)
.expect("a value");
let bound = 0.00035;
assert!(
(err - bound).abs() < 0.5e-4,
"found max error {err}, expected {bound}"
);
}

#[test]
fn test_estimation_lut_13() {
let c = GeoDiffConfig13::<UnstableDefaultBuildHasher>::default();
Expand Down