Estimate a state-value function with first-visit Monte Carlo evaluation. Each episode is a list of [state, reward] pairs. For time step t, the discounted return is:
Gt=rt+γrt+1+γ2rt+2+⋯For each state, use only its earliest occurrence in each episode and average those first-visit returns across episodes. States that are never visited retain value zero. Return all state values as a NumPy array of length n_states, rounded to four decimals.
Input: episodes = [[[0, 1], [1, 2], [2, 3]]], gamma = 1, n_states = 3
Output: [6, 5, 3]
Explanation: With no discounting, returns from the three positions are 6, 5, and 3.
Input: episodes = [[[0, 1], [0, -5], [0, 2]]], gamma = 1, n_states = 1
Output: [-2]
Fill a return array backward with running = reward + gamma * running.
Scan the episode forward with a set so only the first occurrence contributes.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number
Estimate a state-value function with first-visit Monte Carlo evaluation. Each episode is a list of [state, reward] pairs. For time step t, the discounted return is:
Gt=rt+γrt+1+γ2rt+2+⋯For each state, use only its earliest occurrence in each episode and average those first-visit returns across episodes. States that are never visited retain value zero. Return all state values as a NumPy array of length n_states, rounded to four decimals.
Input: episodes = [[[0, 1], [1, 2], [2, 3]]], gamma = 1, n_states = 3
Output: [6, 5, 3]
Explanation: With no discounting, returns from the three positions are 6, 5, and 3.
Input: episodes = [[[0, 1], [0, -5], [0, 2]]], gamma = 1, n_states = 1
Output: [-2]
Fill a return array backward with running = reward + gamma * running.
Scan the episode forward with a set so only the first occurrence contributes.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number