2 releases

0.2.5 Aug 19, 2023
0.2.4 Aug 19, 2023

#2337 in Algorithms

Download history 9/week @ 2024-09-21 18/week @ 2024-09-28 33/week @ 2024-10-05 15/week @ 2024-10-12 55/week @ 2024-10-19 76/week @ 2024-10-26 92/week @ 2024-11-02

240 downloads per month

Apache-2.0

25KB
545 lines

T-Digest algorithm in rust

Build Status codecov

This implementation is following Facebook folly's implementation

Installation

Add this to your Cargo.toml:

[dependencies]
tdigest = "0.2"

then you are good to go. If you are using Rust 2015 you have to extern crate tdigest to your crate root as well.

Example

use tdigest::TDigest;

let t = TDigest::new_with_size(100);
let values: Vec<f64> = (1..=1_000_000).map(f64::from).collect();
let t = t.merge_sorted(values);
let ans = t.estimate_quantile(0.99);
let expected: f64 = 990_000.0;
let percentage: f64 = (expected - ans).abs() / expected;

assert!(percentage < 0.01);

lib.rs:

T-Digest algorithm in rust

Installation

Add this to your Cargo.toml:

[dependencies]
tdigest = "0.2"

then you are good to go. If you are using Rust 2015 you have to extern crate tdigest to your crate root as well.

Example

use tdigest::TDigest;

let t = TDigest::new_with_size(100);
let values: Vec<f64> = (1..=1_000_000).map(f64::from).collect();

let t = t.merge_sorted(values);

let ans = t.estimate_quantile(0.99);
let expected: f64 = 990_000.0;

let percentage: f64 = (expected - ans).abs() / expected;
assert!(percentage < 0.01);

Dependencies

~185–410KB