Real-Time Embedded Convex Optimization



Similar documents
Solving polynomial least squares problems via semidefinite programming relaxations

Lecture 13 Linear quadratic Lyapunov theory

C21 Model Predictive Control

Nonlinear Programming Methods.S2 Quadratic Programming

An Overview Of Software For Convex Optimization. Brian Borchers Department of Mathematics New Mexico Tech Socorro, NM

Conic optimization: examples and software

Optimization of warehousing and transportation costs, in a multiproduct multi-level supply chain system, under a stochastic demand

An Introduction on SemiDefinite Program

Java Modules for Time Series Analysis

Advances in Convex Optimization: Interior-point Methods, Cone Programming, and Applications

POTENTIAL OF STATE-FEEDBACK CONTROL FOR MACHINE TOOLS DRIVES

Duality in General Programs. Ryan Tibshirani Convex Optimization /36-725

Probability and Random Variables. Generation of random variables (r.v.)

TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAA

19 LINEAR QUADRATIC REGULATOR

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

A Log-Robust Optimization Approach to Portfolio Management

8. Linear least-squares

Automated Stellar Classification for Large Surveys with EKF and RBF Neural Networks

Lecture 5 Least-squares

Interior-Point Algorithms for Quadratic Programming

Adaptive cruise controller design: a comparative assessment for PWA systems

APPM4720/5720: Fast algorithms for big data. Gunnar Martinsson The University of Colorado at Boulder

CVXGEN: a code generator for embedded convex optimization

Lecture 2: The SVM classifier

Course 8. An Introduction to the Kalman Filter

Statistical Machine Learning

Modern Optimization Methods for Big Data Problems MATH11146 The University of Edinburgh

Applications to Data Smoothing and Image Processing I

Convex Optimization. Lieven Vandenberghe University of California, Los Angeles

MIMO CHANNEL CAPACITY

1 Finite difference example: 1D implicit heat equation

Nonlinear Optimization: Algorithms 3: Interior-point methods

Kalman Filter Applied to a Active Queue Management Problem

Big Data - Lecture 1 Optimization reminders

TOMLAB - For fast and robust largescale optimization in MATLAB

FE570 Financial Markets and Trading. Stevens Institute of Technology

6. Cholesky factorization

Lecture 2 Linear functions and examples

Simple and efficient online algorithms for real world applications

Distributionally Robust Optimization with ROME (part 2)

EDUMECH Mechatronic Instructional Systems. Ball on Beam System

Methods for Vibration Analysis

WEEK #3, Lecture 1: Sparse Systems, MATLAB Graphics

Language Modeling. Chapter Introduction

STORM: Stochastic Optimization Using Random Models Katya Scheinberg Lehigh University. (Joint work with R. Chen and M. Menickelly)

Mathematical finance and linear programming (optimization)

Computing a Nearest Correlation Matrix with Factor Structure

Neuro-Dynamic Programming An Overview

Summer course on Convex Optimization. Fifth Lecture Interior-Point Methods (1) Michel Baes, K.U.Leuven Bharath Rangarajan, U.

Matlab and Simulink. Matlab and Simulink for Control

Sample Size Calculation for Longitudinal Studies

INDIRECT INFERENCE (prepared for: The New Palgrave Dictionary of Economics, Second Edition)

Blind Deconvolution of Barcodes via Dictionary Analysis and Wiener Filter of Barcode Subsections

10. Proximal point method

Big Data Optimization at SAS

Advanced Lecture on Mathematical Science and Information Science I. Optimization in Finance

Automatic Stress and Load Testing for Embedded Systems

Introduction to Engineering System Dynamics

Parameter Estimation for Bingham Models

CCNY. BME I5100: Biomedical Signal Processing. Linear Discrimination. Lucas C. Parra Biomedical Engineering Department City College of New York

A REVIEW OF FAST l 1 -MINIMIZATION ALGORITHMS FOR ROBUST FACE RECOGNITION

FUZZY CLUSTERING ANALYSIS OF DATA MINING: APPLICATION TO AN ACCIDENT MINING SYSTEM

