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

Function main

rl2/mountaincar/pg_tf.py:202–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

200
201
202def main():
203 env = gym.make('MountainCarContinuous-v0')
204 ft = FeatureTransformer(env, n_components=100)
205 D = ft.dimensions
206 pmodel = PolicyModel(D, ft, [])
207 vmodel = ValueModel(D, ft, [])
208 init = tf.global_variables_initializer()
209 session = tf.InteractiveSession()
210 session.run(init)
211 pmodel.set_session(session)
212 vmodel.set_session(session)
213 gamma = 0.95
214
215 if 'monitor' in sys.argv:
216 filename = os.path.basename(__file__).split('.')[0]
217 monitor_dir = './' + filename + '_' + str(datetime.now())
218 env = wrappers.Monitor(env, monitor_dir)
219
220 N = 50
221 totalrewards = np.empty(N)
222 costs = np.empty(N)
223 for n in range(N):
224 totalreward, num_steps = play_one_td(env, pmodel, vmodel, gamma)
225 totalrewards[n] = totalreward
226 if n % 1 == 0:
227 print("episode:", n, "total reward: %.1f" % totalreward, "num steps: %d" % num_steps, "avg reward (last 100): %.1f" % totalrewards[max(0, n-100):(n+1)].mean())
228
229 print("avg reward for last 100 episodes:", totalrewards[-100:].mean())
230
231 plt.plot(totalrewards)
232 plt.title("Rewards")
233 plt.show()
234
235 plot_running_avg(totalrewards)
236 plot_cost_to_go(env, vmodel)
237
238
239if __name__ == '__main__':

Callers 1

pg_tf.pyFile · 0.70

Calls 9

set_sessionMethod · 0.95
set_sessionMethod · 0.95
FeatureTransformerClass · 0.90
plot_running_avgFunction · 0.90
plot_cost_to_goFunction · 0.90
PolicyModelClass · 0.70
ValueModelClass · 0.70
play_one_tdFunction · 0.70
runMethod · 0.45

Tested by

no test coverage detected