Arms.DiscreteArm module

Discretely distributed arm, of finite support.

Example of creating an arm:

>>> import random; import numpy as np
>>> random.seed(0); np.random.seed(0)
>>> D3values = DiscreteArm({-1: 0.25, 0: 0.5, 1: 0.25})
>>> D3values
D({-1: 0.25, 0: 0.5, 1: 0.25})
>>> D3values.mean
0.0
  • Examples of sampling from an arm:

>>> D3values.draw()
0
>>> D3values.draw_nparray(20)
array([ 0,  0,  0,  0,  0,  0,  1,  1,  0,  1,  0,  0,  1, -1, -1, -1,  1,
        1,  1,  1])
  • Another example, with heavy tail:

>>> D5values = DiscreteArm({-1000: 0.001, 0: 0.5, 1: 0.25, 2:0.25, 1000: 0.001})
>>> D5values
D({-1e+03: 0.001, 0: 0.5, 1: 0.25, 2: 0.25, 1e+03: 0.001})
>>> D5values.mean
0.75

Examples of sampling from an arm:

>>> D5values.draw()
2
>>> D5values.draw_nparray(20)
array([0, 2, 0, 1, 0, 2, 1, 0, 0, 2, 0, 1, 0, 1, 1, 1, 2, 1, 0, 0])
class Arms.DiscreteArm.DiscreteArm(values_to_proba)[source]

Bases: Arms.Arm.Arm

DiscreteArm distributed arm.

__init__(values_to_proba)[source]

New arm.

mean = None

Mean for this DiscreteArm arm

size = None

Number of different values in this DiscreteArm arm

draw(t=None)[source]

Draw one random sample.

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

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

property lower_amplitude

(lower, amplitude)

__str__()[source]

Return str(self).

__repr__()[source]

Return repr(self).

static kl(x, y)[source]

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

Warning

FIXME this is not correctly defined, except for the special case of having only 2 values, a DiscreteArm is NOT a one-dimensional distribution, and so the kl between two distributions is NOT a function of their mean!

static oneLR(mumax, mu)[source]

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

Warning

FIXME this is not correctly defined, except for the special case of having only 2 values, a DiscreteArm is NOT a one-dimensional distribution, and so the kl between two distributions is NOT a function of their mean!

__module__ = 'Arms.DiscreteArm'