Single item inventory control under periodic review and a minimum order quantity

Real-Time Systems Versus Cyber-Physical Systems: Where is the Difference?

TWO L 1 BASED NONCONVEX METHODS FOR CONSTRUCTING SPARSE MEAN REVERTING PORTFOLIOS

Optimization Modeling for Mining Engineers

2+2 Just type and press enter and the answer comes up ans = 4

Numerisches Rechnen. (für Informatiker) M. Grepl J. Berger & J.T. Frings. Institut für Geometrie und Praktische Mathematik RWTH Aachen

Constrained Least Squares

Optimization Methods in Finance

The Filtered-x LMS Algorithm

Controller Design in Frequency Domain

Robust Optimization for Unit Commitment and Dispatch in Energy Markets

Solutions Of Some Non-Linear Programming Problems BIJAN KUMAR PATEL. Master of Science in Mathematics. Prof. ANIL KUMAR

Parameter identification of a linear single track vehicle model

2004 Networks UK Publishers. Reprinted with permission.

Multivariate normal distribution and testing for means (see MKB Ch 3)

Least Squares Estimation

PATTERN RECOGNITION AND MACHINE LEARNING CHAPTER 4: LINEAR MODELS FOR CLASSIFICATION

Linear Programming Notes V Problem Transformations

Using MATLAB in a Graduate Electrical Engineering Optimal Control Course

Week 1 Lecture: (1) Course Introduction (2) Data Analysis and Processing

CALIBRATION OF A ROBUST 2 DOF PATH MONITORING TOOL FOR INDUSTRIAL ROBOTS AND MACHINE TOOLS BASED ON PARALLEL KINEMATICS

Real Time Simulation for Off-Road Vehicle Analysis. Dr. Pasi Korkealaakso Mevea Ltd., May 2015

PID Controller Design for Nonlinear Systems Using Discrete-Time Local Model Networks

So which is the best?

Probability Generating Functions

For a partition B 1,..., B n, where B i B j = for i. A = (A B 1 ) (A B 2 ),..., (A B n ) and thus. P (A) = P (A B i ) = P (A B i )P (B i )

METHODOLOGICAL CONSIDERATIONS OF DRIVE SYSTEM SIMULATION, WHEN COUPLING FINITE ELEMENT MACHINE MODELS WITH THE CIRCUIT SIMULATOR MODELS OF CONVERTERS.

Nonlinear Algebraic Equations Example

CSCI567 Machine Learning (Fall 2014)

Robotics & Automation

Hybrid processing of SCADA and synchronized phasor measurements for tracking network state

Understanding and Applying Kalman Filtering

Transcription:

Real-Time Embedded Convex Optimization Stephen Boyd joint work with Michael Grant, Jacob Mattingley, Yang Wang Electrical Engineering Department, Stanford University Spencer Schantz Lecture, Lehigh University, 12/6/10

Outline Real-time embedded convex optimization Examples Parser/solvers for convex optimization Code generation for real-time embedded convex optimization Spencer Schantz Lecture, Lehigh University, 12/6/10 1

Embedded optimization embed solvers in real-time applications i.e., solve an optimization problem at each time step used now for applications with hour/minute time-scales process control supply chain and revenue management trading Spencer Schantz Lecture, Lehigh University, 12/6/10 2

What s new embedded optimization at millisecond/microsecond time-scales problem size millions thousands traditional problems our focus tens microseconds seconds hours days solve time Spencer Schantz Lecture, Lehigh University, 12/6/10 3

real-time resource allocation Applications update allocation as objective, resource availabilities change signal processing estimate signal by solving optimization problem over sliding window replace least-squares estimates with robust (Huber, l 1 ) versions re-design (adapt) coefficients as signal/system model changes control closed-loop control via rolling horizon optimization real-time trajectory planning all of these done now, on long (minutes or more) time scales but could be done on millisecond/microsecond time scales Spencer Schantz Lecture, Lehigh University, 12/6/10 4

Outline Real-time embedded convex optimization Examples Parser/solvers for convex optimization Code generation for real-time embedded convex optimization Spencer Schantz Lecture, Lehigh University, 12/6/10 5

