Crates.io | streamhist |
lib.rs | streamhist |
version | 0.0.1-alpha.3 |
source | src |
created_at | 2021-01-09 21:59:41.317349 |
updated_at | 2021-02-05 23:06:53.441857 |
description | Implementation of streaming histogram |
homepage | https://github.com/jettify/streamhist |
repository | https://github.com/jettify/streamhist.git |
max_upload_size | |
id | 337236 |
size | 45,634 |
A rust implementation of a streaming centroid histogram algorithm found in Streaming Parallel Decision Trees paper by Ben-Haim/Tom-Tov.
use rand::SeedableRng;
use rand_distr::{Distribution, Normal};
use rand_isaac::Isaac64Rng;
use streamhist::StreamingHistogram;
fn main() {
let mut rng = Isaac64Rng::seed_from_u64(42);
let dist = Normal::new(2.0, 3.0).unwrap();
let mut hist = StreamingHistogram::new(32);
let maxn = 10000;
let vals: Vec<f64> = (0..maxn).map(|_| dist.sample(&mut rng)).collect();
for v in vals.iter() {
hist.insert_one(*v);
}
println!("------------------------------------------------");
println!("Est Mean {:?}", hist.mean().unwrap());
println!("Est Var {:?}", hist.var().unwrap());
println!("Est Median {:?}", hist.median().unwrap());
println!("Est Count vals <= 2.0 {:?}", hist.count_less_then_eq(2.0));
println!("Est quantile {:?}", hist.quantile(0.75).unwrap());
println!("Min {:?}", hist.min().unwrap());
println!("Max {:?}", hist.max().unwrap());
println!("Count {:?}", hist.count());
println!("------------------------------------------------");
assert_eq!(hist.count(), maxn);
}
Licensed under the Apache License, Version 2.0