Struct streamhist::StreamingHistogram[][src]

pub struct StreamingHistogram { /* fields omitted */ }

Implementations

impl StreamingHistogram[src]

pub fn new(max_centroids: u16) -> StreamingHistogram[src]

Creates new StreamingHistogram

  • max_centroids indicates how many centroids should be used to estimate statistics, more centroids more accurate estimation. Each centroids stroes f64 and u64 and uses about 16 bytes of space.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
assert_eq!(hist.count(), 0)

Panics

The function panics if the max_centroids is zero.

use streamhist::StreamingHistogram;
// panics on empty histogram
let mut hist = StreamingHistogram::new(0);

pub fn clear(&mut self)[src]

Clearas all state like centroids and restests all counts.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
hist.insert_one(10.0);
assert_eq!(hist.count(), 1);
hist.clear();
assert_eq!(hist.count(), 0)

pub fn is_empty(&self) -> bool[src]

Returns true if this histogram has no recorded values.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
assert!(hist.is_empty(), 1);

pub fn count(&self) -> u64[src]

Returns number of items observed by histogram.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
assert_eq!(hist.count(), 0);
hist.insert_one(10.0);
assert_eq!(hist.count(), 1)

pub fn max(&self) -> Option<f64>[src]

Returns max value ever observed by histogram.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
assert_eq!(hist.max(), None);
hist.insert_one(10.0);
assert!(hist.max().unwrap() > 9.0);

pub fn min(&self) -> Option<f64>[src]

Returns min value ever observed by histogram.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
assert_eq!(hist.min(), None);
hist.insert_one(10.0);
assert!(hist.min().unwrap() > 9.0);

pub fn insert_one(&mut self, value: f64)[src]

pub fn insert(&mut self, value: f64, count: u64)[src]

pub fn mean(&self) -> Option<f64>[src]

Returns estimate of mean value using centroids.

Note, it is possible to compute exact mean value over data stream using itertive algorithm. Estimate with centroids is resonably accurate try with your distribution.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
hist.insert(10.0, 1);
assert!(hist.mean().unwrap() > 9.0);

pub fn var(&self) -> Option<f64>[src]

Returns estimate of variance value using centroids.

Note, it is possible to compute exact mean value over data stream using itertive algorithm. Estimate with centroids is resonably accurate try with your distribution.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
hist.insert(10.0, 1);
hist.insert(15.0, 1);
assert!(hist.var().unwrap() < 7.0);

pub fn sum(&self, value: f64) -> u64[src]

pub fn quantile(&self, q: f64) -> Option<f64>[src]

Returns estimate of quantile. Input defined from 0.0 to 1.0, otherwise function returns None.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
hist.insert(5.0, 1);
hist.insert(10.0, 1);
hist.insert(15.0, 1);
// same as median
assert!((hist.quantile(0.5).unwrap() - 10.0).abs() < 0.00001);

pub fn median(&self) -> Option<f64>[src]

Returns estimate of median.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
hist.insert(5.0, 1);
hist.insert(10.0, 1);
hist.insert(15.0, 1);
assert!((hist.median().unwrap() - 10.0).abs() < 0.00001);

pub fn merge(&mut self, other: &Self)[src]

Merge second histogram into this one.

Example

use streamhist::StreamingHistogram;
let mut one = StreamingHistogram::new(32);
let mut two = StreamingHistogram::new(32);
one.insert(5.0, 1);
one.insert(10.0, 1);
one.insert(15.0, 1);
two.insert(20.0, 1);
two.insert(25.0, 1);
one.merge(&two);
assert_eq!(one.count(), 5);

pub fn count_less_then_eq(&self, value: f64) -> u64[src]

Returns estimate number of values observed less then or equal then specified.

Example

use streamhist::StreamingHistogram;
let mut hist = StreamingHistogram::new(32);
hist.insert(5.0, 1);
hist.insert(10.0, 1);
hist.insert(15.0, 1);
assert_eq!(hist.count_less_then_eq(100.0), 3);
assert_eq!(hist.count_less_then_eq(-100.0), 0);

Trait Implementations

impl Clone for StreamingHistogram[src]

impl Debug for StreamingHistogram[src]

impl Default for StreamingHistogram[src]

fn default() -> StreamingHistogram[src]

Creates new StreamingHistogram with default max_centroids=64

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.