TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

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 rounded to four decimals.

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 rounded to four decimals

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
Gae ComputationPolicy Gradient LossDiscount ReturnsTd Value UpdateQ Learning Update

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: array

Accepts: number

You must run your code first.
PrevNext

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 rounded to four decimals.

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 rounded to four decimals

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
Gae ComputationPolicy Gradient LossDiscount ReturnsTd Value UpdateQ Learning Update

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

Accepts: array

Accepts: number

You must run your code first.