Concepts / Greedy Policy

Greedy Policy

The key pattern is evaluate, improve, and then evaluate the updated policy again when further improvement may be possible.

  • Programming

From Evaluation to Improvement

A policy tells an agent how to act. Policy iteration asks whether the current policy can be improved by using information about the value of states or state-action pairs. It repeats two activities: evaluate the current policy, then improve it by choosing actions that look better according to the value information.

Current policyEvaluate policyObtain value informationImprove policyChoose maximum-valuedactionsUpdated policyEvaluate again if neededevaluatevalue functionnew policyrepeat
What happens as policy iteration alternates between evaluating the current policy and improving it?
Key point

The key pattern is evaluate, improve, and then evaluate the updated policy again when further improvement may be possible.

Value Information and Greedy Choice

Definition

A greedy policy is a policy constructed from the value function of an original policy. At each decision, it selects an action that has the maximum value according to that original policy's value function.

The value function supplies an estimate of expected return or utility for states or state-action pairs. Policy improvement uses this information for a one-step lookahead: from the current decision, compare the available actions using the original policy's value information, then choose an action with the highest value.

Original policyValue function vπAction ALookahead valueGreedy choiceMaximum-valued actionAction BLookahead valueAction CLookahead valuecomparecomparecomparehighest value winshighest value winshighest value wins
How does the original policy's value function flow through possible actions to determine the greedy choice?

The word greedy describes the decision rule, not a claim that the original policy was poor. The new policy simply uses the available value information to select the best-looking action at each decision. Its comparison is based on the value function of the original policy.

Constructing the Improved Policy

Worked example

Selecting an Action from Lookahead Values

At one decision, three actions have lookahead values of 4, 7, and 5 according to the original policy's value function. Which action does the greedy policy select?

  1. 1
    Compare

    Compare the values associated with all available actions: 4, 7, and 5.

  2. 2
    Find the maximum

    The largest value is 7.

  3. 3
    Choose greedily

    The greedy policy selects the action whose lookahead value is 7.

Result

The action with value 7 becomes the greedy choice at this decision.

Action valuesGreedy choice
4, 7, 5The action valued at 7
6, 6, 3Either action valued at 6

A greedy policy selects a maximum-valued action. If multiple actions share the maximum value, the tie may be broken arbitrarily.

Why Improvement Is Guaranteed

The policy improvement theorem provides the central guarantee: a greedy policy constructed from the original policy's value function is as good as or better than the original policy. The theorem applies because the new policy chooses actions according to the maximum available value information in the one-step comparison.

Original policyUses its existing choicesGreedy policyMaximum-valued choicesValue function vπBasis for comparisonAs good or betterPolicy improvement theoremimprove usingone-step comparisonguarantees
What changes when an original policy is replaced by a greedy policy, and what does the policy improvement theorem guarantee?
Key point

The theorem is a general guarantee. It does not merely describe a lucky result in one example: policy improvement produces a policy that is no worse than the original policy.

The One-Iteration Outcome

In the Figure 4.1 trace, policy iteration begins with an equiprobable random policy. That policy is evaluated, and its value function is then used to form a greedy policy. In this particular problem, the resulting greedy policy is already optimal because it proceeds to terminal states in the minimum number of steps.

Before

Initial policy: equiprobable random policy Evaluation: obtain its value function

The policy has been evaluated but has not yet been improved.

After

Improved policy: greedy policy Result: reaches terminal states in the minimum number of steps

The greedy policy is already optimal for this particular problem.

This example reaches its final policy after one improvement iteration because no better policy is needed after the greedy choice is formed. That stronger conclusion belongs to the particular example. The general policy improvement theorem guarantees that the greedy policy is as good as or better than the original; it does not by itself say that every greedy policy is immediately optimal.

Common Reasoning Errors

  • Common mistake

    Treating a greedy policy as an arbitrary new policy

    What it looks like

    Choosing an action without comparing its value with the other available actions.

    Why it fails

    A greedy policy is specifically constructed by selecting maximum-valued actions according to the original policy's value function.

    Do this instead

    Use the original policy's value function as the basis for a one-step comparison.

  • Common mistake

    Assuming the theorem guarantees immediate optimality in every problem

    What it looks like

    Concluding that every greedy policy must be optimal after one improvement.

    Why it fails

    The theorem guarantees that the new policy is as good as or better than the original. Immediate optimality is a stronger result shown by the particular Figure 4.1 example.

    Do this instead

    Separate the general theorem guarantee from the stronger outcome of a specific example.

  • Common mistake

    Rejecting a greedy choice when values are tied

    What it looks like

    Seeing two actions with the same maximum value and concluding that no greedy policy can be formed.

    Why it fails

    Ties between maximum-valued actions may be broken arbitrarily.

    Do this instead

    Select any one of the actions tied for the maximum value.

  • Common mistake

    Confusing evaluation with improvement

    What it looks like

    Calling the value function itself the improved policy.

    Why it fails

    Evaluation provides value information; improvement uses that information to construct a new policy.

    Do this instead

    Keep the sequence clear: evaluate the current policy, then form a greedy policy from its value function.

Practice: Choose Greedily

EASY

A decision has four available actions with values 2, 9, 9, and 6 according to the original policy's value function. Which action or actions can the greedy policy choose, and why?

Hints
  • Find the maximum value.
  • Check whether more than one action has that value.
  • Use the rule for breaking ties.

What do you think happens?

The action values are 2, 9, 9, and 6. Which action or actions can the greedy policy choose?

  • Only the action valued at 2

  • Only the action valued at 6

  • Either action valued at 9

  • Any action, because all choices are greedy

Reveal answer
Answer:

Either action valued at 9

The greedy policy selects a maximum-valued action. The maximum value is 9, and ties between maximum-valued actions may be broken arbitrarily.

Key Takeaways

  1. 1
    Policy iteration alternates between evaluating a policy and improving it.
  2. 2
    The value function of the original policy supplies the information for a one-step action comparison.
  3. 3
    A greedy policy selects an action with the maximum value at each decision.
  4. 4
    The policy improvement theorem guarantees that the greedy policy is as good as or better than the original policy.
  5. 5
    In the Figure 4.1 example, the greedy policy is already optimal after one iteration because it reaches terminal states in the minimum number of steps.

At a glance

  • Policy iteration repeatedly evaluates the current policy and improves it.
  • A greedy policy is formed by choosing maximum-valued actions according to the original policy's value function.
  • One-step lookahead compares the available actions using that value information.
  • The policy improvement theorem guarantees a result that is as good as or better than the original policy.
  • Ties among maximum-valued actions may be broken arbitrarily.

Related concepts

More concepts starting with G