Struct average::Mean [] [src]

pub struct Mean { /* fields omitted */ }

Estimate the arithmetic mean of a sequence of numbers ("population").

Example

use average::Mean;

let a: Mean = (1..6).map(Into::into).collect();
println!("The mean is {}.", a.mean());

Methods

impl Mean
[src]

Create a new mean estimator.

Add an observation sampled from the population.

Determine whether the sample is empty.

Estimate the mean of the population.

Returns 0 for an empty sample.

Return the sample size.

Merge another sample into this one.

Example

use average::Mean;

let sequence: &[f64] = &[1., 2., 3., 4., 5., 6., 7., 8., 9.];
let (left, right) = sequence.split_at(3);
let avg_total: Mean = sequence.iter().map(|x| *x).collect();
let mut avg_left: Mean = left.iter().map(|x| *x).collect();
let avg_right: Mean = right.iter().map(|x| *x).collect();
avg_left.merge(&avg_right);
assert_eq!(avg_total.mean(), avg_left.mean());

Trait Implementations

impl Debug for Mean
[src]

Formats the value using the given formatter.

impl Clone for Mean
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Default for Mean
[src]

Returns the "default value" for a type. Read more

impl FromIterator<f64> for Mean
[src]

Creates a value from an iterator. Read more