jpt.base.utils.sampling
© Copyright 2021, Mareike Picklum, Daniel Nyga.
Classes
Roulette wheel proportional sampler |
Functions
|
Choose one element from the |
|
Choose from the dict |
|
Choose one element from the |
|
Obtain a sample of the |
|
Equivalent to |
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,
xfalls into. :param x: :return:
- sample(n=1)
Sample
nvalues 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
populationproportionally to theirweights.
- jpt.base.utils.sampling.wchoiced(dist)
Choose from the dict
distone element from key set proportionally to the weights given as values
- jpt.base.utils.sampling.wchoicei(population, weights)
Choose one element from the
populationproportionally to theirweightsand return its index.
- jpt.base.utils.sampling.wsample(population, weights, k)
Obtain a sample of the
populationof lengthk.The probability of each element in
populationto be sampled is proportional to its weight inweightsvector.len(population)must equal tolen(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: