Trait

com.eharmony.aloha.util.rand

AliasMethodSampler

Related Doc: package rand

Permalink

trait AliasMethodSampler extends AnyRef

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AliasMethodSampler
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract val alias: IndexedSeq[Int]

    Permalink

    The alias table used in the alias method.

    The alias table used in the alias method.

    Attributes
    protected[this]
  2. abstract val numClasses: Int

    Permalink

    The number of different classes possible.

  3. abstract val probabilities: IndexedSeq[Double]

    Permalink

    The probability table used in the alias method.

    The probability table used in the alias method.

    Attributes
    protected[this]

Concrete 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. final def asInstanceOf[T0]: T0

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

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

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  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. def hashCode(): Int

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
  15. 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.

  16. 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]
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  18. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped