Control with action values
Monte-Carlo Prediction estimates state values without a model. Greedy policy improvement with respect to , needs the dynamics , which a model-free agent does not have. The way out is to estimate the action values instead and improve the policy greedily with respect to them: Alternating the two steps is generalized policy iteration with action values:
Maintaining exploration
A deterministic policy takes only one action in each state. The agent then sees returns for that action only, and the estimates of the other actions never improve. Choosing among actions needs estimates for all of them, so the agent must keep trying actions it does not currently favor (Sutton & Barto, 2018). One way to do this is exploring starts: every episode starts in a random state-action pair, and every pair has a nonzero probability of being the start. Exploring starts are rarely possible when the agent learns from real interaction, for example on a robot, because the agent cannot choose the state it starts in. The other way is to keep the policy itself stochastic. A policy is -soft if every action has probability at least in every state. The -greedy policy is the -soft policy closest to greedy. With probability it takes the greedy action , and with probability it picks an action uniformly at random from all actions. The greedy action therefore has probability , and every other action has probability .ε-greedy policy improvement
Policy improvement still works within -soft policies. Let be -soft and let be -greedy with respect to . Then, for every state , The inequality holds because the weights are nonnegative and sum to 1, and a weighted average is never larger than the maximum. By the policy improvement theorem, in every state. Repeating evaluation and -greedy improvement converges to the best -soft policy, which is not the optimal policy: it still takes a random action with probability .GLIE
To reach the optimal policy, exploration has to fade without stopping. A schedule is greedy in the limit with infinite exploration (GLIE) if- every state-action pair is visited infinitely often, and
- the policy converges to the greedy policy with respect to .
On-policy MC control
Putting the pieces together gives on-policy first-visit MC control for -soft policies:Off-policy MC with importance sampling
An on-policy method compromises: it learns the values of a policy that keeps exploring. An off-policy method separates the two jobs. The behavior policy explores and generates the episodes, and the target policy , often the greedy policy, is the one being evaluated and improved. This requires coverage: every action that can take must have a nonzero probability under , so implies . Returns generated by have the wrong expectation for . Importance sampling corrects for this by weighting each return with the relative probability of its trajectory under the two policies. Given , the probability of the rest of the trajectory under a policy is a product of policy and transition probabilities, and the transition probabilities cancel in the ratio: The ratio depends only on the two policies, not on the unknown dynamics, and it corrects the expectation: . Let be the set of time steps at which is visited for the first time in an episode, across all the episodes collected so far. Two estimators follow: where is the end of the episode that contains . Ordinary importance sampling is unbiased, but its variance can be unbounded, because a single ratio can be very large. Weighted importance sampling is biased, and the bias goes to zero as the number of returns grows. If includes every visit instead of the first, both estimators are biased for a finite number of episodes, and the bias again vanishes as the number of episodes grows (Sutton & Barto, 2018). Its variance is much lower, so it is the usual choice in practice (Sutton & Barto, 2018). Weighted importance sampling also has an incremental form. With the weight of the new return and the running sum of weights, The ratio is a product over the whole rest of the episode, and that causes the main difficulty. If the target policy is greedy, for every exploratory action, so the ratio, and with it the weight of the return, is zero as soon as explores. Only the tail of each episode after the last exploratory action carries information, and learning is slow when episodes are long. SARSA replaces the MC return with a one-step TD target, so the policy improves after every step instead of after every episode. Q-learning is an off-policy method whose one-step target needs no importance-sampling ratio at all. Key references: (Sutton & Barto, 2018)References
- Sutton, R., Barto, A. (2018). Reinforcement Learning: An Introduction. Link
Found an error on this page? Report an issue.

