18
4th April 2005 4th April 2005 Colloquium on Predictive Control, S Colloquium on Predictive Control, S heffield heffield 1 Nonlinear Model Nonlinear Model Predictive Control Predictive Control using using Automatic Automatic Differentiation Differentiation Yi Cao Yi Cao Cranfield University, UK Cranfield University, UK

Nonlinear Model Predictive Control using Automatic Differentiation

Embed Size (px)

DESCRIPTION

Nonlinear Model Predictive Control using Automatic Differentiation. Yi Cao Cranfield University, UK. Outline. Computation in MPC Dynamic Sensitivity using AD Nonlinear Least Square MPC Error Analysis and Control Evaporator Case Study Performance Comparison Conclusions. - PowerPoint PPT Presentation

Citation preview

Page 1: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 11

Nonlinear Model Predictive Nonlinear Model Predictive Control using Control using

Automatic DifferentiationAutomatic Differentiation

Yi CaoYi CaoCranfield University, UKCranfield University, UK

Page 2: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 22

OutlineOutline

Computation in MPCComputation in MPC Dynamic Sensitivity using ADDynamic Sensitivity using AD Nonlinear Least Square MPCNonlinear Least Square MPC Error Analysis and ControlError Analysis and Control Evaporator Case StudyEvaporator Case Study Performance ComparisonPerformance Comparison ConclusionsConclusions

Page 3: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 33

Computation in Predictive ControlComputation in Predictive Control

Predictive control: at tPredictive control: at tkk, calculate OC for t, calculate OC for tkk·· t t·· ttk+Pk+P, apply only u(t, apply only u(tkk), repeat at t), repeat at tk+1k+1

Prediction: online solving ODEPrediction: online solving ODE Optimization: repeat prediction, sensitivity Optimization: repeat prediction, sensitivity

required.required. Typically, over 80% time spend on solving Typically, over 80% time spend on solving

ODE + sensitivityODE + sensitivity

Page 4: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 44

Current StatusCurrent Status

Linear MPC successfully used in industryLinear MPC successfully used in industry Most systems are nonlinear. NMPC desired.Most systems are nonlinear. NMPC desired. Computation: solving Computation: solving ODEODE and and NLP NLP online.online. Difficult to get gradient for large ODE systems.Difficult to get gradient for large ODE systems. Finite difference: inefficient and inaccurateFinite difference: inefficient and inaccurate Sensitivity equation: nSensitivity equation: n××m ODE’sm ODE’s Adjoint system: TPB problemAdjoint system: TPB problem Other methods: sequential linearization and Other methods: sequential linearization and

orthogonal collocation orthogonal collocation

Page 5: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 55

Automatic DifferentiationAutomatic Differentiation

Limitation of finite and symbolic differenceLimitation of finite and symbolic difference Function = sequence of fundamental OPFunction = sequence of fundamental OP Derivatives of fundamental OP are knownDerivatives of fundamental OP are known Numerically apply chain rulesNumerically apply chain rules Basic modes: forward and reverseBasic modes: forward and reverse Implementation: Implementation:

operating overloadingoperating overloading Source translationSource translation

Page 6: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 66

ODE and Automatic DifferentiationODE and Automatic Differentiation

z(t)=f(x), x(t)=xz(t)=f(x), x(t)=x00+x+x11t+xt+x22tt22+…+x+…+xddttd d

z(t)=zz(t)=z00+z+z11t+zt+z22tt22+…+z+…+zddttdd

AD forward: zAD forward: zk k = z= zkk(x(x00,x,x11,…,x,…,xkk)) AD reverse: AD reverse: zzk k //xxj j = = zzk-j k-j / / xx0 0 = A= Ak-jk-j f’(x)=Af’(x)=A00+A+A11t+t++A+Addttdd

ODE: dx/dt=f(x), dx/dt=z(t), xODE: dx/dt=f(x), dx/dt=z(t), xk+1k+1=z=zkk/(k+1)./(k+1). xx00=x(t=x(t00), x), x11=z=z00(x(x00), x), x22=z=z11(x(x00,x,x11), …), … Sensitivity: BSensitivity: Bkk=dx=dxkk/dx/dx00=1/k=1/kkk

i=0i=0 A Ak-i-1k-i-1BBii, B, B00=I=I dB/dt=f’(x), B=BdB/dt=f’(x), B=B00+B+B11t+t++B+Bddttdd

x(tx(t00+1)=+1)=ddi=0i=0 x xii, , dx(tdx(t00+1)/dx+1)/dx00==dd

i=0i=0BBii

Page 7: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 77

Non-autonomous Systems INon-autonomous Systems I

For control systems: dx/dt=f(x,u)For control systems: dx/dt=f(x,u) u(t)=uu(t)=u00+u+u11t+ut+u22tt22+…+u+…+uddttdd

