update
This commit is contained in:
@@ -16,11 +16,11 @@ import torch
|
||||
class FisrtVisitMC:
|
||||
''' On-Policy First-Visit MC Control
|
||||
'''
|
||||
def __init__(self,n_actions,cfg):
|
||||
self.n_actions = n_actions
|
||||
def __init__(self,action_dim,cfg):
|
||||
self.action_dim = action_dim
|
||||
self.epsilon = cfg.epsilon
|
||||
self.gamma = cfg.gamma
|
||||
self.Q = defaultdict(lambda: np.zeros(n_actions))
|
||||
self.Q = defaultdict(lambda: np.zeros(action_dim))
|
||||
self.returns_sum = defaultdict(float) # sum of returns
|
||||
self.returns_count = defaultdict(float)
|
||||
|
||||
@@ -28,11 +28,11 @@ class FisrtVisitMC:
|
||||
''' e-greed policy '''
|
||||
if state in self.Q.keys():
|
||||
best_action = np.argmax(self.Q[state])
|
||||
action_probs = np.ones(self.n_actions, dtype=float) * self.epsilon / self.n_actions
|
||||
action_probs = np.ones(self.action_dim, dtype=float) * self.epsilon / self.action_dim
|
||||
action_probs[best_action] += (1.0 - self.epsilon)
|
||||
action = np.random.choice(np.arange(len(action_probs)), p=action_probs)
|
||||
else:
|
||||
action = np.random.randint(0,self.n_actions)
|
||||
action = np.random.randint(0,self.action_dim)
|
||||
return action
|
||||
def update(self,one_ep_transition):
|
||||
# Find all (state, action) pairs we've visited in this one_ep_transition
|
||||
|
||||
Reference in New Issue
Block a user