stephen boyd steven diamond enzo busseti akshay agrawal...

50
Convex Optimization Overview Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal Junzi Zhang EE & CS Departments Stanford University 1

Upload: others

Post on 26-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Convex Optimization Overview

Stephen Boyd Steven Diamond Enzo BussetiAkshay Agrawal Junzi Zhang

EE & CS Departments

Stanford University

1

Page 2: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Outline

Mathematical Optimization

Convex Optimization

Solvers & Modeling Languages

Examples

Summary

2

Page 3: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Outline

Mathematical Optimization

Convex Optimization

Solvers & Modeling Languages

Examples

Summary

Mathematical Optimization 3

Page 4: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Optimization problem

minimize f0(x)subject to fi (x) ≤ 0, i = 1, . . . ,m

gi (x) = 0, i = 1, . . . , p

I x ∈ Rn is (vector) variable to be chosen

I f0 is the objective function, to be minimized

I f1, . . . , fm are the inequality constraint functions

I g1, . . . , gp are the equality constraint functions

I variations: maximize objective, multiple objectives, . . .

Mathematical Optimization 4

Page 5: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Finding good (or best) actions

I x represents some action, e.g.,I trades in a portfolioI airplane control surface deflectionsI schedule or assignmentI resource allocationI transmitted signal

I constraints limit actions or impose conditions on outcomeI the smaller the objective f0(x), the better

I total cost (or negative profit)I deviation from desired or target outcomeI fuel useI risk

Mathematical Optimization 5

Page 6: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Engineering design

I x represents a design (of a circuit, device, structure, . . . )I constraints come from

I manufacturing processI performance requirements

I objective f0(x) is combination of cost, weight, power, . . .

Mathematical Optimization 6

Page 7: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Finding good models

I x represents the parameters in a model

I constraints impose requirements on model parameters(e.g., nonnegativity)

I objective f0(x) is the prediction error on some observed data(and possibly a term that penalizes model complexity)

Mathematical Optimization 7

Page 8: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Inversion

I x is something we want to estimate/reconstruct, givensome measurement y

I constraints come from prior knowledge about x

I objective f0(x) measures deviation between predicted andactual measurements

Mathematical Optimization 8

Page 9: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Worst-case analysis (pessimization)

I variables are actions or parameters out of our control(and possibly under the control of an adversary)

I constraints limit the possible values of the parameters

I minimizing −f0(x) finds worst possible parameter values

I if the worst possible value of f0(x) is tolerable, you’re OK

I it’s good to know what the worst possible scenario can be

Mathematical Optimization 9

Page 10: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Optimization-based models

I model an entity as taking actions that solve an optimizationproblem

I an individual makes choices that maximize expected utilityI an organism acts to maximize its reproductive successI reaction rates in a cell maximize growthI currents in an electric circuit minimize total power

I (except the last) these are very crude models

I and yet, they often work very well

Mathematical Optimization 10

Page 11: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Optimization-based models

I model an entity as taking actions that solve an optimizationproblem

I an individual makes choices that maximize expected utilityI an organism acts to maximize its reproductive successI reaction rates in a cell maximize growthI currents in an electric circuit minimize total power

I (except the last) these are very crude models

I and yet, they often work very well

Mathematical Optimization 10

Page 12: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Summary

I summary: optimization arises everywhere

I the bad news: most optimization problems are intractablei.e., we cannot solve them

I an exception: convex optimization problems are tractablei.e., we (generally) can solve them

Mathematical Optimization 11

Page 13: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Summary

I summary: optimization arises everywhere

I the bad news: most optimization problems are intractablei.e., we cannot solve them

I an exception: convex optimization problems are tractablei.e., we (generally) can solve them

Mathematical Optimization 11

Page 14: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Summary

I summary: optimization arises everywhere

I the bad news: most optimization problems are intractablei.e., we cannot solve them

I an exception: convex optimization problems are tractablei.e., we (generally) can solve them

Mathematical Optimization 11

Page 15: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Outline

Mathematical Optimization

Convex Optimization

Solvers & Modeling Languages

Examples

Summary

Convex Optimization 12

Page 16: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Convex optimization problem

convex optimization problem:

minimize f0(x)subject to fi (x) ≤ 0, i = 1, . . . ,m

Ax = b

I variable x ∈ Rn

I equality constraints are linear

I f0, . . . , fm are convex: for θ ∈ [0, 1],

fi (θx + (1− θ)y) ≤ θfi (x) + (1− θ)fi (y)

i.e., fi have nonnegative (upward) curvature

Convex Optimization 13

Page 17: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Why

I beautiful, nearly complete theoryI duality, optimality conditions, . . .

