Artificial Intelligence

Reasoning Under Uncertainty

Decision Theory & Utility

Chapters 1-4 answered probabilistic belief questions: what's the probability of X, given evidence Y? Decision theory answers the natural follow-up: given everyt

JrCodex·8 min read

Jr Codex AI Notes

Level: Intermediate–Advanced Prerequisites: Chapter 4 Time to complete: ~25 minutes


Table of Contents

  1. From "What's True?" to "What Should I Do?"
  2. Utility Theory
  3. Expected Utility
  4. The Maximum Expected Utility Principle
  5. Decision Networks
  6. The Value of Information
  7. Why This Completes the Rationality Picture
  8. Summary & Next Steps

1. From "What's True?" to "What Should I Do?"

Chapters 1-4 answered probabilistic belief questions: what's the probability of X, given evidence Y? Decision theory answers the natural follow-up: given everything I believe, what action should I actually take? This connects directly back to Module 1, Chapter 4's definition of a rational agent.

Probabilistic Reasoning (Ch.1-4)        Decision Theory (this chapter)
─────────────────────────────         ─────────────────────────────
  "What's P(rain tomorrow)?"              "GIVEN P(rain)=70%, should
                                             I bring an umbrella?"

  A belief about the WORLD                  An ACTION, weighing
                                              probability AND how much
                                              I CARE about each outcome
─────────────────────────────         ─────────────────────────────

2. Utility Theory

Utility is a numerical measure of how desirable an outcome is to an agent — it lets fundamentally different outcomes (money, time, health, comfort) be compared on a single, consistent scale.

# A utility function maps OUTCOMES to a number representing DESIRABILITY
def umbrella_utility(brought_umbrella, it_rained):
    if brought_umbrella and it_rained:
        return 80        # stayed dry, minor inconvenience of carrying it
    elif brought_umbrella and not it_rained:
        return 70        # stayed dry, but carried it needlessly (mild annoyance)
    elif not brought_umbrella and it_rained:
        return 10        # got soaked — BAD outcome
    else:
        return 100        # no umbrella needed, didn't carry one — BEST outcome
Utility Is PERSONAL and CONTEXT-DEPENDENT
─────────────────────────────────────────
  A frequent traveler might weight "getting soaked" as far
  WORSE than these numbers suggest (ruined meetings, sick
  days) — utility values encode an agent's OWN priorities,
  not a universal, objective truth.

  This is directly connected to Module 1, Chapter 4's PEAS
  framework — the "Performance Measure" component IS,
  formally, a utility function.
─────────────────────────────────────────

3. Expected Utility

