from algorithms import UCB from models import MAB from models import experiment # Plot tools import matplotlib.pyplot as plt # Create some arms # arm1 = bernoulliArm.bernoulliArm( 0.70, reward1 = 5.0, reward2 = -4.0 ) # arm2 = bernoulliArm.bernoulliArm( 0.35, reward1 = 3.0 ) # arm3 = bernoulliArm.bernoulliArm( 0.40, reward1 = 3.0 ) # arm4 = bernoulliArm.bernoulliArm( 0.90, reward1 = 1.5 ) # armModels = [ arm1, arm2, arm3, arm4 ] armModels = [ normalArm.normalArm( 3.0 ), normalArm.normalArm( 4.0, 1.0 ), normalArm.normalArm( 5.0, 1.0 ) ] bandit = MAB.MAB( armModels ) algo0 = epsilonGreedy.epsilonGreedy( 0.25, len(armModels) ) algo1 = UCB.UCB1( len(armModels) ) exp0 = experiment.experiment( bandit, algo0 ) exp1 = experiment.experiment( bandit, algo1 ) # run expriment selArmIndex0, obtainedRewards0 = exp0.run( 1000 ) selArmIndex1, obtainedRewards1 = exp1.run( 1000 )
# Changelogs ################################################################################ # Import root path import os.path import sys sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../modules"))) # Import modules from arms import bernoulliArm, normalArm from models import MAB # create some arms bArm1 = bernoulliArm.bernoulliArm( 0.7, reward1 = 3.0, reward2 = 2.5 ) bArm2 = bernoulliArm.bernoulliArm( 0.85 ) nArm1 = normalArm.normalArm( 3.0, 2.0 ) nArm2 = normalArm.normalArm( 2.0, 5.0 ) banditArms = [ bArm1, bArm2, nArm1, nArm2 ] # Create a bandit model using arm bandit = MAB.MAB( banditArms ) # Pull, pull and pull!! print bandit.pull( 1 ) print bandit.pull( 0 ) print bandit.pull( [ 1, 3] ) print bandit.pull( [] ) print bandit.tick()