SeriesDeep Learning18 / 20

Reinforcement Learning

Module 17 of CS 7643 - Deep Learning @ Georgia Tech.

Intro to RL#

Machine Learning refers to the development of algorithms which learn from experience, rather than direct programming, to accomplish some task. Machine learning has three major subdivisions:

Reinforcement Learning (RL) involves sequential decision-making in an environment with evaluative feedback. As part of any RL system, an agent interacts with its environment to maximize some reward. The primary objective of the system is to learn the optimal policy mapping states of the environment to action choices.

RL-intro

Markov Decision Processes#

Definition + Components#

Markov Decision Processes (MDPs) provide a theoretical framework to represent RL problems by defining the following core components:

The state transition function T\mathbb{T} defines the distribution over possible state transitions. For example, given a starting state ss and selected action aa, what is the probability of reaching the end state ss'? This is particularly important in the context of a stochastic environment.

The reward function assigns quantitative score to a tuple of (s,a,s)(s, a, s'). As part of an MDP problem, we are ultimately interested in maximizing this score over a long-term period.

Given their definitions, these components are clearly crucial to any MDP framework! But guess what - in practice, we typically don’t know the true values for T\mathbb{T} nor R\mathcal{R}. Instead, we simulate agent interactions with the environment to sample from the distributions, in order to estimate their values. However, for the purposes of this lesson, assume we have known T\mathbb{T} and R\mathcal{R} so we can focus on solving MDPs.

Solving MDPs#

In order to solve an MDP, we must find the optimal policy mapping states to actions.

A good policy maximizes the discounted sum of future rewards:

π=argmaxπE[Gtπ]\pi^{*} = \arg \max_{\pi} \mathbb{E} \left[ G_t | \pi \right]

Gt=Rt+1+γRt+2+γ2Rt+3+=k=0γkRt+k+1G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t + 3} + \ldots = \sum_{k=0}^\infty\gamma^kR_{t+k+1}

Note that we can frame both the value function and optimal policy in terms of the quality function. More specifically…

V(s)=maxaQ(s,a)V^{*}(s) = \max_a Q^{*}(s, a)

π(s)=argmaxaQ(s,a)\pi^{*}(s) = \arg \max_a Q^{*}(s, a)

The Bellman Optimality Equation is a recursive decomposition of our reward maximization problem into the immediate reward R(s,a)R(s, a) and future expected reward.

V(s)=maxasPr(ss,a)[R(s,a)+γV(s)]V^{*}(s) = \max_a \sum_{s'}^{ } \Pr(s' | s, a) [R(s, a) + \gamma V^{*}(s')]

Given this equation, we can now estimate the state value function and state-action value function as follows:

For each of these approaches, we first estimate the value / quality function, then calculate the optimal policy via one walkthrough of greedy policy extraction. An alternative approach is to estimate value using a given policy, then update the policy based on value estimates - this is known as Policy Iteration.

πi+1(s)argmaxasPr(ss,a)[R(s,a)+γVπi(s)]\pi_{i+1}(s) \leftarrow \arg \max_a \sum_{s'} \Pr(s' | s, a) [R(s, a) + \gamma V^{\pi_i}(s')]

Value and Q-Value iteration are value-based approaches to solving MDPs. On the other hand, Policy Iteration is a policy-based method.

Example MDP: Grid World#

The most simple example of an RL system is Grid World which describes the following problem:

grid-world

Deep Q-Learning#

Alright, so that’s all of reinforcement learning! Right? Not even close. One key issue with our current approach is the time complexity. Direct calculation of the state value function / state-action value function / policy has an unfavorable time complexity:

O(S2A)\mathcal{O}(|\mathcal{S}|^2|\mathcal{A}|)

In a simple example such as Grid World, this isn’t too bad. However, for even moderately complicated environments involving larger state and action spaces, these approaches become too computationally expensive. So what’s the solution?

Deep Q-Learning is an approach to solving MDPs which learns a parameterized Q-function to estimate the state-action value function. Given a state : action pair as input, the Q-function outputs a score. In the simplest case, we can use a linear model to represent our Q-function:

Q(s,a;w,b)=waTs+baQ(s, a; w, b) = w_a^{T}s + b_a

In practice, we typically choose to fit a Deep Q-Network (DQN) to represent our Q-function. DQNs are simply neural networks which approximate the Q-function Q(s,a)Q(s, a).

Training a DQN#

So how does the learning process work? Recall that the Bellman Equation defines the Q-function as follows:

Q(s,a)=E[R(s,a)+γmaxaQ(s,a)]Q^{*}(s, a) = \mathbb{E} \left[R(s, a) + \gamma \max_{a'} Q^{*}(s', a') \right]

Our objective function - Temporal Difference (TD) Error - minimizes the difference between our predicted and TD target Q values. Note the TD target is calculated by taking the actual reward received rr and adding it to the discounted state-action value for the next state ss'.

MSE Loss:  (Q(s,a)(r+maxaγQ(s,a)))2\text{MSE Loss:} ~~ (Q(s, a) - (r + \max_{a'} \gamma Q(s', a')))^2

There is one key issue with this representation - during parameter updates to Q(s,a)Q(s, a), the network is also changing its estimate of the TD target, thus “moving the goalposts” for the loss calculation. To solve this problem, DQNs introduce the Target Network as a separate, frozen copy of the network which is used to calculate the TD target. We may then update this frozen network at fixed intervals.

Gathering Data#

Given our optimization approach, how should we go about collecting data via agent experience with the environment?

  1. We might start with a random data gathering policy πgather\pi_{\text{gather}} to collect instances of (s,a,s,r)(s, a, s', r).
  2. Use the data to train our DQN, then use the DQN to update our policy πtrained\pi_{\text{trained}}.
  3. Repeat this process until policy convergence.

While this approach is reasonable, it is problematic for one key reason - we are only exploring states which yield high reward relative to the current data-gathering policy. States with low reward as estimated by the current Q-function (but perhaps with high long-term reward) will be passed over. We must effectively balance Exploration vs. Exploitation by ensuring our algorithm strays from its path to explore alternative (lower-reward) paths:

Exploration vs. Exploitation efforts typically result in an Epsilon-Greedy approach to action selection. In practice, we use annealing to decay epsilon over time, which implies less weight is given to random action selection with increased experience.

at={argmaxaQ(s,a)with probability 1ϵrandom actionwith probability ϵa_t = \begin{cases} \arg \max_a Q(s, a) & \text{with probability} ~ 1 - \epsilon \\ \text{random action} & \text{with probability} ~ \epsilon \end{cases}

Policy-Based Methods#

Whereas value-based methods estimate state value to optimize the policy, policy-based methods focus on directly optimizing the policy itself.

policy-based

Similar to the case where we have a parameterized value function (as in DQN), we can also parameterize our policy.

πθ(as):SA\pi_{\theta}(a|s) : \mathcal{S} \rightarrow \mathcal{A}

Our objective function the expectation of discounted rewards over time.

J(θ)=E[t=1TR(st,at)]J(\theta) = \mathbb{E} \left[ \sum_{t=1}^T R(s_t, a_t) \right]

Policy Gradients#

Given our objective, can we define the policy gradient to calculate during any update step of gradient descent? We define a similar setup to the case of supervised learning, but define our label as a sampled action.

policy-gradient

(all images obtained from Georgia Tech DL course materials)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts