Class Binomial

This class represents a binomial distribution. It can be used to compute the probability of a given event and generate random samples from the distribution.

Hierarchy

Implements

Constructors

Properties

_boundaries: Float64Array
_m: number
_n: number
_p: number

Methods

  • Draws a number from the binomial distribution

    Returns number

    A random value sampled from the binomial distribution.

    Remarks

    Rejection sampling method is used to generates an observation from binomial distribution.

  • Generates an observation using the inverse cumulative distribution method.

    This method uses:

    • the cumulative distribution function to breakdown its from/input set into observations zone
    • a uniform random function to generate a number x, that will be used to identify which observation zone is chosen.

    The process is the following:

    1- The cumulative distribution function is used to define boundaries of observation zone. 2- An number x is drawn using a uniform distribution function 3- The zone in which the number x falls is the observation

    This process can be describe using the following schema with:

    • observations in ordinate (from 0 to 4)
    • probability for each observation in abscissa

    0 ─ 1 ── 2 ──── 3 ─ 4 ───

    Probabilities are cumulated:

    0 ─ 1 ── 2 ──── 3 ─ 4 ───

    Cumulated probabilities are projected on the same dimension:

    ├┼─┼───┼┼──┤ 0 1 2 3 4

    x is drawn and the corresponding observation zone is identified using boundaries:

    ├┼x┼───┼┼──┤ 0 1 2 3 4

    Parameters

    • n: number

      Sampling upper limit.

    Returns number

    Observation

  • Computes the probability of a given event k.

    Parameters

    • k: number

      An event.

    Returns number

    The probability of the event k in the binomial distribution.

  • Generates an observation using the rejection sampling method.

    This method uses a uniform random function to generate:

    • the number k, the potential observation
    • the number x, a random number between 0 and the greatest probability of the distribution

    If the number x is lower or equal to the probability of event k, then it's an observation.

    Otherwise, the process is restarted (k and x are generated).

    This process can be describe using the following schema with:

    • observations in abscissa (from 0 to 4)
    • probability for each observation in ordinate (observation 2 having the greatest probability p_max)

    p_max ────┬─┬──── │ │ ┌─┐ ┌─┤ │ │ │ ┌─┤ │ ├─┤ │ └─┴─┴─┴─┴─┘ 0 1 2 3 4

    Rejection sampling method for this example do the following:

    1- randomly find the potential observation k by using an uniform random function with lower limit 0 and upper limit 4. Lets say k = 0 2- draw a number x, from an uniform random function with lower limit 0 and upper limit p_max. Lets say x > p_0. In that case we restart the process from the beginning. 3- randomly find k. Lets say k = 2 4- randomly find x. Lets say x < p_2. In that case the process stop and the observation is returned.

    Graphically, the following process can be represented as the following:

    p_max ────┬─┬──── │o│ ┌─┐ x┌─┤ │ │ │ ┌─┤ │ ├─┤ │ └─┴─┴─┴─┴─┘ 0 1 2 3 4

    Where x represents the failed attempt and o the success one.

    Intuitively we "see" the returned observations will match the underlying probabilities because observations with greater probability will have a higher chance of being returned than observation with lower one.

    Parameters

    • n: number

      sampling upper limit

    • max: number

      greatest probability of the distribution

    Returns number

    an observation

Generated using TypeDoc