[−][src]Struct stream_histogram::Histogram
A Histogram struct include a double linklist and some attributes for manage data. using linkedList for fast insert and merge items in a sorted data structure
Implementations
impl Histogram
[src]
pub fn new(max: usize) -> Histogram
[src]
Histogram is a data structure for calculation some statistic value from stream data, for example the mean、max、min、 q-quantiles and cumulative distribution etc. You must set the bucket number first, greater bucket number will bring more precision, but also bring more load for process. Default is 10, any number less than 10 will reset to default.
Examples
use crate::histogram::Histogram; let mut histogram = Histogram::new(20); for i in 1..=100000 { histogram.add(i as f64); }
pub fn add(&mut self, number: f64)
[src]
add method update histogram data structure from stream each time update a new value current value must be f64 after update, the inner process will check the bucket number and merge two smallest gap bucket into one bucket.
Examples
use crate::histogram::Histogram; let mut histogram = Histogram::new(20); for i in 1..=100000 { histogram.add(i as f64); }
pub fn quantile(&self, q: f64) -> Option<f64>
[src]
q-quantiles are values that partition a finite set of values into q subsets of (nearly) equal sizes. for more detail please check wikipedia
pub fn cdf(&mut self, x: f64) -> Option<f64>
[src]
Cumulative distribution function(aka: cdf) returns the value of the cumulative distribution at value x. for more detail, please check wikipedia
pub fn mean(&self) -> Option<f64>
[src]
pub fn variance(&self) -> Option<f64>
[src]
pub fn to_string(&self) -> String
[src]
to_string method print the result in a simple visulazation style, each line print the bucket and the size in a dot mode.
Examples
use rand::distributions::{Normal, Distribution}; use crate::histogram::Histogram; let normal = Normal::new(10.0, 10.0); let mut histogram = Histogram::new(20); for _i in 1..=100000 { let v = normal.sample(&mut rand::thread_rng()); histogram.add(v as f64); } println!("{}", histogram.to_string());
pub fn report(&self) -> Option<HistogramReport>
[src]
return a report from current histogram
Example
use crate::histogram::Histogram; let mut histogram = Histogram::new(10); for i in 1..=100 { histogram.add(i as f64); } if let Some(report) = histogram.report(){ println!("{:?}", report); }
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Histogram
[src]
impl !Send for Histogram
[src]
impl !Sync for Histogram
[src]
impl Unpin for Histogram
[src]
impl UnwindSafe for Histogram
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,