Implement a validated strategy selector
Implement choose_strategy(belief, strategies, budget). Validate probabilities and finite utility values, filter unaffordable strategies, and return the positive-utility winner or None.
Your task
- Belief is a nonempty mapping from state names to finite nonnegative numeric probabilities summing to one within math.isclose tolerance 1e-9.
- Each strategy has a unique nonempty name, a finite nonnegative cost, and a values mapping whose keys exactly match belief. Numeric fields accept int or float but reject bool, NaN, and infinity.
- Budget is finite and nonnegative. Raise ValueError for any invalid data, including invalid strategies that would be over budget.
- Utility is sum(belief[state] * values[state]) minus cost. Only strategies with cost <= budget are eligible.
- Return the eligible strategy name with greatest strictly positive utility; break equal utilities by lexicographic name. Return None when no eligible positive-utility strategy exists. Do not mutate inputs.
Examples
EXAMPLE 1
Inputbelief simple=0.6, ambiguous=0.4; direct utility 1.4; retrieve utility 4.6; budget 2
Output'retrieve'
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor