TensorTonic
Problems
Advantage Computation
Reinforcement Learning
Easy

Compute the Monte Carlo advantage at every time step of a completed episode. First compute each discounted return backward:

Gt=rt+γGt+1,GT=0G_t=r_t+\gamma G_{t+1},\qquad G_T=0Gt​=rt​+γGt+1​,GT​=0

Then subtract the value baseline for the visited state:

At=Gt−V(st)A_t=G_t-V(s_t)At​=Gt​−V(st​)

Here, rtr_trt​ is the reward at time ttt, γ\gammaγ is the discount factor, and V(st)V(s_t)V(st​) is the estimated value of the current state. Do not bootstrap beyond the final reward. Return the advantages as a NumPy array. You do not need to round the returned advantages; answers that match the expected values to four decimal places are accepted.

Loading visualization...

Examples

Input: states = [0, 1, 2], rewards = [1, 2, 3], V = [0.5, 1, 1.5], gamma = 1

Output: [5.5, 4, 1.5]

Explanation: The returns are [6, 5, 3], and subtracting the three state baselines gives the advantages.

Input: states = [0, 1, 2], rewards = [1, 2, 3], V = [0, 0, 0], gamma = 0

Output: [1, 2, 3]

Hint 1

Fill a return array backward with running = rewards[index] + gamma * running.

Hint 2

Index the baseline vector with values[np.asarray(states, dtype=int)].

Requirements

  • Compute all returns in one backward pass
  • Subtract the value associated with each visited state
  • Do not add a value estimate after the final reward
  • Return a NumPy array; rounding to four decimals is optional

Constraints

  • states and rewards are nonempty lists of equal length
  • Every state index is valid for V
  • 0 <= gamma <= 1
  • Use NumPy only
Try Similar Problems
Discounted ReturnsEasyTabular Q-Learning (Single Update)EasyOne-Step TD Value UpdateEasyGeneralized Advantage EstimationMediumPolicy Gradient LossMediumFind a Go Group and Its LibertiesEasyInitialize Legal MCTS Edge StatisticsEasyMonte Carlo Policy EvaluationEasyEpsilon-Greedy Action SelectionEasyDouble DQN TargetEasySoftmax (Boltzmann) ExplorationEasyQ-Learning UpdateEasy
Scratchpad

Accepts: array

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
Advantage Computation

Advantage Computation

Reinforcement Learning
Easy

Compute the Monte Carlo advantage at every time step of a completed episode. First compute each discounted return backward:

Gt=rt+γGt+1,GT=0G_t=r_t+\gamma G_{t+1},\qquad G_T=0Gt​=rt​+γGt+1​,GT​=0

Then subtract the value baseline for the visited state:

At=Gt−V(st)A_t=G_t-V(s_t)At​=Gt​−V(st​)

Here, rtr_trt​ is the reward at time ttt, γ\gammaγ is the discount factor, and V(st)V(s_t)V(st​) is the estimated value of the current state. Do not bootstrap beyond the final reward. Return the advantages as a NumPy array. You do not need to round the returned advantages; answers that match the expected values to four decimal places are accepted.

Loading visualization...

Examples

Input: states = [0, 1, 2], rewards = [1, 2, 3], V = [0.5, 1, 1.5], gamma = 1

Output: [5.5, 4, 1.5]

Explanation: The returns are [6, 5, 3], and subtracting the three state baselines gives the advantages.

Input: states = [0, 1, 2], rewards = [1, 2, 3], V = [0, 0, 0], gamma = 0

Output: [1, 2, 3]

Hint 1

Fill a return array backward with running = rewards[index] + gamma * running.

Hint 2

Index the baseline vector with values[np.asarray(states, dtype=int)].

Requirements

  • Compute all returns in one backward pass
  • Subtract the value associated with each visited state
  • Do not add a value estimate after the final reward
  • Return a NumPy array; rounding to four decimals is optional

Constraints

  • states and rewards are nonempty lists of equal length
  • Every state index is valid for V
  • 0 <= gamma <= 1
  • Use NumPy only
Try Similar Problems
Discounted ReturnsEasyTabular Q-Learning (Single Update)EasyOne-Step TD Value UpdateEasyGeneralized Advantage EstimationMediumPolicy Gradient LossMediumFind a Go Group and Its LibertiesEasyInitialize Legal MCTS Edge StatisticsEasyMonte Carlo Policy EvaluationEasyEpsilon-Greedy Action SelectionEasyDouble DQN TargetEasySoftmax (Boltzmann) ExplorationEasyQ-Learning UpdateEasy
Scratchpad

Accepts: array

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
Problems
Loading...
1 / 1