I effective algorithms, methods (in theory and practice)I get global solution (and optimality certificate)I polynomial complexity

I conceptual unification of many methods

I lots of applications (many more than previously thought)

Convex Optimization 14

Page 18: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Why

I beautiful, nearly complete theoryI duality, optimality conditions, . . .

I effective algorithms, methods (in theory and practice)I get global solution (and optimality certificate)I polynomial complexity

I conceptual unification of many methods

I lots of applications (many more than previously thought)

Convex Optimization 14

Page 19: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Why

I beautiful, nearly complete theoryI duality, optimality conditions, . . .

I effective algorithms, methods (in theory and practice)I get global solution (and optimality certificate)I polynomial complexity

I conceptual unification of many methods

I lots of applications (many more than previously thought)

Convex Optimization 14

Page 20: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Why

I beautiful, nearly complete theoryI duality, optimality conditions, . . .

I effective algorithms, methods (in theory and practice)I get global solution (and optimality certificate)I polynomial complexity

I conceptual unification of many methods

I lots of applications (many more than previously thought)

Convex Optimization 14

Page 21: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Application areas

I machine learning, statistics

I finance

I supply chain, revenue management, advertising

I control

I signal and image processing, vision

I networking

I circuit design

I combinatorial optimization

I quantum mechanics

I flux-based analysis

Convex Optimization 15

Page 22: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

The approach

I try to formulate your optimization problem as convexI if you succeed, you can (usually) solve it (numerically)

I using generic software if your problem is not really bigI by developing your own software otherwise

I some tricks:I change of variablesI approximation of true objective, constraintsI relaxation: ignore terms or constraints you can’t handle

Convex Optimization 16

Page 23: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

The approach

I try to formulate your optimization problem as convexI if you succeed, you can (usually) solve it (numerically)

I using generic software if your problem is not really bigI by developing your own software otherwise

I some tricks:I change of variablesI approximation of true objective, constraintsI relaxation: ignore terms or constraints you can’t handle

Convex Optimization 16

Page 24: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Outline

Mathematical Optimization

Convex Optimization

Solvers & Modeling Languages

Examples

Summary

Solvers & Modeling Languages 17

Page 25: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Medium-scale solvers

I 1000s–10000s variables, constraints

I reliably solved by interior-point methods on single machine(especially for problems in standard cone form)

I exploit problem sparsity

I not quite a technology, but getting there

I used in control, finance, engineering design, . . .

Solvers & Modeling Languages 18

Page 26: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Large-scale solvers

I 100k – 1B variables, constraintsI solved using custom (often problem specific) methods

I limited memory BFGSI stochastic subgradientI block coordinate descentI operator splitting methods

I require custom implementation, tuning for each problem

I used in machine learning, image processing, . . .

Solvers & Modeling Languages 19

Page 27: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Modeling languages

I (new) high level language support for convex optimizationI describe problem in high level languageI description automatically transformed to a standard formI solved by standard solver, transformed back to original form

I implementations:I YALMIP, CVX (Matlab)I CVXPY (Python)I Convex.jl (Julia)I CVXR (R)

Solvers & Modeling Languages 20

Page 28: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

CVX

(Grant & Boyd, 2005)

cvx_begin

variable x(n) % declare vector variable

minimize sum(square(A*x-b)) + gamma*norm(x,1)

subject to norm(x,inf) <= 1

cvx_end

I A, b, gamma are constants (gamma nonnegative)I after cvx_end

I problem is converted to standard form and solvedI variable x is over-written with (numerical) solution

Solvers & Modeling Languages 21

Page 29: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

CVXPY

(Diamond & Boyd, 2013); (Agrawal et al., 2018)

import cvxpy as cp

x = cp.Variable(n)

cost = cp.sum_squares(A*x-b) + gamma*cp.norm(x,1)

prob = cp.Problem(cp.Minimize(cost),

[cp.norm(x,"inf") <= 1])

opt_val = prob.solve()

solution = x.value

I A, b, gamma are constants (gamma nonnegative)

I solve method converts problem to standard form, solves,assigns value attributes

Solvers & Modeling Languages 22

Page 30: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Convex.jl

(Udell et al., 2014)

using Convex

x = Variable(n);

cost = sum_squares(A*x-b) + gamma*norm(x,1);

prob = minimize(cost, [norm(x,Inf) <= 1]);

opt_val = solve!(prob);

solution = x.value;

I A, b, gamma are constants (gamma nonnegative)

I solve! method converts problem to standard form, solves,assigns value attributes

Solvers & Modeling Languages 23

Page 31: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Modeling languages

I enable rapid prototyping (for small and medium problems)

I ideal for teaching (can do a lot with short scripts)

