Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit a025dc1

Browse files
authored
Update QLearningExample.py
1 parent 5c3faa7 commit a025dc1

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

QLearningExample.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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

910
import 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

Comments
 (0)