Reinforcement Learning (QLS-RL) Lecture 6

Reinforcement Learning (QLS-RL) Lecture 6

Introduction

The instructor welcomes the students and explains that they will be going through the concepts introduced in the previous lecture step by step.

Recap of Previous Lecture

The instructor recaps the problem of decision making in a Markovian setting, introduces the notion of a value function for a policy, defines the best policy as the one which maximizes the expectation value, and explains how to compute an approximation which is arbitrary close to the optimal policy.

Value Function Approach

  • The value function of a policy in the discounted case is defined as the expected sum of discounted rewards.
  • The best policy is defined as the one which maximizes this expected sum.
  • G(s) is defined as sum over s. This is averaged overall possible distribution of possibility of states.
  • The maximum quantity is attained when we have an optimal policy.
  • The action which maximizes this quantity gives us our optimal policy.

Bellman Equation Approach

  • Bellman's operator is contracting in l infinity norm.
  • There exists a unique solution to this problem due to contractivity of B.
  • Value iteration algorithm can be used to converge to optimal value function from initial guess for value function.

Policy Focused Approach

The instructor introduces a different approach where focus is on policies instead of value functions.

Abstract Formulation

  • Our target return that we want to optimize is itself a function of policy.
  • There exists some set which represents space of policies. It is a relatively complicated geometrical object but it has nice property that it's convex.
  • G function is a real function that sends.

Developing Intuition for Two-State, Two-Action Systems

In this section, the speaker provides a simple example of a two-state, two-action system to help develop intuition.

Simple Example

  • A generic two-state, two-action problem is presented.
  • The squares represent actions and the circles represent states.
  • Transition probabilities are represented by arrows.
  • The policy space for state one and state two is just a segment that goes from 0 to 1.

Level Lines

  • Level lines are introduced as a way to find the optimal policy.
  • The level lines have a gentle slope going upwards and in the corner where it's maximum is where the function will be taking its optimum.
  • There are always deterministic strategies which are optimal and these functions always have maxima in them except for degeneracies where there are several different actions which have the same value.

Introduction to Policy Space Optimization

In this section, the speaker introduces the concept of policy space optimization and explains why it is important. They also outline the plan for breaking down the problem into several steps.

The Goal of Policy Space Optimization

  • The goal of policy space optimization is to find algorithms that search for the optimal policy directly in policy space.
  • This approach bypasses the notion of value function and looks directly at policies.
  • Different approaches exist in reinforcement learning, some heavily rely on value functions while others focus more on policies or mix up both architectures.

Steps for Policy Space Optimization

  • The first step is to rewrite g in a proper form as explicitly as possible in terms of pi.
  • The second step is to compute where does the gradient point if I am in any point of this square for any policy.
  • By using optimality conditions based on gradients, we can derive Bellman's equation and introduce new algorithms that deal with policies at every step.

Benefits of Policy Space Optimization

  • By focusing on policies instead of just value functions, we get different algorithms that deal with policies at every step.
  • We can rederive Bellman's optimality equations by this approach which focuses on gradients in policy space.

Definition of My G

In this section, the speaker defines "My G" and explains how it is rewritten in terms of explicit averages.

Rewriting My G in Terms of Explicit Averages

  • The first step is to take the sum over time out with the discounting factors.
  • The speaker explains that there are random elements involved, including a state at time t, an action at time t, and a new status at time st + 1.
  • The speaker describes how they arrived at this point by starting from some initial condition over which they have to average. They then came from s bar to s with a certain probability. Once they were there, they could pick an action according to their policy, which would send them to a new state s prime and gather a reward that depends on the triplet s,a,s prime.
  • The speaker explains that the probability transition from one state to another in t steps is the product of probabilities over each of the steps.

Using Matrices for My G

In this section, the speaker discusses using matrices and vectors to rewrite "My G" in a more compact form.

Matrix Vector Notation

  • The speaker explains that if they iterate unfolding over the last step and repeat it again, they can rewrite "My G" using matrix vector notation.
  • The speaker introduces matrix vector notation as a way to map everything in terms of vectors and matrices.
  • The speaker notes that after the lecture, they will post a revised version of their notes on Slack.

