-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubc1_agent.py
38 lines (34 loc) · 1.08 KB
/
ubc1_agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from agent import Agent
from util import *
import numpy as np
import math
class UBC1Agent(Agent):
best_arm = 0
#
def __init__(self,time_horizon,number_of_arms):
self.time_horizon = time_horizon
self.number_of_arms = number_of_arms
self.reset()
self.name = "ubc1"
#
def reset(self):
self.mu_estimators = [0]*self.number_of_arms
self.best_arm = 0
self.arms_visited = [0]*self.number_of_arms
self.ubc = [0]*self.number_of_arms
print('ubc1 agent started to decide.')
#
def decide(self,time,time_horizon,number_of_arms):
arm = 0
#explore
if time<number_of_arms:
arm = time
#exploit
else :
arm = np.argmax(self.ubc)
self.arms_visited[arm] += 1
return arm
#
def observe(self,time,arm,reward):
self.mu_estimators[arm] = incrementalAvg(self.arms_visited[arm],self.mu_estimators[arm],reward)
self.ubc[arm] = self.mu_estimators[arm] + math.sqrt(2*math.log(self.time_horizon)/self.arms_visited[arm])