ai theory
Reinforcement Learning Basics (4) — How Good Is the Current State?
Junyoung Park · 2024-04-05 · 9 min
Introduction
The third article described an MDP as the problem statement of reinforcement learning. By writing down its states, actions, transition probabilities, rewards, and discount factor, we could express the world in which an agent must make decisions.
But writing the problem does not immediately give us the answer. We still need numbers that tell us which of DESK, CAFE, and HOME is a good state, and whether STUDY or LEAVE is the better action at DESK.
Looking only at the immediate reward makes the problem seem simple: choose the state or action with the largest reward. As we saw in the first article, however, the objective of reinforcement learning is not to maximize one reward. It is to maximize the return, the sum of future rewards.
Moving one cell now may give but lead to an exit worth . Conversely, a path that gives now may end in several steps later. Whether the present is good or bad cannot be determined from the next reward alone.
Reinforcement learning therefore uses value functions. Before calculating values, this article carefully separates three terms.
- Reward: one number just received
- Return: the sum of future rewards that actually accumulated along one path
- Value: the expected average return after experiencing the same situation many times
Distinguishing Reward, Return, and Value with a Receipt
Reward is the one-step number the environment returns after an action at time .
Return is the discounted sum of every reward actually received from time onward.
If the following rewards are , , and , with , then
This is the outcome of one path actually taken. But even from the same state, the policy may choose another action or the environment may produce another next state. One episode may return , another , and another .
Value expresses the average return we expect across these possible outcomes.
One unusually expensive receipt does not mean that a store is always expensive on average. Value is similar. A high return in one episode is not enough to fix a state's value at a high number. We must also account for how often the different paths occur.
Expectation Is the Average of Futures Not Yet Observed
The state-value function is defined as
Rather than reading every symbol at once, let us work from the inside.
- : the condition that the current state is
- : the discounted return that will accumulate from now on
- : the average over possible outcomes when policy is followed
- : that average attached to state
In one sentence:
The expected return when we begin from state and continue to follow policy .
Expectation means more than adding observed reward numbers and dividing by the number of episodes. It averages both the uncertainty in which action the policy will choose and the uncertainty in which next state the environment will produce.
Suppose only two paths are possible from state .
- Return with probability
- Return with probability
The value is
A value of does not mean that an actual episode must return . The actual result is either or . The number is what we expect on average if the same situation is repeated many times.
The Subscript π Is Not Decoration
We often omit and write when the policy is already clear from context. But we must not forget that the value depends on the policy.
Suppose DESK has two actions.
- STUDY: expected long-term return
- LEAVE: expected long-term return
Under a policy that always chooses STUDY, the value of DESK is close to . Under a policy that chooses each action half the time, the value is about .
Even when the state stays the same, changing the policy changes the future paths and therefore the value.
A state value is not the score of a state by itself. It also scores the policy that will be followed from that state onward.
This is why value functions are useful for comparing policies. In the same MDP, comparing Policy A's with Policy B's tells us which policy creates a better future after that state.
Action Value: How Good Is It to Begin with This Action?
If the state value answers “how good is it to be in this state?”, the action value asks a more specific question.
In words:
The expected return after first taking action in state , then following policy thereafter.
averages over the actions the policy might select in the current state. In contrast, fixes the first action to and averages the future that follows.
Suppose the policy at DESK selects STUDY with probability and LEAVE with probability , and
The state value is the policy-weighted average of the action values.
In general,
The right side multiplies each action's by the probability that the policy selects that action, then adds the results.
How to Read Values in a Gridworld
Let every cell of a Gridworld be a state. The exit in the upper right gives , the pit in the lower right gives , and the agent moves up, down, left, or right.
A state immediately beside the exit can have a high value even if its current reward is zero, because the next action is likely to reach the exit. A state near the pit may have a low value even if it currently has no penalty.
Suppose the directional action values in one state, as in the right side of the figure, are
- up:
- right:
- left:
- down:
The value tells us how good the current cell is on average. The Q-values also tell us which direction leads to that good future.
If the environment model is known, we can use and the transition probabilities to look one step ahead for every action. When the model is unknown, however, it is far more convenient to learn directly from experience that records which action was taken. This is why SARSA and Q-Learning later update action values rather than state values.
Optimal Value Is the Best Future Among All Policies
Every value so far has been associated with a particular policy . The greatest value achievable among all possible policies is the optimal value.
If we knew exactly, we could choose the action with the largest Q-value in state .
returns the largest value itself. returns the action that produced that value.
For example, if the Q-values are for STUDY, for LEAVE, and for WORK OUT, then
while
This small notational difference separates a value from an action, and it will appear repeatedly later.
Value Is Not Reward
At first, rewards and values are easy to confuse because both are numbers written beside states. The following three checks help keep them separate.
A High Reward Can Still Lead to a Low Value
A state that gives now but then leads to at every later step has a low long-term value.
A State with No Current Reward Can Have a High Value
The state one cell before the exit may give zero now but have a high probability of receiving soon.
Value Is Not One Observed Outcome
The return is an outcome actually obtained in one episode. The value is the expectation over many possible returns.
A reward is data returned by the environment. A value is what the agent wants to know, or must estimate, to judge the future.
What to Remember
The central idea of this article is
Value is the expected return when we begin from a particular state or state-action pair and follow a policy.
More specifically:
- A reward is a one-step number.
- A return is the discounted sum of rewards that actually accumulated along one path.
- is the expected return when policy is followed from state .
- is the expected return after taking action first in state .
- The same state has a different value under a different policy.
- denotes the largest value, while denotes the action that produces it.
We now know the definition of value, but still need to calculate it. If the future extends for ten or a hundred steps, must we expand every possible return all the way to the end every time?
The next article introduces the Bellman equation, which folds a long future into “the next reward and the value after the next state.” We will also see how this one line leads to policy evaluation, policy iteration, and value iteration.