Q-Values from State Values
Problem Statement
Given state values V, recover the action values for one state. Each action a provides reward[a] and a next-state distribution P[a] (P[a][s']):
Implement q_from_v(reward, P, gamma, V) returning the list of Q-values, one per action.
Example
q_from_v([1.0, 0.0], [[1.0, 0.0], [0.0, 1.0]], 0.9, [0.0, 10.0])
[1.0, 9.0]
- Action 0 Calculation: For the first action, the immediate reward is . The expected value of the next state is computed by weighting the state values by the transition probabilities , resulting in .
- Action 0 Q-Value: The Q-value is the sum of the immediate reward and the discounted expected future value: .
- Action 1 Calculation: For the second action, the immediate reward is . The expected value of the next state is computed using the transition probabilities , resulting in .
- Action 1 Q-Value: The Q-value is the sum of the immediate reward and the discounted expected future value: .
- The final output is [1.0, 9.0]
Constraints
len(reward) == len(P)(one row per action).- Each
P[a]aligns withVand sums to 1. - Return a list of floats.