I slower than custom methods, but often not much

I current work focuses on extension to large problems

Solvers & Modeling Languages 24

Page 32: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Outline

Mathematical Optimization

Convex Optimization

Solvers & Modeling Languages

Examples

Summary

Examples 25

Page 33: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Radiation treatment planning

I radiation beams with intensities xj ≥ 0 directed at patient

I radiation dose yi received in voxel i

I y = Ax

I A ∈ Rm×n comes from beam geometry, physicsI goal is to choose x to deliver prescribed radiation dose di

I di = 0 for non-tumor voxelsI di > 0 for tumor voxels

I y = d not possible, so we’ll need to compromise

I typical problem has n = 103 beams, m = 106 voxels

Examples 26

Page 34: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Radiation treatment planning via convex optimization

minimize∑

i fi (yi )subject to x ≥ 0, y = Ax

I variables x ∈ Rn, y ∈ Rm

I objective terms are

fi (yi ) = woveri (yi − di )+ + wunder

i (di − yi )+

I woveri and wunder

i are positive weights

I i.e., we charge linearly for over- and under-dosing

I a convex problem

Examples 27

Page 35: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

I real patient case with n = 360 beams, m = 360000 voxelsI optimization-based plan essentially the same as plan used

I but we computed the plan in a few seconds on a GPUI original plan took hours of least-squares weight tweaking

Examples 28

Page 36: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

I real patient case with n = 360 beams, m = 360000 voxelsI optimization-based plan essentially the same as plan used

I but we computed the plan in a few seconds on a GPUI original plan took hours of least-squares weight tweaking

Examples 28

Page 37: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Image in-painting

I guess pixel values in obscured/corrupted parts of image

I total variation in-painting: choose pixel values xij ∈ R3 tominimize total variation

TV(x) =∑i ,j

∥∥∥∥[ xi+1,j − xijxi ,j+1 − xij

]∥∥∥∥2

I a convex problem

Examples 29

Page 38: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

512× 512 grayscale image (n ≈ 300000 variables)

Examples 30

Page 39: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

Examples 31

Page 40: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

512× 512 color image (n ≈ 800000), 80% of pixels removed

Examples 32

Page 41: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

80% of pixels removed

Examples 33

Page 42: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Control

minimize∑T−1

t=0 `(xt , ut) + `T (xT )subject to xt+1 = Axt + But

(xt , ut) ∈ C, xT ∈ CT

I variables areI system states x1, . . . , xT ∈ Rn

I inputs or actions u0, . . . , uT−1 ∈ Rm

I ` is stage cost, `T is terminal cost

I C is state/action constraints; CT is terminal constraint

I convex problem when costs, constraints are convex

I applications in many fields

Examples 34

Page 43: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

I n = 8 states, m = 2 inputs, horizon T = 50

I randomly chosen A, B (with A ≈ I )

I input constraint ‖ut‖∞ ≤ 1

I terminal constraint xT = 0 (‘regulator’)

I `(x , u) = ‖x‖22 + ‖u‖22 (traditional)

I random initial state x0

Examples 35

Page 44: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

Examples 36

Page 45: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Support vector machine classifier with `1-regularization

I given data (xi , yi ), i = 1, . . . ,mI xi ∈ Rn are feature vectorsI y ∈ {±1} are associated boolean outcomes

I linear classifier y = sign(βT x − v)

I find parameters β, v by minimizing (convex function)

(1/m)∑i

(1− yi (β

T xi − v))+

+ λ‖β‖1

I first term is average hinge lossI second term shrinks coefficients in β and encourages sparsityI λ ≥ 0 is (regularization) parameter

I simultaneously selects features and fits classifier

Examples 37

Page 46: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

I n = 20 featuresI trained and tested on m = 1000 examples each

Examples 38

Page 47: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Example

βi vs. λ (regularization path)

Examples 39

Page 48: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Outline

Mathematical Optimization

Convex Optimization

Solvers & Modeling Languages

Examples

Summary

Summary 40

Page 49: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Summary

I convex optimization problems arise in many applications

I convex optimization problems can be solved effectivelyI using generic methods for not huge problemsI by developing custom methods for huge problems

I high level language support(CVX/CVXPY/Convex.jl/CVXR) makes prototyping easy

Summary 41

Page 50: Stephen Boyd Steven Diamond Enzo Busseti Akshay Agrawal ...boyd/papers/pdf/cvx_opt_intro.pdfOptimization-based models I model an entity as taking actions that solve an optimization

Resources

many researchers have worked on the topics covered

I Convex Optimization (book)

I EE364a (course slides, videos, code, homework, . . . )

I software CVX, CVXPY, Convex.jl, CVXR

all available online

Summary 42