Multi-period processor speed scheduling processor adjusts its speed s t [s min,s max ] in each of T time periods energy consumed in period t is φ(s t ); total energy is E = T t=1 φ(s t) n jobs job i available at t = A i ; must finish by deadline t = D i job i requires total work W i 0 S ti 0 is effective processor speed allocated to job i in period t s t = n S ti, i=1 D i t=a i S ti W i Spencer Schantz Lecture, Lehigh University, 12/6/10 6

Minimum energy processor speed scheduling choose speeds s t and allocations S ti to minimize total energy E minimize E = T t=1 φ(s t) subject to s min s t s max, t = 1,...,T s t = n i=1 S ti, t = 1,...,T Di t=a i S ti W i, i = 1,...,n a convex problem when φ is convex more sophisticated versions include multiple processors other constraints (thermal, speed slew rate,... ) stochastic models for (future) data Spencer Schantz Lecture, Lehigh University, 12/6/10 7

Example T = 16 periods, n = 12 jobs s min = 1, s max = 6, φ(s t ) = s 2 t jobs shown as bars over [A i,d i ] with area W i 40 12 35 30 10 φt(st) 25 20 15 job i 8 6 4 10 5 2 0 0 1 2 3 4 5 6 7 s t 0 0 2 4 6 8 10 12 14 16 18 t Spencer Schantz Lecture, Lehigh University, 12/6/10 8

Optimal and uniform schedules uniform schedule: S ti = W i /(D i A i ); gives E unif = 374.1 optimal schedule Sti gives E = 167.1 optimal uniform 6 6 5 5 4 4 st 3 st 3 2 2 1 1 0 0 2 4 6 8 10 12 14 16 18 t 0 0 2 4 6 8 10 12 14 16 18 t Spencer Schantz Lecture, Lehigh University, 12/6/10 9

Minimum time control with active vibration supression F T force F(t) moves object modeled as 3 masses (2 vibration modes) tension T(t) used for active vibration supression goal: move object to commanded position as quickly as possible, with F(t) 1, T(t) 0.1 Spencer Schantz Lecture, Lehigh University, 12/6/10 10

Ignoring vibration modes treat object as single mass; apply only F analytical ( bang-bang ) solution 3 1 y3(t) 2.5 2 1.5 1 0.5 T(t) F(t) 0.5 0 0.5 1 0.1 0.05 0 0.05 2 0 2 4 6 8 10 12 14 16 18 20 t 0 2 0 2 4 6 8 10 12 14 16 18 20 t 0.1 2 0 2 4 6 8 10 12 14 16 18 20 t Spencer Schantz Lecture, Lehigh University, 12/6/10 11

With vibration modes no analytical solution, but reduces to a quasiconvex problem can be solved by solving a small number of convex problems 3 1 y3(t) 2.5 2 1.5 1 0.5 T(t) F(t) 0.5 0 0.5 1 0.1 0.05 0 0.05 2 0 2 4 6 8 10 12 14 16 18 20 t 0 2 0 2 4 6 8 10 12 14 16 18 20 t 0.1 2 0 2 4 6 8 10 12 14 16 18 20 t Spencer Schantz Lecture, Lehigh University, 12/6/10 12

Grasp force optimization choose K grasping forces on object to resist external wrench (force and torque) respect friction cone constraints minimize maximum grasp force convex problem (second-order cone program or SOCP): minimize max i f (i) 2 max contact force subject to i Q(i) f (i) = f ext force equillibrium i p(i) (Q (i) f (i) ) = τ ext torque equillibrium ( ) 1/2 µ i f z (i) f x (i)2 +f y (i)2 friction cone constraints variables f (i) R 3, i = 1,...,K (contact forces) Spencer Schantz Lecture, Lehigh University, 12/6/10 13

Example Spencer Schantz Lecture, Lehigh University, 12/6/10 14

Grasp force optimization solve times example with K = 5 fingers (grasp points) reduces to SOCP with 15 vars, 6 eqs, 5 3-dim SOCs custom code solve time: 50µs (SDPT3: 100ms) Spencer Schantz Lecture, Lehigh University, 12/6/10 15

