PIXELBANKv9.1.0
Menu

Expected Immediate Reward of a Policy

Problem Statement

For a single state, the expected immediate reward under a policy is:

rπ(s)=∑aπ(a∣s) r(s,a)r^\pi(s) = \sum_a \pi(a\mid s)\, r(s, a)

Given the policy pi and the per-action expected rewards r (aligned by action), implement expected_reward(pi, r).

Example:

Input:
expected_reward([0.5, 0.5], [1.0, 3.0])
Output:
2.0
Reasoning:
  • Identify the policy probabilities and corresponding rewards from the input: the policy is Ï€=[0.5,0.5]\pi = [0.5, 0.5] and the rewards are r=[1.0,3.0]r = [1.0, 3.0].
  • Calculate the contribution of the first action by multiplying its probability by its reward: 0.5×1.0=0.50.5 \times 1.0 = 0.5.
  • Calculate the contribution of the second action by multiplying its probability by its reward: 0.5×3.0=1.50.5 \times 3.0 = 1.5.
  • Sum these individual contributions to find the total expected immediate reward: 0.5+1.5=2.00.5 + 1.5 = 2.0.
  • The final output is 2.0

Constraints:

  • len(pi) == len(r), valid distribution.
  • Return 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.
Expected Immediate Reward of a Policy - Easy | PixelBank