# Difference between revisions of "Markov decision process"

Author: Eric Berg (eb645), Fall 2020

# Introduction

A Markov Decision Process (MDP) is a stochastic sequential decision making method.${\displaystyle ^{1}}$ Sequential decision making is applicable any time there is a dynamic system that is controlled by a decision maker where decisions are made sequentially over time. MDPs can be used to determine what action the decision maker should make given the current state of the system and its environment. This decision making process takes into account information from the environment, actions performed by the agent, and rewards in order to decide the optimal next action. MDPs can be characterized as both finite or infinite and continuous or discrete depending on the set of actions and states available and the decision making frequency.${\displaystyle ^{1}}$ This article will focus on discreet MDPs with finite states and finite actions for the sake of simplified calculations and numerical examples. The name Markov refers to the Russian mathematician Andrey Markov, since the Markov Decision Process is based on the Markov Property. In the past, MDPs have been used to solve problems like inventory control, queuing optimization, and routing problems.${\displaystyle ^{2}}$ Today, MDPs are often used as a method for decision making in the reinforcement learning applications, serving as the framework guiding the machine to make decisions and "learn" how to behave in order to achieve its goal.

# Theory and Methodology

A Markov Decision process makes decisions using information about the system's current state, the actions being performed by the agent and the rewards earned based on states and actions.

The MDP is made up of multiple fundamental elements: the agent, states, a model, actions, rewards, and a policy.${\displaystyle ^{1}}$ The agent is the object or system being controlled that has to make decisions and perform actions. The agent lives in an environment that can be described using states, which contain information about the agent and the environment. The model determines the rules of the world in which the agent lives, in other words, how certain states and actions lead to other states. The agent can perform a fixed set of actions in any given state. The agent receives rewards based on its current state. A policy is a function that determines the agent's next action based on its current state.

Reinforcement Learning framework used in Markov Decision Processes

MDP Framework:

• ${\displaystyle S}$ : States (${\displaystyle s\epsilon S}$)
• ${\displaystyle A}$ : Actions (${\displaystyle a\epsilon A}$)
• ${\displaystyle P(S_{t+1}|s_{t},a_{t})}$ : Model determining transition probabilities
• ${\displaystyle R(s)}$: Reward

In order to understand how the Markov Decision Process works, first the Markov Property must be defined. The Markov Property states that the future is independent of the past given the present. ${\displaystyle ^{4}}$In other words, only the present is needed to determine the future, since the present contains all necessary information from the past. The Markov Property can be described in mathematical terms below:

${\textstyle P[S_{t+1}|S_{t}]=P[S_{t+1}|S_{1},S_{2},S_{3}...S_{t}]}$

The above notation conveys that the probability of the next state given the current state is equal to the probability of the next state given all previous states. The Markov Property is relevant to the Markov Decision Process because only the current state is used to determine the next action, the previous states and actions are not needed.

The Policy and Value Function

The policy, ${\displaystyle \Pi }$ , is a function that maps actions to states. The policy determines which is the optimal action given the current state to achieve the maximum total reward.

${\displaystyle \Pi :S\rightarrow A}$

Before the best policy can be determined, a the goal or return must be defined to quantify rewards at every state. There are various ways to define the return. Each variation of the return function tries to maximize rewards in some way, but differs in which accumulation of rewards should be maximized. The first method is to choose the action that maximizes the expected reward given the current state. This is the myopic method, which weighs each time-step decision equally. Next is the finite-horizon method, which tries to maximize the accumulated reward over a fixed number of time steps. But because many applications may have infinite horizons, meaning the agent will always have to make decisions and continuously try to maximize its reward, another method is commonly used, known as the infinite-horizon method. In the infinite-horizon method, the goal is to maximize the expected sum of rewards over all steps in the future. When performing an infinite sum of rewards that are all weighed equally, the results may not converge and the policy algorithm may get stuck in a loop. In order to avoid this, and to be able prioritize short-term or long term-rewards, a discount factor, ${\displaystyle \gamma }$, is added. If ${\displaystyle \gamma }$ is closer to 0, the policy will choose actions that prioritize more immediate rewards, and ${\displaystyle \gamma }$ is closer to 1, long-term rewards are prioritized.

Return/Goal Variations:

