aa203 optimal and learning-based control - stanford...

22
AA203 Optimal and Learning-based Control Stochastic DP, value iteration, policy iteration, stochastic LQR

Upload: others

Post on 11-Mar-2021

2 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

AA203Optimal and Learning-based Control

Stochastic DP, value iteration, policy iteration, stochastic LQR

Page 2: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Roadmap

Open-loop

Indirect methods

Direct methods

Closed-loop

DP HJB / HJI

MPC

Adaptiveoptimal control

Model-based RL

Model-free RLControl

Optimal and learning control

Adaptive controlFeedback control

4/15/21 AA 203 | Lecture 6 2

Page 3: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Stochastic optimal control problem(MDPs)• System: 𝒙!"# = 𝑓!(𝒙! , 𝒖! , 𝒘!), 𝑘 = 0,… ,𝑁 − 1• Control constraints: 𝒖! ∈ 𝑈(𝒙!)• Probability distribution: 𝑃!(⋅ |𝒙! , 𝒖!) of 𝒘!• Policies: 𝜋 = {𝜋$ … , 𝜋%&#}, where 𝒖! = 𝜋!(𝒙!)• Expected Cost:

𝐽' 𝒙$ = 𝐸𝒘!,!*$,…,%&# 𝑔% 𝒙% + <!*$

%&#

𝑔! 𝒙! , 𝜋! 𝒙! , 𝒘!

• Stochastic optimal control problem𝐽∗ 𝑥$ = min

'𝐽'(𝒙$)

4/15/21 AA 203 | Lecture 6 3

Page 4: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Key points

• Discrete-time model• Markovian model• Objective: find optimal closed-loop policy• Additive cost (central assumption)• Risk-neutral formulation

Other communities use different notation: Powell, W. B. AI, OR and control theory: A Rosetta Stone for stochastic optimization. Princeton University, 2012.

4/15/21 AA 203 | Lecture 6 4

Page 5: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Principle of optimality

