Source code for Policies.Uniform

# -*- coding: utf-8 -*-
""" Uniform: the fully uniform policy who selects randomly (uniformly) an arm at each step (stupid).
"""

__author__ = "Lilian Besson"
__version__ = "0.1"

import random

try:
    from .BasePolicy import BasePolicy
except ImportError:
    from BasePolicy import BasePolicy


[docs]class Uniform(BasePolicy): """ Uniform: the fully uniform policy who selects randomly (uniformly) an arm at each step (stupid). """
[docs] def __init__(self, nbArms, lower=0., amplitude=1.): """Nothing to do.""" self.nbArms = nbArms #: Number of arms
[docs] def __str__(self): return "U(1..{})".format(self.nbArms)
[docs] def startGame(self): """Nothing to do.""" pass
[docs] def getReward(self, arm, reward): """Nothing to do.""" pass
[docs] def choice(self): """Uniform random choice between 0 and nbArms - 1 (included).""" return random.randint(0, self.nbArms - 1)
[docs] def choiceWithRank(self, rank=1): """Ignore the rank!""" return self.choice()