pub trait Density<S> {
// Required method
fn probability(&mut self, s: &S, c: &[S]) -> f64;
// Provided methods
fn chain<F: FnMut(f64) -> f64 + 'static>(
self,
func: F,
) -> DensityChain<S, Self>
where Self: Sized { ... }
fn transform<F: FnMut(S) -> S + 'static>(
self,
func: F,
) -> DensityTransformer<S, Self>
where S: Clone,
Self: Sized { ... }
fn add<DD: Density<S>>(self, density: DD) -> DensityAdd<S, Self, DD>
where Self: Sized { ... }
fn sub<DD: Density<S>>(self, density: DD) -> DensitySub<S, Self, DD>
where Self: Sized { ... }
fn mul<DD: Density<S>>(self, density: DD) -> DensityMul<S, Self, DD>
where Self: Sized { ... }
fn div<DD: Density<S>>(self, density: DD) -> DensityDiv<S, Self, DD>
where Self: Sized { ... }
fn max<DD: Density<S>>(self, density: DD) -> DensityMax<S, Self, DD>
where Self: Sized { ... }
fn min<DD: Density<S>>(self, density: DD) -> DensityMin<S, Self, DD>
where Self: Sized { ... }
}Expand description
Describes for each instance of S the probability to take an instance of S if it is
considered.
For sampling instances of S from a set of elements according to the probabaility described by
this trait, sampling::Sampler and one of its implementation sampling::DiscreteSpaceSampler,
sampling::UniqueDiscreteSpaceSampler can be used.
The probabaility over each element must not necessarily add up to one. The implemented
sampling::Sampler correct this, but the probabilities should not be negative.
Required Methods§
Sourcefn probability(&mut self, s: &S, c: &[S]) -> f64
fn probability(&mut self, s: &S, c: &[S]) -> f64
Defines the probability of each instance s of S. This probability can be dependend on
the previously chosen instances of S and are passed with c.
Provided Methods§
Sourcefn chain<F: FnMut(f64) -> f64 + 'static>(self, func: F) -> DensityChain<S, Self>where
Self: Sized,
fn chain<F: FnMut(f64) -> f64 + 'static>(self, func: F) -> DensityChain<S, Self>where
Self: Sized,
Applies the given function func to each probability computed by Density::probability.
Sourcefn transform<F: FnMut(S) -> S + 'static>(
self,
func: F,
) -> DensityTransformer<S, Self>
fn transform<F: FnMut(S) -> S + 'static>( self, func: F, ) -> DensityTransformer<S, Self>
Each time DensityTransformer::probability is called, the given function func is
applied to the input and the previously chosen instances of S.
Sourcefn add<DD: Density<S>>(self, density: DD) -> DensityAdd<S, Self, DD>where
Self: Sized,
fn add<DD: Density<S>>(self, density: DD) -> DensityAdd<S, Self, DD>where
Self: Sized,
Add Densitys.
Every value of the first and second densities are added together.
Sourcefn sub<DD: Density<S>>(self, density: DD) -> DensitySub<S, Self, DD>where
Self: Sized,
fn sub<DD: Density<S>>(self, density: DD) -> DensitySub<S, Self, DD>where
Self: Sized,
Subtract Densitys.
Every value of the second density is subtracted from the value of the first density.
Sourcefn mul<DD: Density<S>>(self, density: DD) -> DensityMul<S, Self, DD>where
Self: Sized,
fn mul<DD: Density<S>>(self, density: DD) -> DensityMul<S, Self, DD>where
Self: Sized,
Multiplies Densitys.
Every value of the first density is multiplied with the value of the second density.
Sourcefn div<DD: Density<S>>(self, density: DD) -> DensityDiv<S, Self, DD>where
Self: Sized,
fn div<DD: Density<S>>(self, density: DD) -> DensityDiv<S, Self, DD>where
Self: Sized,
Divides Densitys.
Every value of the first density is divided by the value of the second density.