SandHouse
Pages and contents

Reinforcement Learning

Markov Decision Process

Rewards

If you have a sequence of rewards received after time step t, Rt+1,Rt+2,…,RT, then the typical reinforcement learning maxim problem is to maximize total reward

G=Rt+1+Rt+2+...+RT

This is applicable to episodic tasks such as a game, where the final state is different from other states 𝒮+≠𝒮. In situations without a terminal state, we seek to maximize discounted return

G=∑k=0∞γkRt+k+1

Markov Property

A state signal that succeeds in retaining all relevant information is said to be Markov, or to have the Markov property (we define this formally below). For example, a checkers position—the current configuration of all the pieces on the board—would serve as a Markov state because it summarizes everything important about the complete sequence of positions that led to it.

Consider the general causal case in which an event may depend on everything that happened previously In this case the dynamics can be defined only by specifying the complete probability distribution.

If the state signal has the Markov property, on the other hand, then the environment’s response at t+1 depends only on the state and action representations at t, in which case the environment’s dynamics can be defined by specifying only

p(s′,r|s,a)=Pr{Rt+1=r,St+1=s′ | St,At}

In this case a state signal has the Markov property, and is a Markov state.

MDP

A reinforcement learning task that satisfies the Markov property is called a Markov decision process, or MDP. If the state and action spaces are finite, then it is called a finite Markov decision process (finite MDP).

Given any state and action s and a, the probability of each possible pair of next state and reward, s’,ris denoted

p(s′,r|s,a)=Pr{St+1=s′,Rt+1=r | St=s,At=a}

Value Functions

Value functions allow us to estimate “how good” it is for an agent to be in a given state, which is defined in terms of future expected rewards.

A policy π:𝒮×𝒜→ℝm is a map from each state s∈𝒮and action a∈𝒜to the probability of taking action awhen in state s: π(a|s).

The value of a state under policy π, denoted vπ(s)is the expected return from starting at sand following π thereafter. We can write the value function for a Markov Decision Process as follows

vπ(s)=Eπ[Gt | St=s]=∑aπ(a|s)∑s′,rp(s′,r | s,a)[r+γvπ(s′)]

Similarly, we denote the action-value function of taking an action a at state s under policy π.

qπ(s,a)=Eπ[Gt | St=s,At=a]

Temporal-Difference Learning

Temporal-difference (TD) learning estimates the value of a state using both the observed reward and the current estimate of the next state’s value. This is a method known as bootstrapping: updating estimates of the values of states based on estimates of the values of successor states, or more broadly, updating estimates based on the value of other estimates.

For a value function V(s), the one-step TD error is

δt=rt+1+γV(st+1)−V(st)

where rt+1 is the observed reward, γ is the discount factor, andV(st+1)is the bootstrapped estimate of future return.

The value estimate is updated as

V(st)←V(st)+αδt

where α is the learning rate. Unlike Monte Carlo methods, TD methods can update after every transition without waiting for an episode to finish.

Common extensions include TD(λ) which combines information from multiple future time horizons, and action-value methods such as SARSA and Q-learning.

Eligibility Trace

An eligibility trace is a temporary record of the occurrence of an event, such as the visiting of a state or the taking of an action. The trace marks the memory parameters associated with the event as eligible for undergoing learning changes. When a TD error occurs, only the eligible states or actions are assigned credit or blame for the error.

Actor-Critic Methods

Actor–critic methods are TD methods that have a separate memory structure to explicitly represent the policy independent of the value function. The policy structure is known as the actor, because it is used to select actions, and the estimated value function is known as the critic, because it criticizes the actions made by the actor.

The one-step actor-critic method updates the actor by

Ht+1(s,a)={Ht(s,a)+αδtif  a=At  and  s=St,Ht(s,a)otherwise

Where Ht(s,a)is the preference for actionaat timetin states. We can include eligibility traces as follows

Ht+1(s,a)=Ht(s,a)+αδtEt(s,a)

Advantage Functions

Sometimes in RL, we don’t need to describe how good an action is in an absolute sense, but only how much better it is than others on average. That is to say, we want to know the relative advantage of that action. We make this concept precise with the advantage function.

The advantage function Aπ(s,a) corresponding to a policy π describes how much better it is to take a specific action a in state s over randomly selecting an action according to π(⋅ | s) assuming you act according to π forever after. Mathematically, the advantage function is defined by

Aπ(s,a)=Qπ(s,a)−Vπ(s)

Generalized Advantage Estimation

GAE introduces a parameter γ that allows us to reduce variance by downweighting rewards corresponding to delayed effects, at the cost of introducing bias. This parameter corresponds to the discount factor used in discounted formulations of MDPs, but we treat it as a variance reduction parameter in an undiscounted problem.

The true advantage is unknown, so GAE estimates it using TD errors. First compute rt+γV(st+1)−V(st).
This is the difference between what actually happened and what the critic expected. GAE combines TD errors over future time steps

∑l=0T−t−1(γλ)lδt+l=δt+γλδt+1+(γλ)2δt+2+⋯

λ controls how far into the future the estimate looks, with

• λ=0: mostly one-step TD; lower variance, more bias.
• λ→1: longer-horizon estimate; less bias, more variance.

Thus GAE can be thought of as a smoothed estimate of how good an action was. A critic can use the GAE estimate to construct a return target V(st)+A^tand minimize (V(st)−R^t)2.

PPO

A normal policy-gradient objective is approximately

𝔼t[rt(θ)A^t]

where

πθ(at∣st)πθold(at∣st)

measures how much the new policy changed the probability of the chosen action. If A^t>0 we want the action to become more likely, and if A^t<0 we want it to become less likely. The problem is that unrestricted policy-gradient updates can change the policy too much. PPO limits this with clipping.

𝔼t[min⁡(rtA^t,clip⁡(rt,1−ϵ,1+ϵ)A^t)]

The clipping prevents the new policy from moving too far from the policy that generated the training data. Therefore PPO can be thought of as a policy gradient with constrained policy updates.

PPO + GAE

The overall process is

(s_t,a_t,r_t,s_{t+1}) \\ \downarrow \\ r_t+\gamma V(s_{t+1})-V(s_t) \\ \downarrow \\ \text{GAE} \rightarrow \hat{A}_t \\ \downarrow \\ \text{PPO} \rightarrow \text{update} \ \pi_\theta

In short:

• Critic: predicts expected future reward.
• GAE: estimates whether an action was better or worse than expected.
• PPO: updates the actor using that advantage while preventing excessively large policy changes.