Robust Kalman filtering estimate state of a linear dynamical system driven by IID noise sensor measurements have occasional outliers (failures, jamming,... ) model: x t+1 = Ax t +w t, y t = Cx t +v t +z t w t N(0,W), v t N(0,V) z t is sparse; represents outliers, failures,... (steady-state) Kalman filter (for case z t = 0): time update: ˆx t+1 t = Aˆx t t measurement update: ˆx t t = ˆx t t 1 +L(y t Cˆx t t 1 ) we ll replace measurement update with robust version to handle outliers Spencer Schantz Lecture, Lehigh University, 12/6/10 16

Measurement update via optimization standard KF: ˆx t t is solution of quadratic problem minimize v T V 1 v +(x ˆx t t 1 ) T Σ 1 (x ˆx t t 1 ) subject to y t = Cx+v with variables x, v (simple analytic solution) robust KF: choose ˆx t t as solution of convex problem minimize v T V 1 v +(x ˆx t t 1 ) T Σ 1 (x ˆx t t 1 )+λ z 1 subject to y t = Cx+v +z with variables x, v, z (requires solving a QP) Spencer Schantz Lecture, Lehigh University, 12/6/10 17

Example 50 states, 15 measurements with prob. 5%, measurement components replaced with (y t ) i = (v t ) i so, get a flawed measurement (i.e., z t 0) every other step (or so) Spencer Schantz Lecture, Lehigh University, 12/6/10 18

State estimation error x ˆx t t 2 for KF (red); robust KF (blue); KF with z = 0 (gray) 0.5 Spencer Schantz Lecture, Lehigh University, 12/6/10 19

Robust Kalman filter solve time robust KF requires solution of QP with 95 vars, 15 eqs, 30 ineqs automatically generated code solves QP in 120 µs (SDPT3: 120 ms) standard Kalman filter update requires 10 µs Spencer Schantz Lecture, Lehigh University, 12/6/10 20

Linearizing pre-equalizer linear dynamical system with input saturation h y we ll design pre-equalizer to compensate for saturation effects u equalizer v h y Spencer Schantz Lecture, Lehigh University, 12/6/10 21

Linearizing pre-equalizer h u e equalizer v h goal: minimize error e (say, in mean-square sense) pre-equalizer has T sample look-ahead capability Spencer Schantz Lecture, Lehigh University, 12/6/10 22

system: x t+1 = Ax t +Bsat(v t ), y t = Cx t (linear) reference system: x ref t+1 = Ax ref t +Bu t, yt ref = Cx ref t e t = Cx ref t Cx t state error x t = x ref t x t satisfies x t+1 = A x t +B(u t v t ), e t = C x t to choose v t, solve QP t+t minimize τ=t e2 τ + x T t+t+1 P x t+t+1 subject to x τ+1 = A x τ +B(u τ v τ ), e τ = C x τ, τ = t,...,t+t v τ 1, τ = t,...,t+t P gives final cost; obvious choice is output Grammian Spencer Schantz Lecture, Lehigh University, 12/6/10 23

Example state dimension n = 3; h decays in around 35 samples pre-equalizer look-ahead T = 15 samples input u random, saturates ( u t > 1) 20% of time Spencer Schantz Lecture, Lehigh University, 12/6/10 24

Outputs desired (black), no compensation (red), equalized (blue) 2.5 0 2.5 Spencer Schantz Lecture, Lehigh University, 12/6/10 25

Errors no compensation (red), with equalization (blue) 0.75 0 0.75 Spencer Schantz Lecture, Lehigh University, 12/6/10 26

Inputs no compensation (red), with equalization (blue) 2.5 0 2.5 Spencer Schantz Lecture, Lehigh University, 12/6/10 27

Linearizing pre-equalizer solve time pre-equalizer problem reduces to QP with 96 vars, 63 eqs, 48 ineqs automatically generated code solves QP in 600µs (SDPT3: 310ms) Spencer Schantz Lecture, Lehigh University, 12/6/10 28

