Struct genevo::random::WeightedDistribution
source · [−]pub struct WeightedDistribution<'a, T> where
T: 'a + AsScalar, { /* private fields */ }
Expand description
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.
Implementations
sourceimpl<'a, T> WeightedDistribution<'a, T> where
T: 'a + AsScalar,
impl<'a, T> WeightedDistribution<'a, T> where
T: 'a + AsScalar,
sourcepub fn from_scalar_values(values: &'a [T]) -> Self
pub fn from_scalar_values(values: &'a [T]) -> Self
Constructs a new instance of WeightedDistribution
for the given slice
of values.
sourcepub fn select(&self, pointer: f64) -> usize
pub fn select(&self, pointer: f64) -> usize
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.
Trait Implementations
sourceimpl<'a, T: Clone> Clone for WeightedDistribution<'a, T> where
T: 'a + AsScalar,
impl<'a, T: Clone> Clone for WeightedDistribution<'a, T> where
T: 'a + AsScalar,
sourcefn clone(&self) -> WeightedDistribution<'a, T>
fn clone(&self) -> WeightedDistribution<'a, T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a, T: Debug> Debug for WeightedDistribution<'a, T> where
T: 'a + AsScalar,
impl<'a, T: Debug> Debug for WeightedDistribution<'a, T> where
T: 'a + AsScalar,
sourceimpl<'a, T: PartialEq> PartialEq<WeightedDistribution<'a, T>> for WeightedDistribution<'a, T> where
T: 'a + AsScalar,
impl<'a, T: PartialEq> PartialEq<WeightedDistribution<'a, T>> for WeightedDistribution<'a, T> where
T: 'a + AsScalar,
sourcefn eq(&self, other: &WeightedDistribution<'a, T>) -> bool
fn eq(&self, other: &WeightedDistribution<'a, T>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &WeightedDistribution<'a, T>) -> bool
fn ne(&self, other: &WeightedDistribution<'a, T>) -> bool
This method tests for !=
.
impl<'a, T> StructuralPartialEq for WeightedDistribution<'a, T> where
T: 'a + AsScalar,
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for WeightedDistribution<'a, T> where
T: RefUnwindSafe,
impl<'a, T> Send for WeightedDistribution<'a, T> where
T: Sync,
impl<'a, T> Sync for WeightedDistribution<'a, T> where
T: Sync,
impl<'a, T> Unpin for WeightedDistribution<'a, T>
impl<'a, T> UnwindSafe for WeightedDistribution<'a, T> where
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more