Finding a Vector for the State-by-State Matrix

In this section, the speaker discusses finding a vector for the state-by-state matrix.

Focusing on Rewards

  • The speaker notes that they want to find out a vector which is made by focusing on rewards.
  • The speaker explains that since the matrix is a state-by-state matrix, they need to focus on rewards in order to find a vector.

State-Value Function

In this section, the speaker explains how to calculate the expected value of the reward if starting in a given state.

Calculating Expected Value

  • The expected value of the reward can be calculated by starting in a state and picking an action according to policy pi.
  • This leads to ending up in a state s prime and summing up all possible rewards.
  • This is represented by the equation E[R|S=s].

Simplifying G

In this section, the speaker simplifies G by recognizing that part of it is just RS.

Simplifying G

  • The yellow part of G, which involves sums over s prime and a, is just RS.
  • This means that equation 2 is equal to equation 3.

Geometric Sum

In this section, the speaker demonstrates how to rewrite G as a geometric sum.

Rewriting G

  • Equation 2 can be rewritten as a product of matrices using linear algebra.
  • Performing the sums results in R transpose P to the power t times rho zero.
  • This allows us to carry out our sum over time and realize that it's a geometric sum.

Using Matrices for Geometric Sum

In this section, the speaker explains how we can use matrices for geometric sums.

Using Matrices for Geometric Sums

  • We can rewrite our sum over time as a geometric series of matrices.
  • This allows us to rewrite it in terms of another matrix's inverse - identity minus gamma B.
  • The convergence is guaranteed if gamma P is less than one.

Eigenvalues and Gradients

In this section, the speaker discusses eigenvalues and gradients in linear algebra.

Eigenvalues

  • All eigenvalues lie within a ball of radius one.
  • Gamma being smaller than one means that the eigenvalue of gamma p is strictly inside the ball.
  • One minus gamma p is invertible if gamma p is strictly inside the ball.

Rewriting G in a More Compact Form

  • G depends on pi, which makes it more complicated.
  • The object depends on pi in a simple way because it's linear.
  • Capital P is also linear in pi.
  • There is non-linearity due to the inverse of a matrix, but the function remains convex with nice properties.

Deriving Gradients

  • There are two points where there is dependence on pi - g and capital b.
  • Derivative with respect to r goes through i.e., derivative of g with respect to r equals derivative of g times derivative of r plus derivative of capital b times derivative of r.
  • Chain rule applies when deriving inverse matrices for gradients.

Understanding the Inverse

The speaker explains how to calculate the inverse of a matrix and takes care to note that matrices are not necessarily commutative.

Calculating the Inverse

  • The inverse is defined as one over f, not f prime f squared.
  • Matrices are not necessarily commutative, so care must be taken when calculating inverses.
  • To calculate the inverse, multiply the matrix by its inverse to get the identity matrix.
  • Take gradients of both sides and use chain rule to get formula for inverse of matrices.

Manipulating Equations

  • Use simple manipulations to isolate new eta from equation 7.
  • Regroup everything on left side and isolate new eta to get equation 8.

Understanding Eta

  • There are two terms on right hand side which are same. They represent initial condition multiplied by inverse matrix, which is called eta.
  • Eta is defined as sum t going zero to infinity gamma t times components of matrix p to power t.

Interpreting the Object

In this section, the speaker explains how to interpret an object and its components.

Components of the Object

  • The object is p to the power t components s bar.
  • The components are s and s bar.

Interpretation of Discounting

  • Discounting can be interpreted as the probability of not being killed at each step.
  • Gamma is the survival probability.
  • With probability one minus gamma, the process gets killed at each step.

Augmented Markov Process

  • The augmented Markov process involves discounting ascending with probability gamma into the coffin state.
  • The sum over t means that at each time step, if I have survived and end up being in state s, I add one plus one.

