epsilon-greedy 전략으로 CliffWalking 풀기
CliffWalking 환경은 RL 알고리즘을 위한 표준 테스트베드예요. 이 환경은 에이전트가 시작 상태에서 목표 상태까지 절벽을 피해 길을 찾아가야 하는 그리드 월드입니다. epsilon-greedy 전략을 사용하면 에이전트가 환경을 효과적으로 탐색하면서 절벽을 피하는 방법을 학습해 누적 보상을 극대화할 수 있어요. 이번 과제에서는 epsilon-greedy 전략으로 이 환경을 해결하고, 각 학습 에피소드에서 얻은 보상을 계산해 rewards_eps_greedy 리스트에 저장하세요.
이 연습은 강의의 일부입니다
Python으로 배우는 Gymnasium 기반 Reinforcement Learning
연습 안내
- 각 에피소드 안에서
epsilon_greedy()함수를 사용해action을 선택하세요. - 받은
reward를episode_reward에 누적하세요. - 각 에피소드가 끝날 때, 전체
episode_reward를 나중에 분석할 수 있도록rewards_eps_greedy리스트에 추가하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
rewards_eps_greedy = []
for episode in range(total_episodes):
state, info = env.reset()
episode_reward = 0
for i in range(max_steps):
# Select action with epsilon-greedy strategy
action = ____
next_state, reward, terminated, truncated, info = env.step(action)
# Accumulate reward
____
update_q_table(state, action, reward, next_state)
state = next_state
# Append the toal reward to the rewards list
____
print("Average reward per episode: ", np.mean(rewards_eps_greedy))