File weight_sampling.hpp

Functions

template<typename WeightVector, typename IndexIterator, typename WeightIterator>
static inline void sampleWeightsWithoutReplacementViaTrackingSelection(WeightVector &weightVector, IndexIterator indexIterator, WeightIterator weightIterator, uint32 numTotal, uint32 numSamples, RNG &rng)

Randomly selects numSamples out of numTotal elements and sets their weights to the value in a given iterator, while the remaining weights are set to 0, by using a set to keep track of the elements that have already been selected. This method is suitable if numSamples is much smaller than numTotal.

Template Parameters:
  • WeightVector – The type of the vector, the weights should be written to

  • IndexIterator – The type of the iterator that provides random access to the indices of the available elements to sample from

  • WeightIterator – The type of the iterator that provides random access to the weights of the available elements to sample from

Parameters:
  • weightVector – A reference to an object of type BitWeightVector the weights should be written to

  • indexIterator – An iterator that provides random access to the indices of the available elements to sample from

  • weightIterator – An iterator that provides random access to the weights of the available elements to sample from

  • numTotal – The total number of available elements to sample from

  • numSamples – The number of weights to be set to 1

  • rng – A reference to an object of type RNG, implementing the random number generator to be used

template<typename WeightVector, typename IndexIterator, typename WeightIterator>
static inline void sampleWeightsWithoutReplacementViaPool(WeightVector &weightVector, IndexIterator indexIterator, WeightIterator weightIterator, uint32 numTotal, uint32 numSamples, RNG &rng)

Randomly selects numSamples out of numTotal elements and sets their weights to the value in a given iterator, while the remaining weights are set to 0, by using a pool, i.e., an array, to keep track of the elements that have not been selected yet.

Template Parameters:
  • WeightVector – The type of the vector, the weights should be written to

  • IndexIterator – The type of the iterator that provides random access to the indices of the available elements to sample from

  • WeightIterator – The type of the iterator that provides random access to the weights of the available elements to sample from

Parameters:
  • weightVector – A reference to an object of type BitWeightVector the weights should be written to

  • indexIterator – An iterator that provides random access to the indices of the available elements to sample from

  • weightIterator – An iterator that provides random access to the weights of the available elements to sample from

  • numTotal – The total number of available elements to sample from

  • numSamples – The number of weights to be set to 1

  • rng – A reference to an object of type RNG, implementing the random number generator to be used

template<typename WeightVector, typename IndexIterator, typename WeightIterator>
static inline void sampleWeightsWithoutReplacement(WeightVector &weightVector, IndexIterator indexIterator, WeightIterator weightIterator, uint32 numTotal, uint32 numSamples, RNG &rng)

Randomly selects numSamples out of numTotal elements and sets their weights to the value in a given iterator, while the remaining weights are set to 0. The method that is used internally is chosen automatically, depending on the ratio numSamples / numTotal.

Template Parameters:
  • WeightVector – The type of the vector, the weights should be written to

  • IndexIterator – The type of the iterator that provides random access to the indices of the available elements to sample from

  • WeightIterator – The type of the iterator that provides random access to the weights of the available elements to sample from

Parameters:
  • weightVector – A reference to an object of template type WeightVector the weights should be written to

  • indexIterator – An iterator that provides random access to the indices of the available elements to sample from

  • weightIterator – An iterator that provides random access to the weights of the available elements to sample from

  • numTotal – The total number of available elements to sample from

  • numSamples – The number of weights to be set to 1

  • rng – A reference to an object of type RNG, implementing the random number generator to be used