Monte Carlo Simulation

  • To compute this object by Monte Carlo simulation, start from a state and let it evolve according to your stochastic process.
  • Every time it is in state s, put a one.
  • Kill the process with probability 1 minus gamma.

Value Function of Policy

In this section, the speaker defines an object as a vector v and explains why it is called a value function.

Definition of Object V

  • R transposed multiplied by one minus gamma b to power one equals vector v.
  • Vector v is a row vector.

Value Function Explanation

  • Multiplying both sides on the right by one minus gamma b gives rt equals 1 minus gamma p v transpose.
  • This can be rewritten as rt plus gamma p vt equals vt.
  • This equation shows that vector v is called a value function.

Linear Policy Gradients

In this section, the speaker introduces the value function and its importance in optimization. They then derive equation 9, which connects the value function to the gradient of the policy.

Deriving Equation 9

  • The speaker replaces definitions for row and p with those for capital R and B.
  • This leads to a recursion relation that connects the value function at a certain state with that at the next state.
  • The resulting equation is called equation number nine.

Taking Derivatives

  • Capital R and capital P are linear in policy, so derivatives can be taken easily.
  • The derivative of capital R is straightforward and gets into the sum.
  • Similarly, inserting definitions for capital P yields another simple derivative.

Final Steps

  • After plugging everything in, we arrive at equation 10.
  • The value function pops up again despite our initial focus on policy space because it contains all relevant information about future rewards.
  • Equation 10 contains three different pieces.

Understanding Policy Gradient Theorem

In this section, the speaker explains how to compute the policy gradient theorem and its components.

Computing Policy Gradient Theorem

  • The policy gradient theorem tells us how much time we spend in state s given our initial condition. It is about the past and sums over all trajectories that brought us to state s.
  • The theorem also considers everything that will happen in the future from state s onwards from the viewpoint of returns of rewards.
  • Total variation in objective function is a result of two operations: everything that happened before and brought us to the current context, and everything that will happen in the future leading to gain rewards.
  • The gradient formula for policy gradient is known as the policy gradient theorem.

Taking Two Gradients Explicitly

  • We consider the policy as coordinates and take derivatives with respect to horizontal and vertical coordinates.
  • Derivatives are taken with respect to other dependent coordinates just for notation purposes but not necessary since some derivatives are equal.
  • We consider functions as a function of all possible objects without caring about constraints since they will be reflected in gradients.
  • Abstract derivative operation (nabla) is turned into an explicit derivative with respect to one policy component.

Computing Vector Components

  • We find out how to compute a vector depending on where we are in a square, which varies based on policy, gradient, value function, and occupation time.
  • Derivative of pi a s with respect to any pi a prime s prime is just one if they are equal and zero otherwise.
  • Sums over s and a can be killed if derivatives are taken with respect to policy components.

State-Action Value Function

In this section, the speaker introduces the state-action value function or Q-function and explains its relationship with the policy and value functions.

Introduction to Q-function

  • The Q-function is the sum over s prime of a discounted cumulative reward.
  • It represents what you expect to collect as a discounted cumulative reward if you start from a given state and take a certain action.
  • The Q-function is equivalent to the state-action value function.
  • The Q-function is implicitly dependent on the policy.

Relationship between Policy, Value Function, and Q-function

  • The value function depends on the policy and conditions only on states.
  • The Q-function depends on both states and actions but has the same content as the value function.
  • You can go from Q to V and vice versa using their definitions.
  • Since policies determine future actions, they also affect what you will get in the future starting from a certain state and action.

Equation 12

  • There is a compact expression for the object that represents changes in objective functions due to changes in policies.
  • This equation involves taking derivatives of both sides of an equation with respect to eta_s.

Gradient Manipulation

In this section, the speaker explains how the gradient is manipulated in a way that allows for a more complicated form of writing it. The gradient depends on two objects which depend on pi.

Gradient Manipulation

  • The gradient is manipulated to allow for a more complicated form of writing it.
  • The gradient depends on two objects which by themselves depend on pi.

First Order Condition for Optimality