• Let 𝜋∗ = {𝜋"∗ , 𝜋#∗, … , 𝜋$%#∗ } be an optimal policy• Consider tail subproblem

𝐸 𝑔$(𝒙$) + -&'(

$%#

𝑔&(𝒙& , 𝜋&(𝒙&), 𝒘&)

and the tail policy {𝜋(∗, … , 𝜋$%#∗ }

Principle of optimality: The tail policy is optimal for the tail subproblem

4/15/21 AA 203 | Lecture 6 5

Page 6: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

The DP algorithm (stochastic case)

Intuition• DP first solves ALL tail subproblems at the final stage• At generic step, it solves ALL tail subproblems of a given time

length, using solution of tail subproblems of shorter length

4/15/21 AA 203 | Lecture 6 6

Page 7: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

The DP algorithm (stochastic case)

The DP algorithm • Start with

𝐽$(𝒙$) = 𝑔$(𝒙$)and go backwards using𝐽& 𝒙& = min

𝒖!∈+(𝒙!)𝐸/! 𝑔& 𝒙& , 𝒖& , 𝒘& + 𝐽&0# (𝑓 𝒙& , 𝒖& , 𝒘&)

for 𝑘 = 0, 1, … , 𝑁 − 1• Then 𝐽∗(𝒙") = 𝐽"(𝒙") and optimal policy is constructed by setting 𝜋&∗(𝒙&) = argmin

𝒖!∈+(𝒙!)𝐸/! 𝑔& 𝒙& , 𝒖& , 𝒘& + 𝐽&0# (𝑓 𝒙& , 𝒖& , 𝒘&)

4/15/21 AA 203 | Lecture 6 7

Page 8: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Example: Inventory Control Problem (1/4)

• Stock available 𝑥& ∈ ℕ, inventory 𝑢& ∈ ℕ, and demand 𝑤& ∈ ℕ• Dynamics: 𝑥&0# = max(0, 𝑥& + 𝑢& −𝑤&)• Constraints: 𝑥& + 𝑢& ≤ 2• Probabilistic structure: 𝑝(𝑤& = 0) = 0.1, 𝑝(𝑤& = 1) = 0.7, and 𝑝(𝑤& = 2) = 0.2• Cost

𝐸 0 + -&'"

1

( 𝑢& + 𝑥& + 𝑢& − 𝑤& 1)

𝑔!( 𝑥!) 𝑔"( 𝑥" , 𝑢" , 𝑤")

4/15/21 AA 203 | Lecture 6 8

Page 9: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Example: Inventory Control Problem (2/4)

4/15/21 AA 203 | Lecture 6 9

Page 10: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Example: Inventory Control Problem (3/4)

• Algorithm takes form𝐽& 𝑥& = min

"2 3!2 1%4!𝐸/![𝑢& + 𝑥& + 𝑢& − 𝑤& 1

+𝐽&0# max(0, 𝑥& + 𝑢& −𝑤&))for 𝑘 = 0,1,2• For example𝐽1 0 = min

3"'",#,1𝐸/" 𝑢1 + 𝑢1 − 𝑤1 1 =

min3"'",#,1

𝑢1 + 0.1 𝑢1 1 + 0.7 𝑢1 − 1 1 + 0.2 𝑢1 − 2 1

which yields 𝐽1(0) = 1.3, and 𝜋1∗(0) = 1

4/15/21 AA 203 | Lecture 6 10

Page 11: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Example: Inventory Control Problem (4/4)

Final solution:• 𝐽"(0) = 3.7, • 𝐽"(1) = 2.7, and • 𝐽"(2) = 2.818

4/15/21 AA 203 | Lecture 6 11

Page 12: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Stochastic LQR

Find control policy that minimizes

𝐸 𝒙$6𝑄𝒙$ + -&'"

$%#

𝒙&6𝑄&𝒙& + 𝒖&6𝑅&𝒖&

subject to

• dynamics 𝒙&0# = 𝐴&𝒙& + 𝐵&𝒖& +𝒘&

with 𝒙", 𝒘& independent and Gaussian vectors (and in addition 𝒘& zero mean)

4/15/21 AA 203 | Lecture 6 12

Page 13: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Stochastic LQR

4/15/21 AA 203 | Lecture 6 13

Page 14: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Infinite Horizon MDPs

State: 𝑥 ∈ 𝒳 (often 𝑠 ∈ 𝒮)Action: 𝑢 ∈ 𝒰 (often 𝑎 ∈ 𝒜)Transition Function: 𝑇 𝑥7 𝑥7%# , 𝑢7%#) = 𝑝(𝑥7|𝑥7%#, 𝑢7%#)Reward Function: 𝑟7 = 𝑅(𝑥7 , 𝑢7)Discount Factor: 𝛾

MDP: ℳ = (𝒳,𝒰, 𝑇, 𝑅, 𝛾)

4/15/21 AA 203 | Lecture 6 14

Page 15: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Infinite Horizon MDPs

MDP: ℳ = (𝒳,𝒰, 𝑇, 𝑅, 𝛾)

Stationary policy: 𝑢7 = 𝜋(𝑥7)

Goal: Choose policy that maximizescumulative reward

𝜋∗ = arg max8

𝐸 -79"

𝛾7𝑅 𝑥7 , 𝜋 𝑥7

4/15/21 AA 203 | Lecture 6 15

Page 16: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Infinite Horizon MDPs

• The optimal reward 𝑉∗(𝑥) satisfies Bellman’s equation

𝑉∗(𝑥) = max-

𝑅 𝑥, 𝑢 + 𝛾 <."∈𝒳

𝑇 𝑥1 𝑥, 𝑢 𝑉∗ 𝑥1

• For any stationary policy 𝜋, the reward V'(𝑥) is the unique solution to the equation

V'(𝑥) = 𝑅 𝑥, 𝑢 + 𝛾 <."∈𝒳

𝑇 𝑥1 𝑥, 𝑢 V' 𝑥1

4/15/21 AA 203 | Lecture 6 16

Page 17: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Solving infinite-horizon MDPs

If you know the model, use DP-ideas• Value Iteration / Policy Iteration

RL: Learning from interaction• Model-Based• Model-free• Value based• Policy based

4/15/21 AA 203 | Lecture 6 17

Page 18: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Value Iteration

• Initialize 𝑉"(𝑥) = 0 for all states 𝑥• Loop until finite horizon / convergence:

𝑉&0# (𝑥) = max3

𝑅 𝑥, 𝑢 + 𝛾 -4#∈𝒳

𝑇 𝑥; 𝑥, 𝑢 𝑉& 𝑥;

4/15/21 AA 203 | Lecture 6 18

Page 19: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Q functions

𝑉∗(𝑥) = max3

𝑅 𝑥, 𝑢 + 𝛾 -4#∈𝒳

𝑇 𝑥; 𝑥, 𝑢 𝑉∗ 𝑥;

𝑉∗(𝑥) = max3𝑄∗(𝑥, 𝑢)

• VI for Q functions

𝑄&0# 𝑥, 𝑢 = 𝑅 𝑥, 𝑢 + 𝛾 -4#∈𝒳

𝑇 𝑥; 𝑥, 𝑢 max3𝑄& 𝑥′, 𝑢

4/15/21 AA 203 | Lecture 6 19

Page 20: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Policy Iteration

Suppose we have a policy 𝜋&(𝑥)We can use VI to compute 𝑉8!(𝑥)

Define 𝜋&0# 𝑥 = argmax3

𝑅 𝑥, 𝑢 + 𝛾 ∑4#∈𝒳 𝑇 𝑥; 𝑥, 𝑢 𝑉8! 𝑥;

Proposition: 𝑉8!$% 𝑥 ≥ 𝑉8! 𝑥 ∀ 𝑥 ∈ 𝒳Inequality is strict if 𝜋& is suboptimal

Use this procedure to iteratively improve policy until convergence

4/15/21 AA 203 | Lecture 6 20

Page 21: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Recap

• Value Iteration• Estimate optimal value function• Compute optimal policy from optimal value function

• Policy Iteration• Start with random policy• Iteratively improve it until convergence to optimal policy

• Require model of MDP to work!

4/15/21 AA 203 | Lecture 6 21

Page 22: AA203 Optimal and Learning-based Control - Stanford ASLasl.stanford.edu/aa203/pdfs/lecture/lecture_6.pdfToday’s lecture •Aim •Provide intro to RL References: •Sutton and Barto,

Next time

• Belief space MDPs• Dual control• LQG• Intro to reinforcement learning

4/15/21 AA 203 | Lecture 6 22