PIXELBANKv9.1.0
Menu

Bellman Optimality Backup

Problem Statement

The Bellman optimality backup takes a max over actions instead of a policy average:

V∗(s)=max⁡a[R(s,a)+γ∑s′P(s′∣s,a) V(s′)]V^*(s) = \max_a \left[ R(s,a) + \gamma \sum_{s'} P(s'\mid s,a)\, V(s') \right]

You are given, for one state, a list of actions. Each action is a dict {"reward": r, "probs": [...], "values": [...]}. Return the optimal state value. Implement bellman_optimality(actions, gamma).

Example:

Input:
bellman_optimality([{"reward":1.0,"probs":[1.0],"values":[0.0]},{"reward":0.0,"probs":[1.0],"values":[10.0]}], 0.9)
Output:
9.0
Reasoning:
  • Evaluate the first action by combining its immediate reward with the discounted expected value of the next state: Q1=1.0+0.9×(1.0×0.0)=1.0Q_1 = 1.0 + 0.9 \times (1.0 \times 0.0) = 1.0.
  • Evaluate the second action similarly, noting that it has no immediate reward but leads to a high-value state with certainty: Q2=0.0+0.9×(1.0×10.0)=9.0Q_2 = 0.0 + 0.9 \times (1.0 \times 10.0) = 9.0.
  • Apply the optimality principle by selecting the maximum Q-value among all available actions to determine the optimal state value: max⁡(1.0,9.0)=9.0\max(1.0, 9.0) = 9.0.
  • The final output is 9.0

Constraints:

  • 1 <= len(actions) <= 1000
  • Each action's probs sum to 1 and align with values.
  • Return the max backed-up value (a float).
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.