Created
May 11, 2019 02:15
-
-
Save amaarora/d41b89d8d9e4e46f5aa7f41fcbbafb21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reward_function(params): | |
''' | |
Example of rewarding the agent to stay within boundary | |
''' | |
import math | |
# Read input parameters | |
track_width = params['track_width'] | |
distance_from_center = params['distance_from_center'] | |
steering = abs(params['steering_angle']) | |
all_wheels_on_track = params['all_wheels_on_track'] | |
steering_angle = params['steering_angle'] | |
is_left_of_center = params['is_left_of_center'] | |
waypoints = params['waypoints'] | |
closest_waypoints = params['closest_waypoints'] | |
heading = params['heading'] | |
speed = params['speed'] | |
# Give a high reward if no wheels go off the track and | |
# the agent is somewhere in between the track borders | |
distance_from_border = (0.5*track_width) - distance_from_center | |
if all_wheels_on_track and distance_from_border >= 0.15: | |
reward = 1.0 | |
else: | |
reward = 1e-3 | |
# Punish heavily if not all_wheels_on_track | |
if not all_wheels_on_track: | |
reward *= -1 | |
return float(reward) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment