The alias table used in the alias method.
The alias table used in the alias method.
The number of different classes possible.
The probability table used in the alias method.
The probability table used in the alias method.
Induces a non-uniform distribution given a uniform random variates.
Induces a non-uniform distribution given a uniform random variates.
This method has the following nice property for distributions with two possible outcomes:
Given two distributions D1 and D2 with two classes, if
then
y = Sampler(D2).sample(j, x)
The same guarantee doesn't hold when the number of classes is greater than two.
Note the implication of this is that if this method is to be used to assign a treatment to an certain population, the treatment should be assigned in the first (zeroth) class and the lack of treatment should be indicated by subsequent class indices. For instance:
val (x, r) = getHashFromUser(u) // Some hashing function based on user info. val samplerFor20130920 = new IntAliasMethodSampler(Seq(0.05, 0.95)) val samplerFor20130921 = new IntAliasMethodSampler(Seq(0.10, 0.90)) val msg = """ | If previously assigned class 0, and the probability of inclusion is increased, | then subsequent assignment to class 0 will occur """.stripMargin.trim assert(!(0 == samplerFor20130920.sample(x, r)) || (0 == samplerFor20130921.sample(x, r)), msg)
integer value in {0, 1, ..., numClasses - 1}. NOTE: the distribution of values passed to this function MUST BE uniformly distributed. Otherwise, the sampling will be biased.
a real-valued uniform variate in the [0, 1] interval.
Get the aliases and probabilities.
Get the aliases and probabilities. Current implementation based on
Previous implementation based on:
There was a bug that occurred infrequently which seems to have been a problem that arose while porting. It was easier just to reimplement than to track down the problem.
probabilities with which the sampler will return the associated index.