WeightVectors
Documentation for WeightVectors.
WeightVectors.AbstractWeightVector
WeightVectors.FixedSizeWeightVector
WeightVectors.WeightVector
WeightVectors._resize!
WeightVectors.binomial_sample
WeightVectors.binomial_sample_fair_coin
WeightVectors.initialize_empty
WeightVectors.multinomial_sample
WeightVectors.AbstractWeightVector
— TypeAbstractWeightVector <: 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.
WeightVectors.FixedSizeWeightVector
— TypeFixedSizeWeightVector <: AbstractWeightVector
An object that conforms to the AbstractWeightVector
interface and cannot be resized.
WeightVectors.WeightVector
— TypeWeightVector <: AbstractWeightVector
An object that conforms to the AbstractWeightVector
interface and can be resized.
WeightVectors._resize!
— MethodReallocate 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).
WeightVectors.binomial_sample
— Methodbinomial_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.
WeightVectors.binomial_sample_fair_coin
— Methodbinomial_sample_fair_coin(rng, trials)
Flips trials
fair coins and reports the number of heads.
Flips up to 64 coins at a time.
WeightVectors.initialize_empty
— Methodinitialize_empty(len::Int)::Memory{UInt64}
Initialize a Memory
that, when underlaying a Weights
object, represents len
zeros.
WeightVectors.multinomial_sample
— Methodmultinomial_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.