Skip to content

Commit b3544c6

Browse files
authored
Merge pull request udacity#54 from udacity/hotfix/smartcab/remove-incomplete-analysis
Remove unfinished smartcab analysis code, leave in other fixes
2 parents 14c6ef4 + b56227d commit b3544c6

File tree

3 files changed

+1
-177
lines changed

3 files changed

+1
-177
lines changed

projects/smartcab/smartcab/analysis.py

Lines changed: 0 additions & 116 deletions
This file was deleted.

projects/smartcab/smartcab/environment.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,6 @@ def __init__(self, num_dummies=3):
6565
self.primary_agent = None # to be set explicitly
6666
self.enforce_deadline = False
6767

68-
# Step data (updated after each environment step)
69-
self.step_data = {
70-
't': 0,
71-
'deadline': 0,
72-
'waypoint': None,
73-
'inputs': None,
74-
'action': None,
75-
'reward': 0.0
76-
}
77-
78-
# Trial data (updated at the end of each trial)
79-
self.trial_data = {
80-
'net_reward': 0.0, # total reward earned in current trial
81-
'final_deadline': None, # deadline value (time remaining)
82-
'success': 0 # whether the agent reached the destination in time
83-
}
84-
8568
def create_agent(self, agent_class, *args, **kwargs):
8669
agent = agent_class(self, *args, **kwargs)
8770
self.agent_states[agent] = {'location': random.choice(self.intersections.keys()), 'heading': (0, 1)}
@@ -120,11 +103,6 @@ def reset(self):
120103
'destination': destination if agent is self.primary_agent else None,
121104
'deadline': deadline if agent is self.primary_agent else None}
122105
agent.reset(destination=(destination if agent is self.primary_agent else None))
123-
if agent is self.primary_agent:
124-
# Reset metrics for this trial (step data will be set during the step)
125-
self.trial_data['net_reward'] = 0.0
126-
self.trial_data['final_deadline'] = deadline
127-
self.trial_data['success'] = 0
128106

129107
def step(self):
130108
#print "Environment.step(): t = {}".format(self.t) # [debug]
@@ -231,22 +209,11 @@ def act(self, agent, action):
231209
if state['location'] == state['destination']:
232210
if state['deadline'] >= 0:
233211
reward += 10 # bonus
234-
self.trial_data['success'] = 1
235212
self.done = True
236213
print "Environment.act(): Primary agent has reached destination!" # [debug]
237214
self.status_text = "state: {}\naction: {}\nreward: {}".format(agent.get_state(), action, reward)
238215
#print "Environment.act() [POST]: location: {}, heading: {}, action: {}, reward: {}".format(location, heading, action, reward) # [debug]
239216

240-
# Update metrics
241-
self.step_data['t'] = self.t
242-
self.trial_data['final_deadline'] = self.step_data['deadline'] = state['deadline']
243-
self.step_data['waypoint'] = agent.get_next_waypoint()
244-
self.step_data['inputs'] = inputs
245-
self.step_data['action'] = action
246-
self.step_data['reward'] = reward
247-
self.trial_data['net_reward'] += reward
248-
print "Environment.act(): Step data: {}".format(self.step_data) # [debug]
249-
250217
return reward
251218

252219
def compute_dist(self, a, b):

projects/smartcab/smartcab/simulator.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import random
44
import importlib
55

6-
import numpy as np
7-
8-
from analysis import Reporter
9-
106
class Simulator(object):
117
"""Simulates agents in a dynamic smartcab environment.
128
@@ -25,7 +21,7 @@ class Simulator(object):
2521
'orange' : (255, 128, 0)
2622
}
2723

28-
def __init__(self, env, size=None, update_delay=1.0, display=True, live_plot=False):
24+
def __init__(self, env, size=None, update_delay=1.0, display=True):
2925
self.env = env
3026
self.size = size if size is not None else ((self.env.grid_size[0] + 1) * self.env.block_size, (self.env.grid_size[1] + 1) * self.env.block_size)
3127
self.width, self.height = self.size
@@ -63,14 +59,8 @@ def __init__(self, env, size=None, update_delay=1.0, display=True, live_plot=Fal
6359
self.display = False
6460
print "Simulator.__init__(): Error initializing GUI objects; display disabled.\n{}: {}".format(e.__class__.__name__, e)
6561

66-
# Setup metrics to report
67-
self.live_plot = live_plot
68-
self.rep = Reporter(metrics=['net_reward', 'avg_net_reward', 'final_deadline', 'success'], live_plot=self.live_plot)
69-
self.avg_net_reward_window = 10
70-
7162
def run(self, n_trials=1):
7263
self.quit = False
73-
self.rep.reset()
7464
for trial in xrange(n_trials):
7565
print "Simulator.run(): Trial {}".format(trial) # [debug]
7666
self.env.reset()
@@ -100,7 +90,6 @@ def run(self, n_trials=1):
10090
# Update environment
10191
if self.current_time - self.last_updated >= self.update_delay:
10292
self.env.step()
103-
# TODO: Log step data
10493
self.last_updated = self.current_time
10594

10695
# Render GUI and sleep
@@ -116,22 +105,6 @@ def run(self, n_trials=1):
116105
if self.quit:
117106
break
118107

119-
# Collect/update metrics
120-
self.rep.collect('net_reward', trial, self.env.trial_data['net_reward']) # total reward obtained in this trial
121-
self.rep.collect('avg_net_reward', trial, np.mean(self.rep.metrics['net_reward'].ydata[-self.avg_net_reward_window:])) # rolling mean of reward
122-
self.rep.collect('final_deadline', trial, self.env.trial_data['final_deadline']) # final deadline value (time remaining)
123-
self.rep.collect('success', trial, self.env.trial_data['success'])
124-
if self.live_plot:
125-
self.rep.refresh_plot() # autoscales axes, draws stuff and flushes events
126-
127-
# Report final metrics
128-
if self.display:
129-
self.pygame.display.quit() # need to shutdown pygame before showing metrics plot
130-
# TODO: Figure out why having both game and plot displays makes things crash!
131-
132-
if self.live_plot:
133-
self.rep.show_plot() # holds till user closes plot window
134-
135108
def render(self):
136109
# Clear screen
137110
self.screen.fill(self.bg_color)

0 commit comments

Comments
 (0)