jpt.base.utils.sampling

© Copyright 2021, Mareike Picklum, Daniel Nyga.

Classes

RouletteWheelSampler

Roulette wheel proportional sampler

Functions

wchoice(population, weights)

Choose one element from the population proportionally to their weights.

wchoiced(dist)

Choose from the dict dist one element from key set proportionally to the weights given as values

wchoicei(population, weights)

Choose one element from the population proportionally to their weights and return its index.

wsample(population, weights, k)

Obtain a sample of the population of length k.

wsamplei(population, weights, k)

Equivalent to wsample, but returns a tuples of the elements chosen and their index in the population.

Module Contents

class jpt.base.utils.sampling.RouletteWheelSampler(elements, weights, normalize=False)

Roulette wheel proportional sampler

_upperbounds
_elements
__getitem__(x)
index(x)

Returns the index of the element, which corresponds to the “roulette” field, x falls into. :param x: :return:

sample(n=1)

Sample n values from the the roulette wheel. :param n: :return:

samplei(n=1)

Same as sample(), but returns a list of indices of selected elements. :param n: :return:

jpt.base.utils.sampling.wchoice(population, weights)

Choose one element from the population proportionally to their weights.

jpt.base.utils.sampling.wchoiced(dist)

Choose from the dict dist one element from key set proportionally to the weights given as values

jpt.base.utils.sampling.wchoicei(population, weights)

Choose one element from the population proportionally to their weights and return its index.

jpt.base.utils.sampling.wsample(population, weights, k)

Obtain a sample of the population of length k.

The probability of each element in population to be sampled is proportional to its weight in weights vector. len(population) must equal to len(weights).

Parameters:
  • population

  • weights

  • k

Returns:

jpt.base.utils.sampling.wsamplei(population, weights, k)

Equivalent to wsample, but returns a tuples of the elements chosen and their index in the population. :param population: :param weights: :param k: :return: