Skip to content

Commit

Permalink
Merge pull request #38 from Santara/master
Browse files Browse the repository at this point in the history
Added stochasticity to action outcomes
  • Loading branch information
rudrasohan authored Dec 15, 2019
2 parents 0badebb + 057d935 commit 5e9cf13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions MADRaS/envs/data/sim_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ server_config:
- car1-stock2

randomize_env: True
add_noise_to_actions: True
action_noise_std: 0.01 # Only in effect when add_noise_to_actions is True
noisy_observations: True # Adds sensor noise. See Section 7.7 of the scr_server paper: https://arxiv.org/abs/1304.1672

vision: False # whether to use vision input
throttle: True
gear_change: False
Expand Down
11 changes: 10 additions & 1 deletion MADRaS/envs/gym_madras.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __init__(self):
self.traffic = []
self.server_config = {}
self.randomize_env = False
self.add_noise_to_actions = False
self.action_noise_std = 0.001
self.noisy_observations = False

def update(self, cfg_dict):
"""Update the configuration terms from a dictionary.
Expand All @@ -79,7 +82,8 @@ def update(self, cfg_dict):
'pid_latency', 'visualise', 'no_of_visualizations', 'track_len',
'max_steps', 'target_speed', 'early_stop', 'accel_pid',
'steer_pid', 'normalize_actions', 'observations', 'rewards', 'dones',
'pid_settings', 'traffic', "server_config", "randomize_env"]
'pid_settings', 'traffic', "server_config", "randomize_env",
'add_noise_to_actions', 'action_noise_std', 'noisy_observations']
for key in direct_attributes:
if key in cfg_dict:
exec("self.{} = {}".format(key, cfg_dict[key]))
Expand Down Expand Up @@ -201,6 +205,8 @@ def start_torcs_process(self):
command = 'export TORCS_PORT={} && torcs -t 10000000 -r ~/.torcs/config/raceman/quickrace.xml -nolaptime'.format(self.torcs_server_port)
if self._config.vision is True:
command += ' -vision'
if self._config.noisy_observations:
command += ' -noisy'

self.torcs_proc = subprocess.Popen([command], shell=True, preexec_fn=os.setsid)
time.sleep(1)
Expand Down Expand Up @@ -354,6 +360,9 @@ def step_pid(self, desire):

def step(self, action):
self.step_num += 1
if self._config.add_noise_to_actions:
noise = np.random.normal(scale=self._config.action_noise_std, size=self.action_dim)
action += noise
if self._config.pid_assist:
return self.step_pid(action)
else:
Expand Down
5 changes: 4 additions & 1 deletion MADRaS/utils/gym_torcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TorcsEnv:
default_speed = 50
initial_reset = False

def __init__(self, vision=False, throttle=False, gear_change=False, obs_dim=29, act_dim=3,visualise=False,no_of_visualisations=1, torcs_server_port=3001, name='MadrasAgent'):
def __init__(self, vision=False, throttle=False, gear_change=False, obs_dim=29, act_dim=3,visualise=False,no_of_visualisations=1, torcs_server_port=3001, name='MadrasAgent', noisy_observations=False):
self.name = name
self.vision = vision
self.throttle = throttle
Expand All @@ -40,6 +40,7 @@ def __init__(self, vision=False, throttle=False, gear_change=False, obs_dim=29,
self.currState = None
self.no_of_visualisations = no_of_visualisations
self.torcs_server_port = torcs_server_port
self.noisy_observations = noisy_observations
self.set_observation_and_action_spaces()


Expand Down Expand Up @@ -220,6 +221,8 @@ def reset_torcs(self, client):
command = 'export TORCS_PORT={} && torcs -t 10000000 -r ~/.torcs/config/raceman/quickrace.xml -nolaptime'.format(self.torcs_server_port)
if self.vision is True:
command += ' -vision'
if self.noisy_observations:
command += ' -noisy'
self.torcs_proc = subprocess.Popen([command], shell=True, preexec_fn=os.setsid)
time.sleep(1)

Expand Down

0 comments on commit 5e9cf13

Please sign in to comment.