Constrained linear quadratic stochastic control linear dynamical system: x t+1 = Ax t +Bu t +w t x t R n is state; u t U R m is control input w t is IID zero mean disturbance u t = φ(x t ), where φ : R n U is (state feedback) policy objective: minimize average expected stage cost (Q 0, R > 0) J = lim T 1 T T 1 t=0 E ( x T t Qx t +u T t Ru t ) constrained LQ stochastic control problem: choose φ to minimize J Spencer Schantz Lecture, Lehigh University, 12/6/10 29

Constrained linear quadratic stochastic control optimal policy has form φ(z) = argmin{v T Rv +EV(Az +Bv +w t )} v U where V is Bellman function but V is hard to find/describe except when U = R m (in which case V is quadratic) many heuristic methods give suboptimal policies, e.g. projected linear control control-lyapunov policy model predictive control, certainty-equivalent planning Spencer Schantz Lecture, Lehigh University, 12/6/10 30

Control-Lyapunov policy also called approximate dynamic programming, horizon-1 model predictive control CLF policy is φ clf (z) = argmin{v T Rv +EV clf (Az +Bv +w t )} v U where V clf : R n R is the control-lyapunov function evaluating u t = φ clf (x t ) requires solving an optimization problem at each step many tractable methods can be used to find a good V clf often works really well Spencer Schantz Lecture, Lehigh University, 12/6/10 31

Quadratic control-lyapunov policy assume polyhedral constraint set: U = {v Fv g}, g R k quadratic control-lyapunov function: V clf (z) = z T Pz evaluating u t = φ clf (x t ) reduces to solving QP minimize v T Rv +(Az +Bv) T P(Az +Bv) subject to Fv g Spencer Schantz Lecture, Lehigh University, 12/6/10 32

Control-Lyapunov policy evaluation times t clf : time to evaluate φ clf (z) t lin : linear policy φ lin (z) = Kz t kf : Kalman filter update (SDPT3 times around 1000 larger) n m k t clf (µs) t lin (µs) t kf (µs) 15 5 10 35 1 1 50 15 30 85 3 9 100 10 20 67 4 40 1000 30 60 298 130 8300 Spencer Schantz Lecture, Lehigh University, 12/6/10 33

Outline Real-time embedded convex optimization Examples Parser/solvers for convex optimization Code generation for real-time embedded convex optimization Spencer Schantz Lecture, Lehigh University, 12/6/10 34

Parser/solvers for convex optimization specify convex problem in natural form declare optimization variables form convex objective and constraints using a specific set of atoms and calculus rules (disciplined convex programming) problem is convex-by-construction easy to parse, automatically transform to standard form, solve, and transform back implemented using object-oriented methods and/or compiler-compilers huge gain in productivity (rapid prototyping, teaching, research ideas) Spencer Schantz Lecture, Lehigh University, 12/6/10 35

parser/solver written in Matlab Example: cvx convex problem, with variable x R n ; A, b, λ, F, g constants cvx specification: minimize Ax b 2 +λ x 1 subject to Fx g cvx begin variable x(n) % declare vector variable minimize (norm(a*x-b,2) + lambda*norm(x,1)) subject to F*x <= g cvx end Spencer Schantz Lecture, Lehigh University, 12/6/10 36

when cvx processes this specification, it verifies convexity of problem generates equivalent cone problem (here, an SOCP) solves it using SDPT3 or SeDuMi transforms solution back to original problem the cvx code is easy to read, understand, modify Spencer Schantz Lecture, Lehigh University, 12/6/10 37

The same example, transformed by hand transform problem to SOCP, call SeDuMi, reconstruct solution: % Set up big matrices. [m,n] = size(a); [p,n] = size(f); AA = [speye(n), -speye(n), speye(n), sparse(n,p+m+1);... F, sparse(p,2*n), speye(p), sparse(p,m+1);... A, sparse(m,2*n+p), speye(m), sparse(m,1)]; bb = [zeros(n,1); g; b]; cc = [zeros(n,1); gamma*ones(2*n,1); zeros(m+p,1); 1]; K.f = m; K.l = 2*n+p; K.q = m + 1; % specify cone xx = sedumi(aa, bb, cc, K); % solve SOCP x = x(1:n); % extract solution Spencer Schantz Lecture, Lehigh University, 12/6/10 38