In this section, the speaker discusses the first order condition for optimality and how it relates to finding optimal points given the gradient.

Optimality Condition

  • The first order condition for optimality states that if you have a function in a convex set, then there are two possibilities. Either the maximum is attained inside the domain and must be a stationary point or if it's strictly inside and has a single extremum, then it's a maximum.
  • If the point sits on the boundary, then the gradient must be pointing outwards. If the maximum is sitting on the boundary, then the gradient of the function must be going towards outside of the domain.

Using Q Function to Prove Optimality

  • Assume that my policy which optimizes my g is given by this property of my q star function at optimality. We can read it from q star so if we knew what q star is, this is a matrix okay q star you can think of as any queue but in particular q star you can think as a matrix which has states here and actions here or vice versa whatever you like.
  • We assume that optimal policy can be read from q star. If we knew what the q star is, this is a matrix.

Understanding the First Order Optimality Condition

In this section, the speaker explains how to define and use the first order optimality condition in reinforcement learning.

Defining the First Order Optimality Condition

  • The first order optimality condition involves selecting an action that maximizes a given state-action pair.
  • This is done by comparing all possible options and choosing the one with the largest cube.
  • This choice is then plugged into the q star matrix to replace pi star.

Using Q Star Matrix

  • The left-hand side of the optimality condition involves taking a gradient of a specific object.
  • Pi star must be chosen according to a specific assumption, which is that it maximizes q star.
  • The first sum in this equation becomes a larger or equal value than any other item in its column.

Applying Policy

  • By multiplying both sides of this equation by sum over a, we can see that any policy satisfies this optimality condition.
  • The optimal action must be chosen based on which reaction has the largest q star for each value of s.
  • This exercise can be done explicitly with mathematical expressions for better understanding.

Bellman's Equation and Policy Gradient

In this section, the speaker discusses the relationship between Bellman's equation and policy gradient. They explain how the optimal policy can be obtained using Bellman's equation and how it relates to the balance equation. The speaker also emphasizes the importance of policy gradient in writing algorithms for optimization in policy space.

Relationship between Bellman's Equation and Policy Gradient

  • The speaker explains that Bellman's equation is equivalent to their previous derivation of the balance equation.
  • They note that this equivalence confirms that Bellman's equation describes optimality.
  • The optimal policy can be obtained by replacing variables in the balance equation with those from Bellman's equation.
  • By plugging in optimal action into the recursion relation, one obtains the definition of v which is equivalent to Bellman's equation.

Importance of Policy Gradient

  • While obtaining the balance equation through Bellman's equation is not strictly important, it confirms optimality. What is more important is understanding policy gradient as it allows for writing algorithms for optimization in policy space.
  • The speaker notes that they will skip discussing algorithmic parts until tomorrow but emphasizes that intertwining learning and optimization is key to efficient reinforcement learning.
  • Sampling becomes important when transitioning to model-free reinforcement learning where there is no access to transition probabilities or computational power to solve Bellman's equations.

Recap

  • The speaker recaps what has been covered so far: rewriting g in another form, taking gradients, looking at level lines of g, etc.

Constructing Algorithms in Policy Space

In this section, the speaker discusses constructing algorithms in policy space and the different types of algorithms that will be covered.

Types of Algorithms

  • The speaker mentions that there are several algorithms that will be covered.
  • The discussion on these algorithms will take place tomorrow.

Questions and Revised Notes

  • The speaker hopes to have eased any confusion or concerns.
  • The speaker asks if there are any questions.
  • There are no questions, and the revised notes will be posted on Slack for those interested.
  • The speaker reminds attendees to pressure those responsible for posting lessons. Lecture videos have already been uploaded to YouTube.

Conclusion

  • The speaker concludes by saying goodbye and reminding attendees that something is moving forward.

Turn any video into a summary like this

YouTube links, meetings, lectures. With transcripts, search, and chat.

Video description

QUANTITATIVE LIFE SCIENCE Reinforcement Learning (QLS-RL) A. Celani QLS-RL-L06-Celani-Zoom.mp4