Skip to content

Instantly share code, notes, and snippets.

View ritchieng's full-sized avatar
🤓

Ritchie Ng ritchieng

🤓
View GitHub Profile
Simulator.run(): Trial 95
Environment.reset(): Trial set up with start = (6, 4), destination = (2, 1), deadline = 35
RoutePlanner.route_to(): destination = (2, 1)
LearningAgent.update(): deadline = 35, inputs = {'light': 'green', 'oncoming': None, 'right': None, 'left': None}, action = left, reward = 2.0
LearningAgent.update(): deadline = 34, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = None, reward = 0.0
LearningAgent.update(): deadline = 33, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = None, reward = 0.0
LearningAgent.update(): deadline = 32, inputs = {'light': 'green', 'oncoming': None, 'right': None, 'left': None}, action = forward, reward = 2.0
LearningAgent.update(): deadline = 31, inputs = {'light': 'green', 'oncoming': None, 'right': None, 'left': None}, action = forward, reward = 2.0
LearningAgent.update(): deadline = 30, inputs = {'light': 'green', 'oncoming': None, 'right': None, 'left': None}, action = forward, reward = 2.
# Format of results
(light, next_waypoint)[None, 'forward', 'left', 'right']
('green', 'right', None) ['4.00', '4.00', '4.00', '4.00']
('red', 'right', 'left') ['4.00', '4.00', '4.00', '4.00']
('red', 'forward', None) ['4.00', '4.00', '4.00', '4.00']
('green', 'right', 'left') ['1.44', '4.00', '4.00', '4.00']
('red', None, 'left') ['0.00', '-0.91', '-0.99', '-0.07']
('green', None, None) ['4.00', '4.00', '4.00', '4.00']
('green', 'left', 'left') ['1.44', '4.00', '4.00', '4.00']
import random
from environment import Agent, Environment
from planner import RoutePlanner
from simulator import Simulator
class LearningAgent(Agent):
"""An agent that learns to drive in the smartcab world."""
def __init__(self, env):
super(LearningAgent, self).__init__(env) # sets self.env = env, state = None, next_waypoint = None, and a default color
# Format of results
(light, oncoming, next_waypoint)[None, 'forward', 'left', 'right']
('green', 'right', None) ['4.00', '4.00', '4.00', '4.00']
('red', 'right', 'left') ['4.00', '4.00', '4.00', '4.00']
('red', 'forward', None) ['4.00', '4.00', '4.00', '4.00']
('green', 'right', 'left') ['4.00', '4.00', '4.00', '4.00']
('red', None, 'left') ['0.01', '-0.37', '-0.50', '0.57']
('green', None, None) ['4.00', '4.00', '4.00', '4.00']
('green', 'left', 'left') ['3.16', '2.94', '3.40', '4.00']
import random
from environment import Agent, Environment
from planner import RoutePlanner
from simulator import Simulator
class LearningAgent(Agent):
"""An agent that learns to drive in the smartcab world."""
def __init__(self, env):
super(LearningAgent, self).__init__(env) # sets self.env = env, state = None, next_waypoint = None, and a default color
Environment.reset(): Trial set up with start = (8, 6), destination = (1, 4), deadline = 45
RoutePlanner.route_to(): destination = (1, 4)
LearningAgent.update(): deadline = 45, inputs = {'light': 'green', 'oncoming': None, 'right': None, 'left': None}, action = left, reward = 2.0
LearningAgent.update(): deadline = 44, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = left, reward = -1.0
LearningAgent.update(): deadline = 43, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = left, reward = -1.0
LearningAgent.update(): deadline = 42, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = None, reward = 0.0
LearningAgent.update(): deadline = 41, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = forward, reward = -1.0
LearningAgent.update(): deadline = 40, inputs = {'light': 'green', 'oncoming': None, 'right': None, 'left': None}, action = right, reward = -0.5
LearningAgent.update(): deadl
Simulator.run(): Trial 0
Environment.reset(): Trial set up with start = (3, 6), destination = (7, 5), deadline = 25
RoutePlanner.route_to(): destination = (7, 5)
LearningAgent.update(): deadline = 25, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = None, reward = 0.0
LearningAgent.update(): deadline = 24, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = left, reward = -1.0
LearningAgent.update(): deadline = 23, inputs = {'light': 'red', 'oncoming': None, 'right': 'forward', 'left': None}, action = None, reward = 0.0
LearningAgent.update(): deadline = 22, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = right, reward = 2.0
LearningAgent.update(): deadline = 21, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = forward, reward = -1.0
LearningAgent.update(): deadline = 20, inputs = {'light': 'red', 'oncoming': None, 'right': None, 'left': None}, action = right, reward = -0.5
Lea
import random
from environment import Agent, Environment
from planner import RoutePlanner
from simulator import Simulator
class LearningAgent(Agent):
"""An agent that learns to drive in the smartcab world."""
def __init__(self, env):
@ritchieng
ritchieng / most_common_email_p2.py
Created June 30, 2016 15:52
Seeking email that sent the most emails from email logs (text file)
# Seeking email that sent the most emails from email logs (text file)
# 1. Request file name
fname = raw_input('Enter file name: ')
# 2. File handle
fhandle = open(fname)
# 3. Create dictionary
counts = dict()
@ritchieng
ritchieng / key_value_count_sort_p3.py
Created June 30, 2016 15:51
Collate list of timings and counts, sort, and find most/least timings in an email log
# Collate list of timings and counts, sort, and find most/least common timings in an email log
# This script uses mbox.txt to give you an example of how it might work
# 1. Prompt for file to load
fname = input('Enter file name: ')
# 2. File handle to access file
fhandle = open(fname)
# 3a. Create counts dictionary