Struct average::WeightedMean[][src]

pub struct WeightedMean { /* fields omitted */ }

Estimate the weighted and unweighted arithmetic mean of a sequence of numbers (“population”).

Example

use average::WeightedMean;

let a: WeightedMean = (1..6).zip(1..6)
    .map(|(x, w)| (f64::from(x), f64::from(w))).collect();
println!("The weighted mean is {}.", a.mean());

Implementations

impl WeightedMean[src]

pub fn new() -> WeightedMean[src]

Create a new weighted and unweighted mean estimator.

pub fn add(&mut self, sample: f64, weight: f64)[src]

Add an observation sampled from the population.

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

Determine whether the sample is empty.

Might be a false positive if the sum of weights is zero.

pub fn sum_weights(&self) -> f64[src]

Return the sum of the weights.

Returns 0 for an empty sample.

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

Estimate the weighted mean of the population.

Returns 0 for an empty sample.

Trait Implementations

impl Clone for WeightedMean[src]

impl Debug for WeightedMean[src]

impl Default for WeightedMean[src]

impl<'de> Deserialize<'de> for WeightedMean[src]

impl<'a> FromIterator<&'a (f64, f64)> for WeightedMean[src]

impl FromIterator<(f64, f64)> for WeightedMean[src]

impl Merge for WeightedMean[src]

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

Merge another sample into this one.

Example

use average::{WeightedMean, Merge};

let weighted_sequence: &[(f64, f64)] = &[
    (1., 0.1), (2., 0.2), (3., 0.3), (4., 0.4), (5., 0.5),
    (6., 0.6), (7., 0.7), (8., 0.8), (9., 0.9)];
let (left, right) = weighted_sequence.split_at(3);
let avg_total: WeightedMean = weighted_sequence.iter().collect();
let mut avg_left: WeightedMean = left.iter().collect();
let avg_right: WeightedMean = right.iter().collect();
avg_left.merge(&avg_right);
assert!((avg_total.mean() - avg_left.mean()).abs() < 1e-15);

impl Serialize for WeightedMean[src]

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<S, T> Cast<T> for S where
    T: Conv<S>, 
[src]

impl<S, T> CastFloat<T> for S where
    T: ConvFloat<S>, 
[src]

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

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

impl<T> Pointable for T

type Init = T

The type for initializers.

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.