Created
December 5, 2018 13:24
-
-
Save cmar/7428e93f29c9a8e9b8de50cc5bb423d0 to your computer and use it in GitHub Desktop.
Example Deep Racer Reward Function
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
# example reward function for reinforcement training | |
def reward_function (on_track, x, y, distance_from_center, car_orientation, progress, | |
steps, throttle, steering, track_width, waypoints, closest_waypoint): | |
import math | |
marker_1 = 0.1 * track_width | |
marker_2 = 0.25 * track_width | |
marker_3 = 0.5 * track_width | |
reward = 1e-3 | |
if distance_from_center >= 0.0 and distance_from_center <= marker_1: | |
reward = 1 | |
elif distance_from_center <= marker_2: | |
reward = 0.5 | |
elif distance_from_center <= marker_3: | |
reward = 0.1 | |
else: | |
reward = 1e-3 # likely crashed/ close to off track | |
# penalize reward if the car is steering way too much | |
ABS_STEERING_THRESHOLD = 0.5 | |
if abs(steering) > ABS_STEERING_THRESHOLD: | |
reward *= 0.8 | |
# penalize reward for the car taking slow actions | |
THROTTLE_THRESHOLD = 0.5 | |
if throttle < THROTTLE_THRESHOLD: | |
reward *= 0.8 | |
# add steering penalty | |
if abs(steering) > 0.5: | |
reward *= 0.80 | |
# add throttle penalty | |
if throttle < 0.5: | |
reward *= 0.80 | |
# if on a straight | |
if abs(steering) < 0.1 and throttle > .9: | |
reward *= 1.2 | |
return float(reward) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment