Arms.Poisson module

Poisson distributed arm, possibly truncated.

Example of creating an arm:

>>> import random; import numpy as np
>>> random.seed(0); np.random.seed(0)
>>> Poisson5 = Poisson(5, trunc=10)
>>> Poisson5
P(5, 10)
>>> Poisson5.mean  # doctest: +ELLIPSIS
4.9778...

Examples of sampling from an arm:

>>> Poisson5.draw()  # doctest: +ELLIPSIS
9
>>> Poisson5.draw_nparray(20)  # doctest: +ELLIPSIS
array([ 5,  6,  5,  5,  8,  4,  5,  4,  3,  3,  7,  3,  3,  4,  5,  2,  1,
        7,  7, 10])
class Arms.Poisson.Poisson(p, trunc=1)[source]

Bases: Arms.Arm.Arm

Poisson distributed arm, possibly truncated.

  • Default is to not truncate.
  • Warning: the draw() method is QUITE inefficient! (15 seconds for 200000 draws, 62 µs for 1).
__init__(p, trunc=1)[source]

New arm.

p = None

Parameter p for Poisson arm

trunc = None

Max value of rewards

mean = None

Mean for this Poisson arm

draw(t=None)[source]

Draw one random sample. The parameter t is ignored in this Arm.

draw_nparray(shape=(1, ))[source]

Draw a numpy array of random samples, of a certain shape.

set_mean_param(p)[source]
__str__()[source]

Return str(self).

__repr__()[source]

Return repr(self).

static kl(x, y)[source]

The kl(x, y) to use for this arm.

static oneLR(mumax, mu)[source]

One term of the Lai & Robbins lower bound for Poisson arms: (mumax - mu) / KL(mu, mumax).

__module__ = 'Arms.Poisson'
class Arms.Poisson.UnboundedPoisson(p)[source]

Bases: Arms.Poisson.Poisson

Poisson distributed arm, not truncated, ie. trunc = oo.

__init__(p)[source]

New arm.

__module__ = 'Arms.Poisson'