Epsilon-greediness
이 연습 문제에서는 감쇠된 epsilon-greediness를 적용하는 select_action() 함수를 구현해 보겠습니다.
Epsilon-greediness는 에이전트가 환경을 더 탐색하도록 유도해 학습 성능을 높이는 데 도움이 됩니다!
Epsilon-greediness 스케줄은 주어진 step에 대해 다음 식으로 임계값 $\varepsilon$를 결정합니다:
$$\varepsilon = end + (start-end) \cdot e^{-\frac{step}{decay}}$$
select_action()은 확률 $\varepsilon$로 무작위 행동을, 확률 $1-\varepsilon$로 가장 높은 Q-value를 갖는 행동을 반환해야 합니다.
이 연습은 강의의 일부입니다
Python으로 배우는 Deep Reinforcement Learning
연습 안내
- 주어진
step값에 대한 임계값epsilon을 계산하세요. - 0과 1 사이의 난수를 하나 추출하세요.
- 확률
epsilon으로 무작위 행동을 반환하세요. - 확률
1-epsilon으로 가장 높은 Q-value를 갖는 행동을 반환하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
def select_action(q_values, step, start, end, decay):
# Calculate the threshold value for this step
epsilon = end + (____) * math.exp(____ / ____)
# Draw a random number between 0 and 1
sample = random.____
if sample < epsilon:
# Return a random action index
return random.____
# Return the action index with highest Q-value
return torch.____.item()
for step in [1, 500, 2500]:
actions = [select_action(torch.Tensor([1, 2, 3, 5]), step, .9, .05, 1000) for _ in range(20)]
print(f"Selecting 20 actions at step {step}.\nThe action with highest q-value is action 3.\nSelected actions: {actions}\n\n")