MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / play_one

Function play_one

rl2/cartpole/q_learning_bins.py:80–101  ·  view source on GitHub ↗
(model, eps, gamma)

Source from the content-addressed store, hash-verified

78
79
80def play_one(model, eps, gamma):
81 observation = env.reset()
82 done = False
83 totalreward = 0
84 iters = 0
85 while not done and iters < 10000:
86 action = model.sample_action(observation, eps)
87 prev_observation = observation
88 observation, reward, done, info = env.step(action)
89
90 totalreward += reward
91
92 if done and iters < 199:
93 reward = -300
94
95 # update the model
96 G = reward + gamma*np.max(model.predict(observation))
97 model.update(prev_observation, action, G)
98
99 iters += 1
100
101 return totalreward
102
103
104def plot_running_avg(totalrewards):

Callers 1

q_learning_bins.pyFile · 0.70

Calls 5

resetMethod · 0.45
sample_actionMethod · 0.45
stepMethod · 0.45
predictMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected