com.eharmony.aloha.util.rand

IntAliasMethodSampler

case class IntAliasMethodSampler(prob: Seq[Double]) extends AliasMethodSampler with Product with Serializable

Linear Supertypes
Serializable, Serializable, Product, Equals, AliasMethodSampler, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. IntAliasMethodSampler
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AliasMethodSampler
  7. AnyRef
  8. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new IntAliasMethodSampler(prob: Seq[Double])

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. val alias: IndexedSeq[Int]

    The alias table used in the alias method.

    The alias table used in the alias method.

    Attributes
    protected[this]
    Definition Classes
    IntAliasMethodSamplerAliasMethodSampler
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  16. val numClasses: Int

    The number of different classes possible.

    The number of different classes possible.

    Definition Classes
    IntAliasMethodSamplerAliasMethodSampler
  17. val prob: Seq[Double]

  18. val probabilities: IndexedSeq[Double]

    The probability table used in the alias method.

    The probability table used in the alias method.

    Attributes
    protected[this]
    Definition Classes
    IntAliasMethodSamplerAliasMethodSampler
  19. def sample(uniformlyDistributedVariate: Int, uniform01: Float): Int

    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

    • y = Sampler(D1).sample(j, x) AND
    • Σi ≤ j(D1,i) = Σi ≤ j(D2,i)

    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)
    uniformlyDistributedVariate

    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.

    uniform01

    a real-valued uniform variate in the [0, 1] interval.

    returns

    Definition Classes
    AliasMethodSampler
  20. final def structures(probs: Seq[Double]): (IndexedSeq[Int], IndexedSeq[Double])

    Get the aliases and probabilities.

    Get the aliases and probabilities. Current implementation based on

    • https://hips.seas.harvard.edu/blog/2013/03/03/the-alias-method-efficient-sampling-with-many-discrete-outcomes/

    Previous implementation based on:

    • http://www.keithschwarz.com/interesting/code/alias-method/AliasMethod.java.html
    • http://www.keithschwarz.com/darts-dice-coins/

    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.

    probs

    probabilities with which the sampler will return the associated index.

    returns

    Attributes
    protected[this]
    Definition Classes
    AliasMethodSampler
  21. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  22. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AliasMethodSampler

Inherited from AnyRef

Inherited from Any

Ungrouped