Ejemplo n.º 1
0
""" Example of use of SMPyBandits.
See https://SMPyBandits.GitHub.io/API.html for more details!"""
import numpy as np
np.random.seed(0)  # for reproducibility
from SMPyBandits.Arms import Bernoulli
arms = [Bernoulli(0.1), Bernoulli(0.9)]
from SMPyBandits.Environment import MAB
my_MAB_problem = MAB(arms)
nbArms = my_MAB_problem.nbArms  # 2 arms !
from SMPyBandits.Policies import UCB
my_UCB_algo = UCB(nbArms)
my_UCB_algo.startGame()  # reset internal memory

horizon = 1000
for t in range(horizon):  # simulation loop
    chosen_arm = my_UCB_algo.choice()
    observed_reward = my_MAB_problem.draw(chosen_arm)
    my_UCB_algo.getReward(chosen_arm, observed_reward)

cumulated_reward = sum(my_UCB_algo.rewards)  # random!
number_of_plays = sum(my_UCB_algo.pulls)  # horizon = 1000
mean_reward = cumulated_reward / number_of_plays
print("The UCB algorithm obtains here a mean reward =", mean_reward)
Ejemplo n.º 2
0
 def startGame(self):
     UCB.startGame(self)
     self.budget = self.inibudget
     self.estmeans.fill(0.0)
     self.successes.fill(0)
Ejemplo n.º 3
0
 def startGame(self):
     UCB.startGame(self)
     SafeAlg.startGame(self)
Ejemplo n.º 4
0
 def startGame(self):
     UCB.startGame(self)
     self.positive_mean = nb.repeat(0.0, self.nbArms, dtype='float')
     self.negative_mean = nb.repeat(0.0, self.nbArms, dtype='float')
     self.positive_count = nb.repeat(0, self.nbArms, dtype='int')
     self.negative_count = nb.repeat(0, self.nbArms, dtype='int')
Ejemplo n.º 5
0
 def startGame(self):
     UCB.startGame(self)
     self.reward_samples = [np.array([0.0]) for a in range(self.nbArms)]
Ejemplo n.º 6
0
 def startGame(self):
     UCB.startGame(self)
     Budgeted.startGame(self)
     BernoulliEstimator.startGame(self)