-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_Agent.py
48 lines (38 loc) · 1.24 KB
/
data_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
39
40
41
42
43
44
45
46
47
48
import numpy as np
from src import agent
''' Agent which implements several heuristic algorithms'''
class dataUpdateAgent(agent.FiniteHorizonAgent):
def __init__(self, epLen, func, alpha):
'''args:
epLen - number of steps
func - function used to decide action
data - all data observed so far
alpha - alpha parameter in ambulance problem
'''
self.epLen = epLen
self.func = func
self.data = []
self.alpha = alpha
def reset(self):
# resets data matrix to be empty
self.data = []
def update_obs(self, obs, action, reward, newObs, timestep):
'''Add observation to records'''
self.data.append(newObs)
def get_num_arms(self):
return 0
def update_policy(self, k):
'''Update internal policy based upon records'''
self.greedy = self.greedy
def greedy(self, state, timestep, epsilon=0):
'''
Select action according to function
'''
if timestep == 0:
return state
else:
action = self.func(self.data)
return action
def pick_action(self, state, step):
action = self.greedy(state, step)
return action