Function smartnoise_runtime::utilities::create_subset [−][src]
pub fn create_subset<T>(
set: &[T],
weights: &[f64],
k: usize,
_enforce_constant_time: bool
) -> Result<Vec<T>> where
T: Clone,
Accepts set and element weights and returns a subset of size k (without replacement).
Weights are (after being normalized) the probability of drawing each element on the first draw (they sum to 1) Based on Algorithm A from Raimidis PS, Spirakis PG (2006). “Weighted random sampling with a reservoir.”
Arguments
set
- Set of elements for which you would like to create a subsetweights
- Weight for each element in the set, corresponding to the probability it is drawn on the first draw.k
- The size of the desired subset
Return
subset of size k sampled according to weights
Example
use smartnoise_runtime::utilities::create_subset; let set = vec![1, 2, 3, 4, 5, 6]; let weights = vec![1., 1., 1., 2., 2., 2.]; let k = 3; let subset = create_subset(&set, &weights, k, false);