# Markov decision process: Difference between revisions

Author: Eric Berg (eb645) (SysEn 5800 Fall 2020)

# Introduction

A Markov Decision Process (MDP) is a stochastic sequential decision making method.$^{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.$^{1}$ This article will focus on discrete 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 MDP is based on the Markov Property. In the past, MDPs have been used to solve problems like inventory control, queuing optimization, and routing problems.$^{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 MDP 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.$^{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.

MDP Framework:

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

In order to understand how the MDP works, first the Markov Property must be defined. The Markov Property states that the future is independent of the past given the present.$^{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 MDP 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, $\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.

$\Pi :S\rightarrow A$ Before the best policy can be determined, a 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.$^{2}$ Next is the finite-horizon method, which tries to maximize the accumulated reward over a fixed number of time steps.$^{2}$ 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. $^{2}$ 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, $\gamma$ , is added. $^{3}$ If $\gamma$ is closer to 0, the policy will choose actions that prioritize more immediate rewards, if $\gamma$ is closer to 1, long-term rewards are prioritized.

Return/Goal Variations:

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

The value function, $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.

$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,, as shown in equation (2). Because the actions and rewards are dependent on the policy, the value function of an MDP is associated with a given policy.

$V(s)=E[r_{t+1}+\gamma V(s_{t+1})|s_{t}]$ , $s_{t+1}=s'$ $V(s)=R(s)+\gamma \sum _{s'\epsilon S}P_{ss'}V(s')$ $V^{\Pi }(s)=R(s,\Pi (s))+\gamma \sum _{s'\epsilon S}P(s'|s,\Pi (s))V(s')$ (1)

$V^{*}(s)=max_{a}[R(s,a)+\gamma \sum _{s'\epsilon S}P(s'|s,a)V^{*}(s')]$ (2)

The optimal value function can be solved iteratively using iterative methods such as dynamic programming, Monte-Carlo evaluations, or temporal-difference learning.$^{5}$ The optimal policy is one that chooses the action with the largest optimal value given the current state:

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

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 policy function can be solved using methods such as value iteration, policy iteration, Q-learning, or linear programming. $^{5,6}$ Algorithms

The first method for solving the optimality equation (2) is using value iteration, also known as successive approximation, backwards induction, or dynamic programming. $^{1,6}$ Value Iteration Algorithm:

1. Initialization: Set $V_{0}^{*}(s)=0$ for all $s\epsilon S$ , choose $\varepsilon >0$ , n=1
2. Value Update: For each $s\epsilon S$ , compute: $V_{n+1}^{*}(s)=max_{a}[R(s,a)+\gamma \sum _{s'\epsilon S}P(s'|s,a)V_{n}^{*}(s')]$ 3. If $|V_{n+1}-V_{n}|<\varepsilon$ , the algorithm has converged and the optimal value function, $V^{*}$ , has been determined, otherwise return to step 2 and increment n by 1.

The value function approximation becomes more accurate at each iteration because more future states are considered. The value iteration algorithm can be slow to converge in certain situations, so an alternative algorithm can be used which converges more quickly.

Policy Iteration Algorithm:

1. Initialization: Set an arbitrary policy $\Pi (s)$ and $V(s)$ for all $s\epsilon S$ , choose $\varepsilon >0$ , n=1
2. Policy Evaluation: For each $s\epsilon S$ , compute: $V_{n+1}^{\Pi }(s)=R(s,\Pi (s))+\gamma \sum _{s'\epsilon S}P(s'|s,\Pi (s))V_{n}^{\Pi }(s')$ 3. If $|V_{n+1}-V_{n}|<\varepsilon$ , the optimal value function, $V^{*}$ has been determined, continue to next step, otherwise return to step 2 and increment n by 1.
4. Policy Update: For each $s\epsilon S$ , compute: $\Pi _{n+1}(s)=argmax_{a}[R(s,\Pi _{n}(s))+\gamma \sum _{s'\epsilon S}P(s'|s,\Pi _{n}(s))V_{n}^{\Pi }(s')]$ 5. If $\Pi _{n+1}=\Pi _{n}$ ,the algorithm has converged and the optimal policy, $\Pi ^{*}$ has been determined, otherwise return to step 2 and increment n by 1.

With each iteration the optimal policy is improved using the previous policy and value function until the algorithm converges and the optimal policy is found.

# Numerical Example

As an example, the MDP 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 action between work and school is leave work and go to school. In the state that the student is at school, the allowable actions are to go to the bar, enjoy their hobby, or sleep. The probabilities assigned to each state given the previous state and action in this example is 1. The rewards associated with each state are written in red.

Assume $P(s'|s)=1.0$ , $\gamma$ =1.

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

$V^{*}(s)=max_{a}[R(s,a)+\gamma \sum _{s'\epsilon S}P(s'|s,a)V^{*}(s')]$ $V^{*}(Hobby)=max_{a}[3+(1)(1.0*0)]=3$ $V^{*}(Bar)=max_{a}[2+1(1.0*0)]=2$ $V^{*}(Sleep)=max_{a}[0+1(1.0*0)]=0$ $V^{*}(School)=max_{a}[-2+1(1.0*2),-2+1(1.0*0),-2+1(1.0*3)]=1$ $V^{*}(YouTube)=max_{a}[-1+1(1.0*-1),-1+1(1.0*1)]=0$ $V^{*}(Work)=max_{a}[1+1(1.0*0),1+1(1.0*1)]=2$ Then, the optimal policy at each state will choose the action that generates the highest value function.

$\Pi ^{*}(s)=argmax_{a}[R(s,a)+\gamma \sum _{s'\epsilon S}P_{ss'}^{a}V(s')]$ $\Pi ^{*}(YouTube)=argmax_{a}[0,2]\rightarrow a=$ Work

$\Pi ^{*}(Work)=argmax_{a}[0,1]\rightarrow a=$ School

$\Pi ^{*}(School)=argmax_{a}[0,2,3]\rightarrow a=$ Hobby

Therefore, the optimal policy in each state provides a sequence of decisions that generates the optimal path sequence in this decision process. As a results, if the student starts in state Work, he/she should choose to go to school, then to enjoy their hobby, then go to sleep.

# Applications

MDPs have been applied in various fields including operations research, electrical engineering, computer science, manufacturing, economics, finance, and telecommunication.$^{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 to take from the current state, the rewards in this case are the costs 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.$^{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. $^{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, 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, MDPs have been used to teach a computer how to play computer games like Pong, Pacman, or AlphaGo.$^{7,8}$ DeepMind Technologies, owned by Google, used the MDP framework in conjunction with neural networks to play Atari games better than human experts. $^{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.$^{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.$^{9}$ 