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(f64::from).collect(); println!("The mean is {}.", a.mean());
Methods
impl Mean
[src]
impl Mean
pub fn new() -> Mean
[src]
pub fn new() -> Mean
Create a new mean estimator.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Determine whether the sample is empty.
pub fn mean(&self) -> f64
[src]
pub fn mean(&self) -> f64
Estimate the mean of the population.
Returns 0 for an empty sample.
pub fn len(&self) -> u64
[src]
pub fn len(&self) -> u64
Return the sample size.
Trait Implementations
impl Debug for Mean
[src]
impl Debug for Mean
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for Mean
[src]
impl Clone for Mean
fn clone(&self) -> Mean
[src]
fn clone(&self) -> Mean
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl Default for Mean
[src]
impl Default for Mean
impl Estimate for Mean
[src]
impl Estimate for Mean
fn add(&mut self, sample: f64)
[src]
fn add(&mut self, sample: f64)
Add an observation sampled from the population.
fn estimate(&self) -> f64
[src]
fn estimate(&self) -> f64
Estimate the statistic of the population.
impl Merge for Mean
[src]
impl Merge for Mean
fn merge(&mut self, other: &Mean)
[src]
fn merge(&mut self, other: &Mean)
Merge another sample into this one.
Example
use average::{Mean, Merge}; 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().collect(); let mut avg_left: Mean = left.iter().collect(); let avg_right: Mean = right.iter().collect(); avg_left.merge(&avg_right); assert_eq!(avg_total.mean(), avg_left.mean());
impl FromIterator<f64> for Mean
[src]
impl FromIterator<f64> for Mean
fn from_iter<T>(iter: T) -> Mean where
T: IntoIterator<Item = f64>,
[src]
fn from_iter<T>(iter: T) -> Mean where
T: IntoIterator<Item = f64>,
Creates a value from an iterator. Read more
impl<'a> FromIterator<&'a f64> for Mean
[src]
impl<'a> FromIterator<&'a f64> for Mean