Expected utility
A probability describes uncertainty; a utility describes how desirable an outcome is under an explicit set of preferences. Expected utility is the probability-weighted average of possible outcome utilities for a specified action. It gives a way to compare actions when their results are uncertain, but it is not a promise that an individual outcome will equal the average.
A two-action decision tree
A fictional workshop is choosing between two demonstration formats. Option A earns 8 utility points if its uncertain setup succeeds and 0 otherwise. Option B earns 3 points for certain. Initially success probability p is 1/2. Draw a decision node with two branches: A leads to a chance node with outcomes (1/2,8) and (1/2,0); B leads to a single outcome (1,3). Assume these utilities are already on a comparable scale, with larger better, and all constraints have been checked. The numbers are fictional, not financial returns or a recommendation to operate equipment.
Calculate a weighted average
For a finite action a, EU(a) = sum over outcomes o of P(o|a) × U(a,o). The probabilities for that action must be nonnegative and sum to one, and outcomes must be mutually exclusive and exhaustive. A gives 1/2 × 8 + 1/2 × 0 = 4. B gives 1 × 3 = 3. Under these assumptions A has greater expected utility, although a single failure gives it 0 points. If the utility already accounts for risk preferences, do not subtract an unrelated risk penalty twice.
from fractions import Fraction
def expected_utility(outcomes): # Each pair is (exact probability, numeric utility). return sum(p * u for p, u in outcomes)
print(expected_utility([(Fraction(1, 2), 8), (Fraction(1, 2), 0)]))print(expected_utility([(Fraction(1), 3)]))Outputs: 4 and 3. expected_utility assumes valid input pairs and exact rational probabilities. For an actual model validate input and explicitly account for costs, side effects and uncertainty in the probability estimates. A utility is not necessarily money, a probability, or a physical measurement.
Find a decision threshold and check sensitivity
The expected utility of A is 8p; that of B is 3. Equality occurs when p=3/8. Below 3/8 B is better, above it A is better, and at equality either is optimal under this criterion. The next function returns both ties in action order instead of making up a preference. Exact fractions avoid accidental rounding of this threshold. If a plausible range for p is [1/4,1/2], the preferred choice changes within the range. That is a reason to investigate further, not to conceal the uncertainty.
from fractions import Fraction
def expected_utility(outcomes): # Each pair is (exact probability, numeric utility). return sum(p * u for p, u in outcomes)
def best_actions(p): scores = {"A": 8 * p, "B": Fraction(3)} best = max(scores.values()) return [name for name, score in scores.items() if score == best]
for p in (Fraction(1, 4), Fraction(3, 8), Fraction(1, 2)): print(best_actions(p))The outputs are ['B'], ['A', 'B'], and ['A']. The function assumes a Fraction between 0 and 1. Changing a cost or utility changes the threshold. For example, if A also consumes one point regardless of success, EU(A)=8p−1 and the threshold becomes 1/2. Treat hard restrictions separately: a prohibited action is excluded even when its score is high.
From one decision to a sequence
A Markov model describes transitions where the current state is sufficient for predicting the next state distribution under the model. A Markov decision process (MDP) adds actions and rewards to a fully observed state model. If the state is not directly observable, a partially observable MDP uses noisy observations and reasoning about possible states, for example maintaining a belief distribution. Unlike this one-step example, such models compare policies over a sequence of decisions, considering future rewards and consequences. They do not require that actual environments satisfy the Markov assumption. This is an introduction, not a complete MDP or POMDP solver.
Practice and responsible limits
For p=1/4, 3/8 and 1/2, calculate both action scores before running best_actions. Add the one-point setup cost and check the new tie. Explain how a wrong probability, omitted outcome or unsuitable utility could reverse the result. Do not automate consequential decisions just because a numerical score is available. Use the project to document assumptions, constraints and sensitivity; the next chapter introduces how ML estimates patterns from data.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Expected utility — understanding check
Apply the chapter concepts to new situations.
At p=1/2, what is the expected utility of A?
At which p do A and B tie?
A plausible interval for p contains values strictly below and above 3/8. What follows under the lesson utilities?
If A costs one utility point regardless of outcome, what is its new expected utility?
Which model explicitly represents sequential decisions with a state that is not fully observed and observations that may be noisy?