[][src]Struct genevo::random::WeightedDistribution

pub struct WeightedDistribution<'a, T> where
    T: 'a + AsScalar
{ /* fields omitted */ }

The WeightedDistribution is used to select values proportional to their weighted values.

The values in a WeightedDistribution must have a scalar representation. Thus their types must implement the genetic::AsScalar trait. The weights of the values are calculated from their scalar representation.

Methods

impl<'a, T> WeightedDistribution<'a, T> where
    T: 'a + AsScalar
[src]

pub fn from_scalar_values(values: &'a [T]) -> Self[src]

Constructs a new instance of WeightedDistribution for the given slice of values.

pub fn select(&self, pointer: f64) -> usize[src]

Selects a value proportional to its weight and returns its index.

The pointer must be a float between 0 und the sum of the weights of all values. Usually the pointer is chosen uniformly at random.

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

Returns the sum of the weights of all values in this WeightedDistribution instance.

The sum is calculated from the scalar values of the slice that was used to create this WeightedDistribution instance.

pub fn value(&self, index: usize) -> &T[src]

Returns a reference to the value at the given index.

Trait Implementations

impl<'a, T: PartialEq> PartialEq<WeightedDistribution<'a, T>> for WeightedDistribution<'a, T> where
    T: 'a + AsScalar
[src]

impl<'a, T: Clone> Clone for WeightedDistribution<'a, T> where
    T: 'a + AsScalar
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a, T: Debug> Debug for WeightedDistribution<'a, T> where
    T: 'a + AsScalar
[src]

Auto Trait Implementations

impl<'a, T> Send for WeightedDistribution<'a, T> where
    T: Sync

impl<'a, T> Sync for WeightedDistribution<'a, T> where
    T: Sync

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

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

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

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.

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

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

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