INNER CODE UNIT · Rust

new

TeamAtomECS/AtomECS · src/atom_sources/mod.rs:132

    pub fn new(values: Vec<f64>, weights: Vec<f64>) -> Self {
        WeightedProbabilityDistribution {
            values,
            weighted_index: WeightedIndex::new(&weights).unwrap(),
        }
    }
}
impl Distribution<f64> for WeightedProbabilityDistribution {
    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64 {
        let index = self.weighted_index.sample(rng);
        self.values[index]
    }
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…