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

Value Iteration Step

Reinforcement Learning
Medium

Perform one value-iteration update for a Markov decision process. For every state, evaluate each action using its immediate reward and expected discounted next-state value, then keep the best action value.

Vnew(s)=max⁡a[R(s,a)+γ∑s′T(s,a,s′)V(s′)]V_{\mathrm{new}}(s) = \max_a \left[ R(s,a) + \gamma \sum_{s'} T(s,a,s')V(s') \right]Vnew​(s)=amax​[R(s,a)+γs′∑​T(s,a,s′)V(s′)]

Here:

  • sss is the current state and s′s's′ is a possible next state
  • aaa is an available action
  • R(s,a)R(s,a)R(s,a) is the immediate reward
  • T(s,a,s′)T(s,a,s')T(s,a,s′) is the probability of transitioning to s′s's′
  • V(s′)V(s')V(s′) is the current value estimate
  • γ\gammaγ is the discount factor

Return the updated value of every state as a list of floats.

Loading visualization...

Examples

Input: values = [0, 0], transitions = [[[0.8, 0.2], [0.3, 0.7]], [[0.5, 0.5], [0.1, 0.9]]], rewards = [[1, 2], [-1, 0]], gamma = 0.9

Output: [2.0, 0.0]

Explanation: With zero current values, only immediate rewards contribute, so the best rewards are 2 and 0.

Input: values = [0, 0, 0], transitions = [[[0, 1, 0], [0, 0, 1]], [[1, 0, 0], [0, 0, 1]], [[0, 1, 0], [1, 0, 0]]], rewards = [[1, 2], [3, 0], [-1, 5]], gamma = 0.9

Output: [2.0, 3.0, 5.0]

Hint 1

sum(probability * value for probability, value in zip(action_transitions, values)) computes one expected next-state value.

Hint 2

Use max() over the action values computed for each state.

Requirements

  • values contains one current value for every state
  • transitions has shape (S,A,S)(S, A, S)(S,A,S) and rewards has shape (S,A)(S, A)(S,A)
  • Use the supplied transition probabilities, rewards, and discount factor without modifying them
  • Return a list of SSS updated floating-point values

Constraints

  • The process contains at least one state and one action
  • Every transition-probability row sums to 1
  • 0≤γ≤10 \leq \gamma \leq 10≤γ≤1
Try Similar Problems
Q Learning UpdateSarsa UpdateTd Value UpdateMc Policy EvaluationDiscount Returns

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

Value Iteration Step

Reinforcement Learning
Medium

Perform one value-iteration update for a Markov decision process. For every state, evaluate each action using its immediate reward and expected discounted next-state value, then keep the best action value.

Vnew(s)=max⁡a[R(s,a)+γ∑s′T(s,a,s′)V(s′)]V_{\mathrm{new}}(s) = \max_a \left[ R(s,a) + \gamma \sum_{s'} T(s,a,s')V(s') \right]Vnew​(s)=amax​[R(s,a)+γs′∑​T(s,a,s′)V(s′)]

Here:

  • sss is the current state and s′s's′ is a possible next state
  • aaa is an available action
  • R(s,a)R(s,a)R(s,a) is the immediate reward
  • T(s,a,s′)T(s,a,s')T(s,a,s′) is the probability of transitioning to s′s's′
  • V(s′)V(s')V(s′) is the current value estimate
  • γ\gammaγ is the discount factor

Return the updated value of every state as a list of floats.

Loading visualization...

Examples

Input: values = [0, 0], transitions = [[[0.8, 0.2], [0.3, 0.7]], [[0.5, 0.5], [0.1, 0.9]]], rewards = [[1, 2], [-1, 0]], gamma = 0.9

Output: [2.0, 0.0]

Explanation: With zero current values, only immediate rewards contribute, so the best rewards are 2 and 0.

Input: values = [0, 0, 0], transitions = [[[0, 1, 0], [0, 0, 1]], [[1, 0, 0], [0, 0, 1]], [[0, 1, 0], [1, 0, 0]]], rewards = [[1, 2], [3, 0], [-1, 5]], gamma = 0.9

Output: [2.0, 3.0, 5.0]

Hint 1

sum(probability * value for probability, value in zip(action_transitions, values)) computes one expected next-state value.

Hint 2

Use max() over the action values computed for each state.

Requirements

  • values contains one current value for every state
  • transitions has shape (S,A,S)(S, A, S)(S,A,S) and rewards has shape (S,A)(S, A)(S,A)
  • Use the supplied transition probabilities, rewards, and discount factor without modifying them
  • Return a list of SSS updated floating-point values

Constraints

  • The process contains at least one state and one action
  • Every transition-probability row sums to 1
  • 0≤γ≤10 \leq \gamma \leq 10≤γ≤1
Try Similar Problems
Q Learning UpdateSarsa UpdateTd Value UpdateMc Policy EvaluationDiscount Returns

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.