55# environment: https://github.com/openai/gym/wiki/MountainCar-v0
66# 3 actions: 0:push_left, 1:no_push, 2:push_right
77# 2 observations: 0:position ; 1:volecity
8+ # inspired by https://github.com/llSourcell/Q_Learning_Explained
89
910import numpy as np
1011
@@ -67,7 +68,7 @@ def episode_simulation(environment, policy=None, render=False):
6768 environment = gym .make (environment_name )
6869 environment .seed (0 )
6970 np .random .seed (0 )
70- print ( '----- using Q Learning (iterations) -----' )
71+
7172 # create qTable with zeros
7273 # 3 actions: 0:push_left, 1:no_push, 2:push_right
7374 q_table = np .zeros ((number_states , number_states , 3 ))
@@ -106,10 +107,10 @@ def episode_simulation(environment, policy=None, render=False):
106107 if done :
107108 break
108109 if i % 50 == 0 :
109- print ('Iteration No: %d -- Total reward : %d.' % (i + 1 , total_reward ))
110+ print ('Iteration No: %d -- Total Reward : %d.' % (i + 1 , total_reward ))
110111
111112 solution_policy = np .argmax (q_table , axis = 2 )
112113 solution_policy_scores = [episode_simulation (environment , solution_policy , False ) for _ in range (100 )]
113- print ("Average score of solution = " , np .mean (solution_policy_scores ))
114+ print ("Mean score : " , np .mean (solution_policy_scores ))
114115# run with render=True for visualization
115- episode_simulation (environment , solution_policy , True )
116+ episode_simulation (environment , solution_policy , True )
0 commit comments