Struct Resampler

Source
pub struct Resampler<'a, R: Rng, W: Float> { /* private fields */ }
Expand description

The Resampler can be turned into an Iterator to contineously pull sample indices

§Example

use wheel_resample::Resampler;

let mut rng = rand::thread_rng();
let weights = [0.1, 0.2, 0.3, 0.8];
let resampler = Resampler::new(&mut rng, &weights);

let population = vec![1, 2, 3, 4];
let samples = resampler.into_iter().take(4).map(|i| population[i].clone()).collect::<Vec<u32>>();

// Make sure we got four samples
assert_eq!(samples.len(), 4);

// Make sure all samples come from the population
assert!(samples.iter().all(|s| population.contains(s)));

Implementations§

Source§

impl<'a, R: Rng, W: Float> Resampler<'a, R, W>

Source

pub fn new(rng: &'a mut R, weights: &'a [W]) -> Self

Create Resampler instance from random generator and weights

Trait Implementations§

Source§

impl<'a, R: Rng, W: SampleUniform + Float> IntoIterator for Resampler<'a, R, W>

Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = ResampleIterator<'a, R, W>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a, R, W> Freeze for Resampler<'a, R, W>

§

impl<'a, R, W> RefUnwindSafe for Resampler<'a, R, W>

§

impl<'a, R, W> Send for Resampler<'a, R, W>
where R: Send, W: Sync,

§

impl<'a, R, W> Sync for Resampler<'a, R, W>
where R: Sync, W: Sync,

§

impl<'a, R, W> Unpin for Resampler<'a, R, W>

§

impl<'a, R, W> !UnwindSafe for Resampler<'a, R, W>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V