Skip to content

num::sample_categorical

Defined in header <stochastic/categorical.hpp>

template <std::uniform_random_bit_generator RNG>
idx sample_categorical(view<const real> weights, RNG &rng);

Draw an index with probability proportional to its weight, in one pass: \(P(k) = w_k / \sum_j w_j\).