*David Silver’s YouTube series on Reinforcement Learning, Episode 2*.

The full lesson is the following:

A **Markov Decision Process** descrbes an environment for reinforcement learning. The environment is fully observable. In MDPs, the current state completely characterises the process.

# Markov Process (MP)

The **Markov Property** states the following:

A state is

Markovif and only if

The transition between a state and the next state is characterized by a **transition probability**. It is defined by :

We can characterize a **state transition matrix** , describing all transition probabilities from all states to all successor states , where each row of the matrix sums to 1.

A **Markov Process** is a memoryless random process. It is a sequence of randdom states with the Markov Property.

A Markov Process, also known as Markov Chain, is a tuple , where :

- is a finite set of states
- is a state transition probability matrix such that

We can represent a Markov Decision Process schematically the following way :

**Samples** describe chains that take different states. For example, it could be :

- 1, 1, 2, 1, 2, 3, 4, 3, Exit
- 1, 2, 3, Exit
- …

The transition matrix corresponding to this problem is :

# Markov Reward Process (MRP)

## Markov Reward

A Markov Reward is a Markov Chain a value function. A **Markov Reward Process** is a tuple where :

- is a reward function
- is a discount factor between 0 and 1
- all other components are the same as before

We can therefore attach a reward to each state in the following graph :

Then, the **Return** is the total discounte reward from time-step :

Just like in Finance, we compute the present value of future rewards. This represents the fact that we prefer to get reward now instead of getting it in the future.

- if is close to 0, we have a “myopic” evaluation where almost only the present matters
- if is close to 1, we have a “far-sighted” evaluation

A simple return for the sequence 1-1-2-3-Exit and with would be :

But why do we use a discount factor ?

- there is uncertainty in the future, and our model is not perfect
- it avoids infinite returns in cyclical Markov Processes
- animals and humans have a preference for immediate reward

## Bellman Equation

The **value function** gives the long-term value of a state . It reflects the expected return when we are in a given state :

The value function can be decomposed in two parts :

- the immediate reward
- the discounted value of the successor rate

This is the **Bellman Equation** for MRP :

If we consider that is equal to 1, we can compute the value function at state 2 in our previous example :

We can summarize the Bellman equation is a matrix form :

We can solve this equation as a simple linear equation :

However, solving this equation this way has a computational complexity of for states since it contains a matrix inversion step. There are several ways to compute it faster, and we’ll develop those solutions later on.

# Markov Decision Process (MDP)

So far, we have not seen the action component. Markov Decision Process (MDP) is a Markov Reward Process with decisions. As defined at the beginning of the article, it is an environment in which all states are Markov.

A **Markov Decision Process** is a tuple of the form : where :

- is a finite set of actions
- the state probability matrix is now modified :
- the reward function is now modified :
- all other components are the same as before

We now have more control on the actions we can take :

There might stil be some states in which we cannot take action and are subject to the transition probabilities, but in other states, we have an action choice to make. This is the reality of an agent, and we needd to maximize the reward and find the best path to reach the final state.

But what does it mean to actually **make a decision** ?

## Policies

The agent chooses a policy. A policy is a distribution over actions given states.

A policy describes the behavior of an agent. Policies are *time stationary*, they donnot depend on time.

Given an MDP and a policy :

- the state sequence is a Markov Process .
- the state and reward sequence is a Markov Reward Process .

We compte the Markov Reward Process values by averaging over the dynamics that result of each choice. In other words :

## Value Function

The **state-value function** of an MDP is now conditional to the chosen policy . It is the expected return starting from state and following policy :

The **action-value function** is the expected return starting from a state , taking action and following policy :

The state-value function can again be decomposed into immediate reward plus discounted value of successor rate. This is the **Bellman Expectation Equation** :

The action-value function can be decomposed similarly :

Let’s illustrate those concepts ! Suppose we start in the state . We can take actions, either the one on the left or on the right. To each action, we attach a q-value, which gives the value of taking this action. The value of being in state is therefore an average of both actions :

This is the Bellman Expectation Equation for :

What if we now consider the inverse ? We start from an action, and have two resulting states.

The state shows how good it is to be in a state. The action tells us how good it is to take an action. This is the Bellman Expectation Equation for :

We can now group both interpretations into a single graph :

This shows us a recursion that expresses in terms of itself. This is how we solve the Markov Decision Process. At the root of the tree, we know how gooddit is to be in a state. We then consider all the actions we might do given the policy. For each action, there are possible outcome states.

We can now express the Bellman Equation a for the state-value as :

And similarly for the action-value :

We can simply illustrate how this Bellman Expectation works. We suppose here that there is no discount, and that our policy is to pick each action with a probability of 50%.

We can represent the Bellman Expectation Equation in a matrix form :

The solution is given by :

Again, the inversion of the matrix is of complexity , and we there need more efficient ways to solve this.

## Optimal Value Function

The

optimal state-valuefunction is the maximum value function over all policies :

It reflects the maximum reward we can get by following the best policy.

The

optimal action-valuefunction is the maximum action-value function over all policies.

It shows given that we commit to a particular action in state , what is the maximum reward we can get.

An optimal value function specifies the best possible performance in the MDP. An MDP is said to be **solved** if we know the optimal value function.

## Optimal Policy

The **optimal policy** defines the best possible way to behave in an MDP. We first define a partial ordering over policies :

if

For any MDP, there exists an optimal policy that is better than or equal to all other policies.

- All optimal policies achieve the optimal value function :
- All optimal policies achieve the optimal action-value function :

So, how do we find this policy ? We must maximise over :

if , and otherwise.

This tells us that once we have found , we are done. This now brings the problem to : How do we find ?

Once we are in the final state, it’s quite easy. We know which action will lead to the maximal reward. If we move back to one state before, we know that the state we were in leads to the maximum reward. We therefore pick this action since it maximizes the reward. If we move another step before, we …

You get the idea. This simply means that we can move backward, and take at each state the action that maximizes the reward :

However, when picking an action, we must average over what the environment might do to us once we have picke this action.

The Bellman Optimality Equation for can be obtained by combining both :

And finally, we can switch the order andd start with the action to derive the Bellman Equation for . We start by taking the action , and there is an uncertainty on the state the environment is going to lead us in. Then, wherever we are, we get to make a decision to maximise the reward.

## Solving the Bellman Equation

The Bellman Equation is a non-linear problem. There is no closed form solution in general. We need to use iterative solutions, among which :

- value iteration
- policy iteration
- Q-learning
- Sarsa

Value and policy iteration are Dynamic Programming algorithms, and we’ll cover them in the next article.

Like it? Buy me a coffee

## Leave a comment