Skip to main content

Density

Trait Density 

Source
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§

Source

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§

Source

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.

Examples found in repository?
examples/inverse_nearest_neighbor.rs (line 11)
9fn main() {
10    ContinuesSpaceSampler::new(
11        BiasedNearestNeighborDist::new(1.0, 1.0).chain(zero_one_cut_of),
12        [0.0, 0.0],
13        [4.0, 4.0],
14    )
15    .sample_iter(rng());
16}
Source

fn transform<F: FnMut(S) -> S + 'static>( self, func: F, ) -> DensityTransformer<S, Self>
where S: Clone, Self: Sized,

Each time DensityTransformer::probability is called, the given function func is applied to the input and the previously chosen instances of S.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn max<DD: Density<S>>(self, density: DD) -> DensityMax<S, Self, DD>
where Self: Sized,

Takes the maximum value of Densitys.

Source

fn min<DD: Density<S>>(self, density: DD) -> DensityMin<S, Self, DD>
where Self: Sized,

Takes the minimum value of Densitys.

Implementors§

Source§

impl Density<([f64; 2], [f64; 2])> for DensityCappedEdgeBiasedDistRatio

Source§

impl Density<([f64; 2], [f64; 2])> for DensityCappedEdgeDistRatio

Source§

impl Density<([f64; 2], [f64; 2])> for DensityHorizontalVertical

Source§

impl Density<([f64; 2], [f64; 2])> for PlanarityDensity

Source§

impl Density<[f64; 2]> for BiasedAverageDistance

Source§

impl Density<[f64; 2]> for BiasedNearestNeighborDist

Source§

impl Density<[f64; 2]> for BiasedNearestNeighborDistXIncreasing

Source§

impl Density<[f64; 2]> for DensityCone

Source§

impl Density<[f64; 2]> for DensitySlopedX

Source§

impl Density<[f64; 2]> for KNearestNeighborDist

Source§

impl Density<[f64; 2]> for StripHorizontalVertical

Source§

impl<S> Density<S> for DensityEqualProbability<S>

Source§

impl<S, D1, D2> Density<S> for DensityAdd<S, D1, D2>
where D1: Density<S>, D2: Density<S>,

Source§

impl<S, D1, D2> Density<S> for DensityDiv<S, D1, D2>
where D1: Density<S>, D2: Density<S>,

Source§

impl<S, D1, D2> Density<S> for DensityMax<S, D1, D2>
where D1: Density<S>, D2: Density<S>,

Source§

impl<S, D1, D2> Density<S> for DensityMin<S, D1, D2>
where D1: Density<S>, D2: Density<S>,

Source§

impl<S, D1, D2> Density<S> for DensityMul<S, D1, D2>
where D1: Density<S>, D2: Density<S>,

Source§

impl<S, D1, D2> Density<S> for DensitySub<S, D1, D2>
where D1: Density<S>, D2: Density<S>,

Source§

impl<S, D> Density<S> for DensityChain<S, D>
where D: Density<S>,

Source§

impl<S, D> Density<S> for DensityMultiAdd<S, D>
where D: Density<S>,

Source§

impl<S, D> Density<S> for DensityMultiDiv<S, D>
where D: Density<S>,

Source§

impl<S, D> Density<S> for DensityMultiMax<S, D>
where D: Density<S>,

Source§

impl<S, D> Density<S> for DensityMultiMin<S, D>
where D: Density<S>,

Source§

impl<S, D> Density<S> for DensityMultiMul<S, D>
where D: Density<S>,

Source§

impl<S, D> Density<S> for DensityMultiSub<S, D>
where D: Density<S>,

Source§

impl<S, D> Density<S> for DensityTransformer<S, D>
where S: Clone, D: Density<S>,

Source§

impl<S, P> Density<S> for PenaltyDensity<S, P>
where P: FnMut(&S, &S) -> bool,

Source§

impl<S, T: FnMut(&S, &[S]) -> f64> Density<S> for T