(x(x00, u(t)) , u(t)) →→ x(t), dx(t)/du x(t), dx(t)/dukk=?=? Method I: Augmented system:Method I: Augmented system: dvdv11/dt=v/dt=v22, …, dv, …, dvd+1d+1/dt=0, v/dt=0, vk+1k+1(t(t00)=u)=ukk, u=v, u=v11

X=[xX=[xTT v vTT]]TT, dX/dt=F(X) (, dX/dt=F(X) (autonomousautonomous)) High dimension system, n+mdHigh dimension system, n+md Not suitable for systems with large m Not suitable for systems with large m

Page 8: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 88

Non-autonomous Systems IINon-autonomous Systems II

Method II: nonsquare ADMethod II: nonsquare AD

Let v=[uLet v=[u00TT, u, u11

TT, …, u, …, uddTT]]TT

xxk+1k+1 = z = zkk(x(x00,x,x11,…,x,…,xkk,v)/(k+1),v)/(k+1)

AAkk=[A=[Akxkx | A | Akvkv] := [] := [zzkk//xx00 | | zzkk//v]v]

BBkk=[B=[Bkxkx | B | Bkvkv] := [dx] := [dxkk/dx/dx00 | dx | dxkk/dv]/dv]

BBkk = A = Ak-1k-1++k-1k-1j=1j=1AA(k-j-1)x(k-j-1)xBBjj, B, B00=[I | 0]=[I | 0]

x(tx(t00+1)=+1)=ddk=0k=0xxkk, ,

dx(tdx(t00+1)/dv= +1)/dv= ddk=0k=0BBkv kv ,, dx(tdx(t00+1)/dx(t+1)/dx(t00)= )= dd

k=0k=0BBkxkx

Page 9: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 99

Nonlinear Least Square MPCNonlinear Least Square MPC

ΦΦ==½½∑∑PPk=0k=0

(x(t(x(tkk)-r)-rkk))TTWWkk(x(t(x(tkk)-r)-rkk))

s.t. s.t. dx/dt=f(x,u,d)dx/dt=f(x,u,d), t, t[t[t00, t, tPP], x(t], x(t00) given,) given,

uujj=u(t=u(tjj)=u(t), t)=u(t), t[t[tjj, t, tj+1j+1], u], ujj=u=uM-1M-1, j, j[M, P-1], [M, P-1],

L≤u≤V, scale L≤u≤V, scale t=tt=tj+1j+1-t-tjj=1. =1. Nonlinear LS: minNonlinear LS: minL≤U≤VL≤U≤V ΦΦ==½E(U)½E(U)TTE(U)E(U) Jacobian: Jacobian: J(U)=∂E/∂UJ(U)=∂E/∂U Gradient: G(U)=JGradient: G(U)=JTT(U)E(U)(U)E(U) Hessian: H(U)=JHessian: H(U)=JTT(U)J(U)+Q(U)≈J(U)J(U)+Q(U)≈JTT(U)J(U)(U)J(U)

Page 10: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1010

ODE and JacobianODE and Jacobian using AD using AD

Efficient algorithm requires efficient J(U)Efficient algorithm requires efficient J(U) Difficult: E(U) is nonlinear dynamicDifficult: E(U) is nonlinear dynamic JJi,ji,j=W=Wii

½½dx(tdx(tii))/du/duj-1j-1 for i≥j, otherwise, for i≥j, otherwise, JJi,ji,j=0=0 Algorithm: for k=0:P-1, xAlgorithm: for k=0:P-1, x00=x(t=x(tkk)) Forward AD: xForward AD: xii, i=1,…,d, , i=1,…,d, →→ x(t x(tk+1k+1)) Reverse AD: AReverse AD: Aixix, A, Aiuiu

Accumulate: BAccumulate: Bixix, B, Biuiu, , →→ B Buu(k)=(k)=BBiuiu, B, Bxx(k)=(k)=BBixix

JJ(k+1)j(k+1)j=W=Wk+1k+1½½BBxx(k)…B(k)…Bxx(j)B(j)Buu(j-1), j=1,…,k+1(j-1), j=1,…,k+1

K=k+1K=k+1

Page 11: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1111

NLS MPC using ADNLS MPC using AD

Collect information: x, d, r, etc.Collect information: x, d, r, etc. Nonlinear LS to give a guess uNonlinear LS to give a guess u Solve ODE and calculate JSolve ODE and calculate J Update u and check convergence Update u and check convergence Implement the first moveImplement the first move

Page 12: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1212

Error Analysis Error Analysis

Taylor coefficients by AD is accurate.Taylor coefficients by AD is accurate. x(tx(tkk)=)= x xkk has truncation error, e has truncation error, ekk (local). (local). eekk will propagated to k+1, …, P (global). will propagated to k+1, …, P (global). Local error controllable by order and stepLocal error controllable by order and step Global error depend on sensitivity dxGlobal error depend on sensitivity dxk1k1/dx/dxkk Remainder: Remainder: kk≈≈C(h/r)C(h/r)k+1k+1 Convergence radius: r Convergence radius: r ≈≈ r rkk=|x=|xk-1k-1|/|x|/|xkk|| k-1k-1==kk(r/h)=(r/h)=kk+|x+|xkk| | →→ kk=|x=|xkk|/(r/h-1)|/(r/h-1)

Page 13: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1313

Error ControlError Control

Tolerance Tolerance < < dd

Increase order, d or decrease step, h?Increase order, d or decrease step, h? Decrease h by h/c (c>1): Decrease h by h/c (c>1): ==dd(1/c)(1/c)d+1d+1

c=(c=(dd//))1/(d+1)1/(d+1) , increase op by factor c , increase op by factor c Increase d to d+p (p>0): Increase d to d+p (p>0): ==dd(h/r)(h/r)pp

p=ln(p=ln(//)/ln(h/r), increase op by (1+p/d))/ln(h/r), increase op by (1+p/d)22 c<(1+p/d)c<(1+p/d)22 decrease h, decrease h, otherwise increase dotherwise increase d

Page 14: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1414

Case StudyCase Study

Evaporator processEvaporator process 3 measurable states: L2, X2 and P23 measurable states: L2, X2 and P2 3 manipulates: 0≤F2≤4, 0≤P100,F200≤4003 manipulates: 0≤F2≤4, 0≤P100,F200≤400 Set point change:Set point change: X2 from 25% to 15%X2 from 25% to 15%

P2 from 50.5 kPa to 70 kPaP2 from 50.5 kPa to 70 kPa Disturbance: F1, X1, T1 and T200 Disturbance: F1, X1, T1 and T200 20%20% All disturbance unmeasured.All disturbance unmeasured. T=1 min, M=5 min, P=10 min, W=[100,1,1]T=1 min, M=5 min, P=10 min, W=[100,1,1]

Page 15: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1616

Simulation ResultsSimulation Results

0.8

1

1.2

L2, m

(a)

10

20

30

X2,

%

(b)

50

60

70

80

P2,

kP

a

(c)

1

2

3

4

F2,

kg/

min

(d)

100

200

300

P10

0, k

Pa

(e)

0

100

200

300

F20

0, k

g/m

in

(f )

8

10

12

F1,

kg/

min

(g)

4

5

6

X1,

%

(h)

0 20 40 60 80 10030

40

50

time, min

T1,

o C

(i)

0 20 40 60 80 10020

25

30

time, min

T20

0, o C

(j)

Page 16: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1717

Performance ComparisonPerformance Comparison

CVODES, a state-of-the-art solver for CVODES, a state-of-the-art solver for dynamic sensitivity.dynamic sensitivity.

Simultaneously solves ODE and sensitivitySimultaneously solves ODE and sensitivity Two approaches: full & partial integration.Two approaches: full & partial integration. Three approaches programmed in CThree approaches programmed in C Tested on Windows XP P-IV 2.5GHzTested on Windows XP P-IV 2.5GHz Solve evaporator ODE + sensitivity using Solve evaporator ODE + sensitivity using

input generated by NMPC.input generated by NMPC.

Page 17: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1818

Accuracy and EfficiencyAccuracy and Efficiency

Taylor ADTaylor AD CVODES PCVODES P CVODES FCVODES F

TolTol dd timetime errorerror timetime errorerror timetime ErrorError

1e-41e-4 44 .008.008 7e-57e-5 .022.022 4e-44e-4 .812.812 4e-34e-3

1e-61e-6 66 .009.009 7e-87e-8 .042.042 9e-59e-5 1.641.64 8e-58e-5

1e-81e-8 88 .011.011 4e-114e-11 .063.063 2e-62e-6 2.362.36 2e-62e-6

1e-111e-11 1111 .013.013 5e-135e-13 .114.114 6e-96e-9 4.564.56 3e-113e-11

Page 18: Nonlinear Model Predictive Control using  Automatic Differentiation

4th April 20054th April 2005 Colloquium on Predictive Control, SheffieldColloquium on Predictive Control, Sheffield 1919

ConclusionsConclusions

AD can play an important role to improve AD can play an important role to improve nonlinear model predictive controlnonlinear model predictive control

Efficient algorithm to integrate ODE at the Efficient algorithm to integrate ODE at the same time to calculate sensitivitysame time to calculate sensitivity

Error analysis and control algorithmError analysis and control algorithm Efficiency validated via comparison with Efficiency validated via comparison with

state-of-the-art software. state-of-the-art software. Satisfactory performance with Evaporator Satisfactory performance with Evaporator

studystudy