AWS DeepRacer 보상 함수 예제 - AWS DeepRacer

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS DeepRacer 보상 함수 예제

다음은 몇 가지 AWS DeepRacer 보상 함수 예제입니다.

예제 1: 타임 트라이얼 시 중앙선 따르기

이 예제에서는 에이전트가 중앙선에서 얼마나 멀리 떨어져 있는지 확인하고 트랙의 중앙에 가까울 경우 더 높은 보상을 제공하여 에이전트가 중앙선을 가깝게 따르도록 합니다.

def reward_function(params): ''' Example of rewarding the agent to follow center line ''' # Read input parameters track_width = params['track_width'] distance_from_center = params['distance_from_center'] # Calculate 3 markers that are increasingly further away from the center line marker_1 = 0.1 * track_width marker_2 = 0.25 * track_width marker_3 = 0.5 * track_width # Give higher reward if the car is closer to center line and vice versa if 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 return reward

예제 2: 타임 트라이얼에서 두 경계선 사이를 유지

이 예제는 에이전트가 경계선 안쪽을 유지하면 높은 보상을 제공하고 에이전트가 랩을 완주하는 데 가장 좋은 경로를 알아내도록 합니다. 프로그래밍하고 이해하기는 쉽지만 수렴하는 데 시간이 오래 걸립니다.

def reward_function(params): ''' Example of rewarding the agent to stay inside the two borders of the track ''' # Read input parameters all_wheels_on_track = params['all_wheels_on_track'] distance_from_center = params['distance_from_center'] track_width = params['track_width'] # Give a very low reward by default reward = 1e-3 # Give a high reward if no wheels go off the track and # the car is somewhere in between the track borders if all_wheels_on_track and (0.5*track_width - distance_from_center) >= 0.05: reward = 1.0 # Always return a float value return reward

예제 3: 타임 트라이얼에서 지그재그 주행 방지

이 예제는 에이전트가 중앙선을 추종하도록 장려하지만 조향이 너무 많을 경우 보상이 감소하여 지그재그 행동을 방지하는 데 도움이 됩니다. 에이전트가 시뮬레이터에서 원활한 주행 방법을 학습하여 실제 차량에 배치되었을 때도 동일한 행동을 유지할 가능성이 높습니다.

def reward_function(params): ''' Example of penalize steering, which helps mitigate zig-zag behaviors ''' # Read input parameters distance_from_center = params['distance_from_center'] track_width = params['track_width'] abs_steering = abs(params['steering_angle']) # Only need the absolute steering angle # Calculate 3 marks that are farther and father away from the center line marker_1 = 0.1 * track_width marker_2 = 0.25 * track_width marker_3 = 0.5 * track_width # Give higher reward if the car is closer to center line and vice versa if distance_from_center <= marker_1: reward = 1.0 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 # Steering penality threshold, change the number based on your action space setting ABS_STEERING_THRESHOLD = 15 # Penalize reward if the car is steering too much if abs_steering > ABS_STEERING_THRESHOLD: reward *= 0.8 return float(reward)

예제 4: 정지 장애물 또는 이동 차량에 충돌하지 않고 한 차선을 유지

이 보상 함수는 에이전트가 트랙 경계선 사이를 유지하면 보상을 제공하고, 전방 객체에 너무 접근하면 페널티를 부여합니다. 에이전트는 충돌을 회피하기 위해 차선을 변경할 수 있습니다. 총 보상은 보상과 페널티의 가중 합계입니다. 이 예제에서는 충돌을 회피하여 안전에 더 집중하도록 페널티에 더 많은 가중치를 부여합니다. 다양한 평균 가중치를 실험하여 다양한 행동 결과에 대해 훈련합니다.

import math def reward_function(params): ''' Example of rewarding the agent to stay inside two borders and penalizing getting too close to the objects in front ''' all_wheels_on_track = params['all_wheels_on_track'] distance_from_center = params['distance_from_center'] track_width = params['track_width'] objects_location = params['objects_location'] agent_x = params['x'] agent_y = params['y'] _, next_object_index = params['closest_objects'] objects_left_of_center = params['objects_left_of_center'] is_left_of_center = params['is_left_of_center'] # Initialize reward with a small number but not zero # because zero means off-track or crashed reward = 1e-3 # Reward if the agent stays inside the two borders of the track if all_wheels_on_track and (0.5 * track_width - distance_from_center) >= 0.05: reward_lane = 1.0 else: reward_lane = 1e-3 # Penalize if the agent is too close to the next object reward_avoid = 1.0 # Distance to the next object next_object_loc = objects_location[next_object_index] distance_closest_object = math.sqrt((agent_x - next_object_loc[0])**2 + (agent_y - next_object_loc[1])**2) # Decide if the agent and the next object is on the same lane is_same_lane = objects_left_of_center[next_object_index] == is_left_of_center if is_same_lane: if 0.5 <= distance_closest_object < 0.8: reward_avoid *= 0.5 elif 0.3 <= distance_closest_object < 0.5: reward_avoid *= 0.2 elif distance_closest_object < 0.3: reward_avoid = 1e-3 # Likely crashed # Calculate reward by putting different weights on # the two aspects above reward += 1.0 * reward_lane + 4.0 * reward_avoid return reward