WeightVectors

Documentation for WeightVectors.

WeightVectors.AbstractWeightVectorType
AbstractWeightVector <: AbstractVector{Float64}

An abstract vector capable of storing normal, non-negative floating point numbers on which rand samples an index according to values rather than sampling a value uniformly.

source
WeightVectors._resize!Method

Reallocate w with the size len, compacting w into that new memory. Any elements if w past len must be set to zero already (that's a general invariant for Weights, though, not just this function).

source
WeightVectors.binomial_sampleMethod
binomial_sample(rng, trials, px, py)

Flip a coin with probability of px//py of coming up heads trials times and return the number of heads.

Has O(trials) expected runtime with a very low constant factor.

Implementation based on Farach-Colton, M. and Tsai, M.T., 2015. Exact sublinear binomial sampling.

source
WeightVectors.multinomial_sampleMethod
multinomial_sample(rng, trials, weights)

Draw trials elements from the probability distribution specified by weights (need not sum to 1) and return the number of times each element was drawn.

Runs in O(trials * weights), but can be as fast as O(trials) if the weights are skewed toward big weights at the beginning.

source