Outline Real-time embedded convex optimization Examples Parser/solvers for convex optimization Code generation for real-time embedded convex optimization Spencer Schantz Lecture, Lehigh University, 12/6/10 39

General vs. embedded solvers general solver (say, for QP) handles single problem instances with any dimensions, sparsity pattern typically optimized for large problems must deliver high accuracy variable execution time: stops when tolerance achieved embedded solver solves many instances of the same problem family (dimensions, sparsity pattern) with different data solves small or smallish problems can deliver lower (application dependent) accuracy often must satisfy hard real-time deadline Spencer Schantz Lecture, Lehigh University, 12/6/10 40

(if a general solver works, use it) otherwise, develop custom code Embedded solvers by hand automatically via code generation can exploit known sparsity pattern, data ranges, required tolerance at solver code development time we ve had good results with interior-point methods; other methods (e.g., active set, first order) might work well too typical speed-up over (efficient) general solver: 100 10000 Spencer Schantz Lecture, Lehigh University, 12/6/10 41

Convex optimization solver generation specify convex problem family in natural form, via disciplined convex programming declare optimization variables, parameters form convex objective and constraints using a specific set of atoms and calculus rules code generator analyzes problem structure (dimensions, sparsity,... ) chooses elimination ordering generates solver code for specific problem family idea: spend (perhaps much) time generating code save (hopefully much) time solving problem instances Spencer Schantz Lecture, Lehigh University, 12/6/10 42

lacements Parser/solver vs. code generator Problem instance Parser/solver x Problem family description Code generator Source code Compiler Custom solver Problem instance Custom solver x Spencer Schantz Lecture, Lehigh University, 12/6/10 43

cvxgen code generator handles problems transformable to QP accepts high-level problem family description generates flat C source, auxiliary files, documentation no libraries, almost branch-free primal-dual interior-point method with iteration limit direct LDL T factorization of KKT matrix regularization and iterative refinement for extreme reliability (slow) method to determine static variable ordering explicit factorization code generated Spencer Schantz Lecture, Lehigh University, 12/6/10 44

cvxgen example specification dimensions n = 30 # assets. parameters alpha (n) # mean returns. lambda nonnegative # risk aversion. Sigma (n,n) psd # covariance. eta nonnegative # limit on total short position. variables w (n) # asset weights. maximize alpha *w - lambda*quad(w,sigma) # risk adjusted mean return. subject to sum(w) == 1 # budget constraint. sum(neg(w)) <= eta # limit on total short position. Spencer Schantz Lecture, Lehigh University, 12/6/10 45

Sample solve times for cvxgen generated code Scheduling Battery Suspension Variables 279 153 104 Constraints 465 357 165 CVX, Intel i7 4.2 s 1.3 s 2.6 s CVXGEN, Intel i7 850 µs 360 µs 110 µs CVXGEN, Atom 7.7 ms 4.0 ms 1.0 ms Spencer Schantz Lecture, Lehigh University, 12/6/10 46

Conclusions can solve convex problems on millisecond, microsecond time scales (using existing algorithms, but not using existing codes) there should be many applications parser/solvers make rapid prototyping easy new code generation methods yield solvers that are extremely fast, even competitive with analytical methods can be embedded in real-time applications Spencer Schantz Lecture, Lehigh University, 12/6/10 47

References Automatic Code Generation for Real-Time Convex Optimization (Mattingley, Boyd) Real-Time Convex Optimization in Signal Processing (Mattingley, Boyd) Code Generation for Receding Horizon Control (Mattingley, Boyd) Fast Evaluation of Quadratic Control-Lyapunov Policy (Wang, Boyd) Fast Model Predictive Control Using Online Optimization (Wang, Boyd) cvx (Grant, Boyd, Ye) cvxgen (Mattingley, Boyd) Spencer Schantz Lecture, Lehigh University, 12/6/10 48