Skip to content

Commit 359991a

Browse files
committed
Smart Cab: second submission 0.95 benachmark
1 parent e37acf2 commit 359991a

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

projects/smartcab/smartcab/agent.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
GEAR = 2
1919

20+
reducer_func = lambda x: ( x * .95 // 0.001) * 0.001
21+
2022
ALL_STATES = ['light', 'oncoming', 'left', 'right']
2123
ALL_ACTIONS = [None, 'forward', 'left', 'right']
2224

@@ -52,31 +54,37 @@ def reset(self, destination=None):
5254
* Epsilon(exploration factor): higher the randomness higher the exploration
5355
'''
5456
self.planner.route_to(destination)
55-
# pdb.set_trace()
56-
# TODO: Prepare for a new trip; reset any variables here, if required
57+
random.shuffle(ALL_ACTIONS)
5758
self.prev_state = None
5859
self.prev_reward = None
5960
self.prev_action = None
6061

62+
# learning rate
6163
if self.counter < 50:
6264
self.alpha -= 0.01
6365
# self.alpha = (self.alpha // 0.0001) * 0.0001
6466

65-
if self.counter < 0:
67+
# long term focus
68+
if self.counter < 20:
6669
self.gamma += 0.01
6770

71+
# randomness
6872
if self.epsilon < 0:
6973
# self.epsilon -= 0.01
70-
self.epsilon = (self.epsilon // 0.0001) * 0.0001
74+
self.epsilon = (self.epsilon * .9 // 0.0001) * 0.0001
7175

76+
if self.counter >= 10 * 98:
77+
pprint(self.Q)
78+
# pdb.set_trace()
7279

73-
self.counter += 50
80+
self.counter += 10
7481

7582
def get_q_val(self, state, action):
7683
try:
7784
return self.Q[(self.state, action)]
7885
except KeyError:
79-
self.Q[(self.state, action)] = 0
86+
# optimism in the face of uncertainty
87+
self.Q[(self.state, action)] = 0.05
8088
return 0
8189

8290
def best_q_action(self, s):
@@ -158,12 +166,19 @@ def run():
158166
e.set_primary_agent(a, enforce_deadline=True) # specify agent to track
159167
# NOTE: You can set enforce_deadline=False while debugging to allow longer trials
160168

161-
# Now simulate it
162-
sim = Simulator(e, update_delay=0, display=False) # create simulator (uses pygame when display=True, if available)
163-
# NOTE: To speed up simulation, reduce update_delay and/or set display=False
169+
show = False
170+
# NOTE: To speed up simulation, set show = False.
171+
# NOTE: To show the GUI, set show = True
172+
173+
if show:
174+
# Now simulate it
175+
sim = Simulator(e, update_delay=0.5, display=True) # create simulator (uses pygame when display=True, if available)
176+
sim.run(n_trials=100) # run for a specified number of trials
177+
# NOTE: To quit midway, press Esc or close pygame window, or hit Ctrl+C on the command-line
178+
else:
179+
sim = Simulator(e, update_delay=0.0, display=False)
180+
sim.run(n_trials=100)
164181

165-
sim.run(n_trials=400) # run for a specified number of trials
166-
# NOTE: To quit midway, press Esc or close pygame window, or hit Ctrl+C on the command-line
167182

168183

169184
if __name__ == '__main__':

0 commit comments

Comments
 (0)