()
| 233 | |
| 234 | |
| 235 | def main(): |
| 236 | env = gym.make('MountainCarContinuous-v0') |
| 237 | ft = FeatureTransformer(env, n_components=100) |
| 238 | D = ft.dimensions |
| 239 | pmodel = PolicyModel(ft, D, [], []) |
| 240 | # init = tf.global_variables_initializer() |
| 241 | session = tf.InteractiveSession() |
| 242 | # session.run(init) |
| 243 | pmodel.set_session(session) |
| 244 | pmodel.init_vars() |
| 245 | gamma = 0.99 |
| 246 | |
| 247 | if 'monitor' in sys.argv: |
| 248 | filename = os.path.basename(__file__).split('.')[0] |
| 249 | monitor_dir = './' + filename + '_' + str(datetime.now()) |
| 250 | env = wrappers.Monitor(env, monitor_dir) |
| 251 | |
| 252 | totalrewards, pmodel = random_search(env, pmodel, gamma) |
| 253 | print("max reward:", np.max(totalrewards)) |
| 254 | |
| 255 | # play 100 episodes and check the average |
| 256 | avg_totalrewards = play_multiple_episodes(env, 100, pmodel, gamma, print_iters=True) |
| 257 | print("avg reward over 100 episodes with best models:", avg_totalrewards) |
| 258 | |
| 259 | plt.plot(totalrewards) |
| 260 | plt.title("Rewards") |
| 261 | plt.show() |
| 262 | |
| 263 | |
| 264 | if __name__ == '__main__': |
no test coverage detected