pub struct Mix<T, U, X>{ /* private fields */ }
Expand description
Mixture distributions.
§Examples
use rand_distr::{Distribution, Normal, Uniform};
use mix_distribution::Mix;
let mut rng = rand::thread_rng();
// Mixture of two distributions
let mix = {
let dists = vec![
Normal::new(0.0, 1.0).unwrap(),
Normal::new(1.0, 2.0).unwrap(),
];
let weights = &[2, 1];
Mix::new(dists, weights).unwrap()
};
mix.sample(&mut rng);
// Mixture of three distributions
let mix = {
let dists = vec![
Uniform::new_inclusive(0.0, 2.0),
Uniform::new_inclusive(1.0, 3.0),
Uniform::new_inclusive(2.0, 4.0),
];
let weights = &[2, 1, 3];
Mix::new(dists, weights).unwrap()
};
mix.sample(&mut rng);
// From iterator over (distribution, weight) pairs
let mix = Mix::with_zip(vec![
(Uniform::new_inclusive(0, 2), 2),
(Uniform::new_inclusive(1, 3), 1),
])
.unwrap();
mix.sample(&mut rng);
Implementations§
Source§impl<T, U, X> Mix<T, U, X>
impl<T, U, X> Mix<T, U, X>
Sourcepub fn new<I, J>(dists: I, weights: J) -> Result<Self, WeightedError>where
I: IntoIterator<Item = T>,
J: IntoIterator,
J::Item: SampleBorrow<X>,
X: for<'a> AddAssign<&'a X> + Clone + Default,
pub fn new<I, J>(dists: I, weights: J) -> Result<Self, WeightedError>where
I: IntoIterator<Item = T>,
J: IntoIterator,
J::Item: SampleBorrow<X>,
X: for<'a> AddAssign<&'a X> + Clone + Default,
Creates a new Mix
.
dists
and weights
must have the same length.
Propagates errors from rand_dist::weighted::WeightedIndex::new()
.
Sourcepub fn with_zip<W>(
dists_weights: impl IntoIterator<Item = (T, W)>,
) -> Result<Self, WeightedError>
pub fn with_zip<W>( dists_weights: impl IntoIterator<Item = (T, W)>, ) -> Result<Self, WeightedError>
Creats a new Mix
with the given iterator over (distribution, weight) pairs.
Propagates errors from rand_dist::weighted::WeightedIndex::new()
.
Trait Implementations§
Auto Trait Implementations§
impl<T, U, X> Freeze for Mix<T, U, X>
impl<T, U, X> RefUnwindSafe for Mix<T, U, X>where
X: RefUnwindSafe,
<X as SampleUniform>::Sampler: RefUnwindSafe,
U: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, U, X> Send for Mix<T, U, X>
impl<T, U, X> Sync for Mix<T, U, X>
impl<T, U, X> Unpin for Mix<T, U, X>
impl<T, U, X> UnwindSafe for Mix<T, U, X>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more