• Myopic: Maximize ${\displaystyle E[r_{t}|\Pi ,s_{t}]}$ , maximize expected reward for each state
• Finite-horizon: Maximize ${\displaystyle E[\textstyle \sum _{t=0}^{k}\displaystyle r_{t}|\Pi ,s_{t}]}$
• Discounted Infinite-horizon: Maximize ${\displaystyle E[\textstyle \sum _{t=0}^{\infty }\displaystyle \gamma ^{t}r_{t}|\Pi ,s_{t}]}$ ${\displaystyle \gamma \epsilon [0,1]}$

The value function, ${\displaystyle v(s)}$, characterizes the return at a given state. Most commonly, the discounted infinite horizon return method is used to determine the best policy. Below the value function is defined as the expected sum of discounted future rewards.

${\displaystyle v(s)=E[\sum _{t=0}^{\infty }\gamma ^{t}r_{t}|s_{t}]}$

The value function can be decomposed into two parts, the immediate reward of the current state, and the discounted value of the next state. This decomposition leads to the derivation of the Bellman Equation. Because the actions and rewards are dependent on the policy, the value function of an MDP is associated with a given policy.

${\displaystyle v(s)=E[r_{t+1}+\gamma v(s_{t+1})|s_{t}]}$

${\displaystyle v(s)=R(s)+\gamma \sum _{s'\epsilon S}P_{ss'}V(s')}$

${\displaystyle v^{\pi }(s)=R(s,\pi (s))+\gamma \sum _{s'\epsilon S}P(s'|s,\pi (s))V(s')}$

The value function can solved iteratively using iterative methods such as dynamic programming, Monte-Carlo evaluations, or temporal-difference learning.

The optimal policy is one that chooses the action with the largest value given the current state:

${\displaystyle \Pi (s)=max_{a}[R(s,a)+\gamma \sum _{s'\epsilon S}P_{ss'}^{a}V(s')]}$

${\displaystyle \Pi (s)=max_{\Pi }V_{\Pi }(s)}$

The policy is a function of the current state, meaning at each time step a new policy is calculated considering the present information. The optimal value function can be solved using methods such as value iteration, policy iteration, Q-learning, or linear programming.

The Algorithm

At each step, given state ${\displaystyle s_{t}}$

1. Update Value Function ${\displaystyle V(s)}$
2. Update Policy ${\displaystyle \Pi (s)}$ and perform action ${\displaystyle a}$

# Numerical Example

A Markov Decision Process describing a college student's hypothetical situation.

As an example, the Markov decision process can be applied to a college student, depicted to the right. In this case, the agent would be the student. The states would be the circles and squares in the diagram, and the arrows would be the actions. The actions between class states would be "study". In the state that the student is in Class 2, the allowable actions are to study or sleep. The model in this case would assign probabilities to each state given the previous state and action. These probabilities are written next to the arrows. Finally the rewards associated with each state are written in red.

Assume the first state is Class 1, ${\displaystyle \gamma }$ =1.

First, the value functions must be calculated for each state.

${\displaystyle V(s)=R(s)+\gamma \sum _{s'\epsilon S}P_{ss'}V(s')}$

${\displaystyle V(Class1)=-1.3}$

${\displaystyle V(Class2)=2.7}$

${\displaystyle V(Sleep)=0}$

${\displaystyle V(Pass)=10+(1)(1.0*0)=10}$

${\displaystyle V(Facebook)=-1+(1)(0.9*-1+0.1*-1.3)=-2.03}$

${\displaystyle V(Class3)=-2+1(0.6*10+0.4(0.2*-1.3+0.4*2.7+0.4*7.4))=7.4}$

Then, in state 1 (Class 1), the optimal policy is that the action chosen should result in the state that generates the highest value function.

${\displaystyle \Pi (s)=max_{a}[R(s,a)+\gamma \sum _{s'\epsilon S}P_{ss'}^{a}V(s')]}$

${\displaystyle \Pi (Class1)=max_{a}[-2+2.7,-1-2.03]=max_{a}[0.7,-3.03]=0.7}$

${\displaystyle a=}$ = study and go to Class 2

Therefore, the optimal policy in state Class 1 is to go to Class 2. Now, the optimal policy action can be decided in each state using the same process.

# Applications

Computer playing Pong arcade game by Atari using reinforcement learning

Markov Decision Processes have been applied in various fields including operations research, electrical engineering, computer science, manufacturing, economics, finance, and telecommunication.${\displaystyle ^{2}}$ For example, the sequential decision making process described by MDP can be used to solve routing problems such as the Traveling salesman problem. In this case, the agent is the salesman, the actions available are the routes available take from the current state, the rewards in this case consists of cost of taking each route, and the goal is to determine the optimal policy that minimizes the cost function over the duration of the trip. Another application example is maintenance and repair problems, in which a dynamic system such as a vehicle will deteriorate over time due to its actions and the environment, and the available decisions at every time epoch is to do nothing, repair, or replace a certain component of the system.${\displaystyle ^{2}}$ This problem can be formulated as an MDP to choose the actions that to minimize cost of maintenance over the life of the vehicle. MDPs have also been applied to optimize telecommunication protocols, stock trading, and queue control in manufacturing environments. ${\displaystyle ^{2}}$

Given the significant advancements in artificial intelligence and machine learning over the past decade, MDPs are being applied in fields such as robotics, automated systems, and autonomous vehicles, and other complex autonomous systems. MDPs have been used widely within reinforcement learning to teach robots or other computer-based systems how to do something they were previously were unable to do. For example, Markov decision processes have been used to teach a computer how to play computer games like Pong, Pacman, or AlphaGo.${\displaystyle ^{7,8}}$ DeepMind Technologies, owned by Google, used the MDP framework in conjunction with neural networks to play Atari games better than human experts. ${\displaystyle ^{7}}$ In this application, only the raw pixel input of the game screen was used as input, and a neural network was used to estimate the value function for each state, and choose the next action.${\displaystyle ^{7}}$ MDPs have been used in more advanced applications to teach a simulated human robot how to walk and run and a real legged-robot how to walk.${\displaystyle ^{9}}$

Google's DeepMind uses reinforcement learning to teach AI how to walk

# Conclusion

A Markov Decision Process is a stochastic, sequential decision-making method based on the Markov Property. MDPs can be used to make optimal decisions for a dynamic system given information about its current state and its environment. This process is fundamental in reinforcement learning applications and a core method for developing artificially intelligent systems. MDPs have been applied to a wide variety of industries and fields including robotics, operations research, manufacturing, economics, and finance.

# References

1. Puterman, M. L. (1990). Chapter 8 Markov decision processes. In Handbooks in Operations Research and Management Science (Vol. 2, pp. 331–434). Elsevier. https://doi.org/10.1016/S0927-0507(05)80172-0
2. Feinberg, E. A., & Shwartz, A. (2012). Handbook of Markov Decision Processes: Methods and Applications. Springer Science & Business Media.
3. Abbeel, P. (n.d.). Markov Decision Processes and Exact Solution Methods: 34.
4. Ashraf, M. (2018, April 11). Reinforcement Learning Demystified: Markov Decision Processes (Part 1). Medium. https://towardsdatascience.com/reinforcement-learning-demystified-markov-decision-processes-part-1-bf00dda41690
5. Bertsekas, D. P. (2011). Dynamic Programming and Optimal Control 3rd Edition, Volume II. Massachusetts Institue of Technology, 233.
6. Littman, M. L. (2001). Markov Decision Processes. In N. J. Smelser & P. B. Baltes (Eds.), International Encyclopedia of the Social & Behavioral Sciences (pp. 9240–9242). Pergamon. https://doi.org/10.1016/B0-08-043076-7/00614-8
7. Mnih, V., Kavukcuoglu, K., Silver, D., Graves, A., Antonoglou, I., Wierstra, D., & Riedmiller, M. (2013). Playing Atari with Deep Reinforcement Learning. ArXiv:1312.5602 [Cs]. http://arxiv.org/abs/1312.5602
8. Silver, D., Hubert, T., Schrittwieser, J., Antonoglou, I., Lai, M., Guez, A., Lanctot, M., Sifre, L., Kumaran, D., Graepel, T., Lillicrap, T., Simonyan, K., & Hassabis, D. (2018). A general reinforcement learning algorithm that masters chess, shogi, and Go through self-play. Science, 362(6419), 1140–1144. https://doi.org/10.1126/science.aar6404
9. Ha, S., Xu, P., Tan, Z., Levine, S., & Tan, J. (2020). Learning to Walk in the Real World with Minimal Human Effort. ArXiv:2002.08550 [Cs]. http://arxiv.org/abs/2002.08550
10. Platt, R. (n.d.). Markov Decision Processes. 66.
11. Roberts, J. (n.d.). Markov Decision Processes. 24.
12. Silver, D. (n.d.). Lecture 2: Markov Decision Processes. Markov Processes, 57.