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

Function play_one

rl2/mountaincar/q_learning.py:101–124  ·  view source on GitHub ↗
(model, env, eps, gamma)

Source from the content-addressed store, hash-verified

99
100# returns a list of states_and_rewards, and the total reward
101def play_one(model, env, eps, gamma):
102 observation = env.reset()[0]
103 done = False
104 totalreward = 0
105 iters = 0
106 while not done and iters < 10000:
107 action = model.sample_action(observation, eps)
108 prev_observation = observation
109 observation, reward, done, truncated, info = env.step(action)
110
111 # update the model
112 if done:
113 G = reward
114 else:
115 Qnext = model.predict(observation)
116 # assert(next.shape == (1, env.action_space.n))
117 G = reward + gamma*np.max(Qnext[0])
118
119 model.update(prev_observation, action, G)
120
121 totalreward += reward
122 iters += 1
123
124 return totalreward
125
126
127def plot_cost_to_go(env, estimator, num_tiles=20):

Callers 1

mainFunction · 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