Class

com.eharmony.aloha.util.rand

IntAliasMethodSampler

Related Doc: package rand

Permalink

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
Visibility
  1. Public
  2. All

Instance Constructors

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

    Permalink

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. val alias: IndexedSeq[Int]

    Permalink

    The alias table used in the alias method.

    The alias table used in the alias method.

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

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

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

    Permalink
    Definition Classes
    AnyRef
  8. def finalize(): Unit

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

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

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

    Permalink
    Definition Classes
    AnyRef
  12. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  13. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  14. val numClasses: Int

    Permalink

    The number of different classes possible.

    The number of different classes possible.

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

    Permalink
  16. val probabilities: IndexedSeq[Double]

    Permalink

    The probability table used in the alias method.

    The probability table used in the alias method.

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

    Permalink

    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.

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

    Permalink

    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.

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

    Permalink
    Definition Classes
    AnyRef
  20. final def wait(): Unit

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

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

    Permalink
    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