Since outcomes are uncertain (Chapters 1-4's probability), a rational agent should weigh each possible outcome by both its utility and its probability — this is expected utility.

Expected Utility Formula
─────────────────────────────────────────
  EU(action) = Σ P(outcome | action) × Utility(outcome)

  Sum, over every POSSIBLE outcome of taking this action,
  the PROBABILITY of that outcome times how DESIRABLE it is.
─────────────────────────────────────────
def expected_utility(action_outcomes):
    """action_outcomes: list of (probability, utility) tuples for one action"""
    return sum(prob * utility for prob, utility in action_outcomes)
 
p_rain = 0.7
p_no_rain = 0.3
 
eu_bring_umbrella = expected_utility([
    (p_rain, umbrella_utility(True, True)),        # 0.7 * 80
    (p_no_rain, umbrella_utility(True, False)),       # 0.3 * 70
])
 
eu_no_umbrella = expected_utility([
    (p_rain, umbrella_utility(False, True)),          # 0.7 * 10
    (p_no_rain, umbrella_utility(False, False)),        # 0.3 * 100
])
 
print(f"EU(bring umbrella): {eu_bring_umbrella:.1f}")      # 77.0
print(f"EU(no umbrella): {eu_no_umbrella:.1f}")              # 37.0

Given a 70% chance of rain, bringing the umbrella has much higher expected utility (77.0 vs 37.0) — even though it's not guaranteed to be the best choice on any specific day (if it happens not to rain, no umbrella scores higher that day), it's the better choice on average, across the actual probability of rain.


4. The Maximum Expected Utility Principle

The Rational Choice Rule
─────────────────────────────────────────
  A RATIONAL agent should choose the action that MAXIMIZES
  expected utility:

  best_action = argmax_action  EU(action)
─────────────────────────────────────────
def choose_best_action(actions_with_outcomes):
    """actions_with_outcomes: dict action_name -> list of (probability, utility) tuples"""
    utilities = {
        action: expected_utility(outcomes)
        for action, outcomes in actions_with_outcomes.items()
    }
    best_action = max(utilities, key=utilities.get)
    return best_action, utilities
 
 
actions = {
    "bring_umbrella": [(0.7, 80), (0.3, 70)],
    "no_umbrella":    [(0.7, 10), (0.3, 100)],
}
best, all_utilities = choose_best_action(actions)
print(f"Best action: {best}")      # "bring_umbrella"
print(all_utilities)                 # {'bring_umbrella': 77.0, 'no_umbrella': 37.0}

This is a precise, formal completion of Module 1, Chapter 4's rationality definition: a rational agent maximizes expected utility given its beliefs, not actual outcome — exactly resolving that earlier chapter's point that a rational agent can still get "unlucky" on any specific occasion without its decision process having been irrational.


5. Decision Networks

A decision network (also called an "influence diagram") extends Chapter 2's Bayesian networks with two new node types, formally combining probabilistic belief with the choice of action.

Decision Network Node Types
─────────────────────────────────────────
  Chance nodes (ovals):     random variables, exactly like
                               Chapter 2's Bayesian network nodes
                               — e.g. "Weather"

  Decision nodes (rectangles):  a CHOICE the agent controls
                                   — e.g. "BringUmbrella?"

  Utility nodes (diamonds):        the OUTCOME'S desirability,
                                     depending on both chance AND
                                     decision nodes
─────────────────────────────────────────
A Simple Decision Network
─────────────────────────────────────────
    [Weather]  (chance node)         [BringUmbrella?]  (decision node)
         \                                    /
          \                                  /
           ▼                                ▼
                      [Utility]
                   (depends on BOTH)
─────────────────────────────────────────
def evaluate_decision_network(weather_prob, utility_fn):
    """
    Evaluate every possible decision by computing expected utility
    over the chance node's distribution — directly using Chapter 2's
    joint-probability-style reasoning, now feeding into Section 3's
    expected utility calculation.
    """
    decisions = ["bring_umbrella", "no_umbrella"]
    results = {}
 
    for decision in decisions:
        eu = sum(
            prob * utility_fn(decision, weather)
            for weather, prob in weather_prob.items()
        )
        results[decision] = eu
 
    return results
 
def utility_fn(decision, weather):
    if decision == "bring_umbrella":
        return 80 if weather == "rainy" else 70
    else:
        return 10 if weather == "rainy" else 100
 
weather_distribution = {"rainy": 0.7, "sunny": 0.3}
decision_results = evaluate_decision_network(weather_distribution, utility_fn)
print(decision_results)      # matches Section 4's results, now framed as a formal network

A decision network is a natural, direct extension of everything built across this module — Chapter 2's chance nodes and CPTs, combined with this chapter's utility and expected-utility machinery, formalized into a single graphical structure that can represent arbitrarily complex real-world decisions.


6. The Value of Information

A powerful, practical question decision theory can answer precisely: is it worth the cost to gather more information before deciding?

The Value of Information (VOI)
─────────────────────────────────────────
  VOI = [Expected utility WITH the new information]
         − [Expected utility WITHOUT it]

  If VOI > cost of obtaining the information, it's WORTH
  gathering before deciding. If VOI <= cost, decide now —
  more information isn't worth the delay/expense.
─────────────────────────────────────────
# Is it worth checking a (perfectly accurate, for simplicity) weather forecast
# before deciding whether to bring an umbrella?
 
eu_without_forecast = max(decision_results.values())      # best you can do WITHOUT knowing for sure
 
# WITH a perfect forecast, you'd always make the BEST choice for whatever it says
eu_with_perfect_forecast = (
    weather_distribution["rainy"] * utility_fn("bring_umbrella", "rainy") +      # correctly bring it when rainy
    weather_distribution["sunny"] * utility_fn("no_umbrella", "sunny")             # correctly skip it when sunny
)
 
value_of_information = eu_with_perfect_forecast - eu_without_forecast
print(f"Value of a perfect forecast: {value_of_information:.1f}")      # how much better-off you'd be, on average

This is exactly the formal reasoning behind real decisions like "should I pay for a weather app, get a second medical opinion, or run an additional experiment before committing?" — the Data Science Notes' A/B testing chapter covers a closely related idea (is it worth running a larger experiment before deciding whether to ship a feature?), approached from a slightly different but philosophically aligned angle.


7. Why This Completes the Rationality Picture

Tracing the Full Arc of This Curriculum So Far
─────────────────────────────────────────
  Module 1, Ch.4:    defined a rational agent abstractly —
                        "chooses the action expected to best
                        achieve its performance measure"

  Module 3:              gave agents a way to represent KNOWLEDGE
                            and REASON about it logically (but
                            only in strict true/false terms)

  Module 4, Ch.1-4:          extended reasoning to handle genuine
                                UNCERTAINTY via probability

  Module 4, Ch.5 (HERE):        completes the picture — showing
                                    EXACTLY how a rational agent
                                    should convert probabilistic
                                    belief into a concrete ACTION,
                                    using expected utility
─────────────────────────────────────────

Decision theory is the mathematical bridge between "what do I believe is likely true" and "what should I actually do about it" — precisely the gap between Module 3's pure logic and a genuinely useful, acting AI agent.


8. Summary & Next Steps

Key Takeaways

  • Decision theory answers "what should I do?" by combining probabilistic belief (Chapters 1-4) with utility — a numerical measure of how desirable each outcome is to a specific agent.
  • Expected utility weighs each possible outcome by both its probability and its utility; the Maximum Expected Utility principle says a rational agent should choose the action maximizing this value.
  • Decision networks extend Chapter 2's Bayesian networks with decision nodes (choices) and utility nodes (outcome desirability), formalizing real-world decisions graphically.
  • The Value of Information quantifies whether gathering more information before deciding is actually worth its cost — a precise, decision-theoretic answer to a common practical dilemma.
  • This chapter completes Module 1, Chapter 4's abstract definition of rationality with a concrete mathematical recipe: maximize expected utility, given probabilistic beliefs.

Module 4 Complete — Next Module

You now have the complete probabilistic reasoning toolkit: probability foundations for AI, Bayesian networks, Naive Bayes, Markov chains/HMMs, and decision theory. Module 5 shifts to multi-agent settings and reinforcement learning — where an agent doesn't just reason about a static world, but learns and acts within one that responds to it over time.

Concept Check

  1. Why can a rational agent (by the Maximum Expected Utility principle) still end up worse off on any single specific occasion?
  2. What are the three node types in a decision network, and what does each represent?
  3. What does a Value of Information calculation actually tell you, and how would you use it in practice?

Next Chapter

Module 5: Agents, Multi-Agent Systems & RL


Jr Codex — 1-on-1 Personalized Coaching | Back to Module Index