jpt.base.utils.sampling ======================= .. py:module:: jpt.base.utils.sampling .. autoapi-nested-parse:: © Copyright 2021, Mareike Picklum, Daniel Nyga. Classes ------- .. autoapisummary:: jpt.base.utils.sampling.RouletteWheelSampler Functions --------- .. autoapisummary:: jpt.base.utils.sampling.wchoice jpt.base.utils.sampling.wchoiced jpt.base.utils.sampling.wchoicei jpt.base.utils.sampling.wsample jpt.base.utils.sampling.wsamplei Module Contents --------------- .. py:class:: RouletteWheelSampler(elements, weights, normalize=False) Roulette wheel proportional sampler .. py:attribute:: _upperbounds .. py:attribute:: _elements .. py:method:: __getitem__(x) .. py:method:: index(x) Returns the index of the element, which corresponds to the "roulette" field, ``x`` falls into. :param x: :return: .. py:method:: sample(n=1) Sample ``n`` values from the the roulette wheel. :param n: :return: .. py:method:: samplei(n=1) Same as ``sample()``, but returns a list of indices of selected elements. :param n: :return: .. py:function:: wchoice(population, weights) Choose one element from the ``population`` proportionally to their ``weights``. .. py:function:: wchoiced(dist) Choose from the dict ``dist`` one element from key set proportionally to the weights given as values .. py:function:: wchoicei(population, weights) Choose one element from the ``population`` proportionally to their ``weights`` and return its index. .. py:function:: 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)``. :param population: :param weights: :param k: :return: .. py:function:: 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: