Question: what is the error in this code import numpy as np class BernoulliBandit: def _ _ init _ _ ( self , p , verbose
what is the error in this code
import numpy as np
class BernoulliBandit:
def initself p verboseTrue:
self.p p
if verbose:
printCreating BernoulliBandit with p :fformatp
def pullself:
return nprandom.binomial self.pimport random
class BanditsGame:
def initself K T verboseTrue:
self.T T
self.K K
self.bandits BernoulliBanditnprandom.uniform verbose for i in rangeK
# self.bandits BernoulliBanditnprandom.RandomStateiuniform verbose for i in rangeK
self.verbose verbose
def runstochasticself:
results npzerosselfT
for t in rangeselfT:
k random.randrangeselfK
resultst self.banditskpull
if self.verbose:
printTt Playing bandit t Reward is :fformatt k resultst
return resultsgame BanditsGameK T
game.runstochastic
def runsimulationnruns, runspergame, K T:
results npzerosKT
for run in rangenruns:
runresults npzerosKT
for run in rangerunspergame:
game BanditsGameKK TT verboseFalse
runresults game.runstochastic
results runresults runspergame
results results nruns
return results
stochasticresults runsimulationnruns runspergame K T
stochasticresults stochasticresults.meanaxis
printMean reward: :fformatstochasticresults.mean
printG: :fformatstochasticresults.sum
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
