+ All Categories
Home > Technology > Convex Optimization Modelling with CVXOPT

Convex Optimization Modelling with CVXOPT

Date post: 05-Dec-2014
Category:
Upload: andrewmart11
View: 849 times
Download: 7 times
Share this document with a friend
Description:
An introduction to convex optimization modelling using cvxopt in an IPython environment. The facility location problem is used as an example to demonstrate modelling in cvxopt.
Popular Tags:
42

Click here to load reader

Transcript
Page 1: Convex Optimization Modelling with CVXOPT

CVXOPT:

A Python Based Convex Optimization Suite

11 May 2012 Industrial Engineering Seminar

Andrew B. Martin

Page 2: Convex Optimization Modelling with CVXOPT

Easy and Hard

• Easy Problems - efficient and reliable solution algorithms exist

• Once distinction was between Linear/Nonlinear, now Convex/Nonconvex

2

Page 3: Convex Optimization Modelling with CVXOPT

Outline

• What is CVXOPT?

• How does CVXOPT solve problems?

• What are some interesting applications of CVXOPT?

3

Page 4: Convex Optimization Modelling with CVXOPT

Convex Sets

• For any x,y belonging to the set C, the chord connecting x and y is contained within C.

4

Page 5: Convex Optimization Modelling with CVXOPT

Convex Functions

• A real valued function mapping a set X to R where X is a convex set and for any x, y belonging to X

5

10

)()1()())1((

t

yftxtfyttxf

Page 6: Convex Optimization Modelling with CVXOPT

Convex Programming

pibxa

mixftosubject

xfMinimize

iTi

i

,...,1

,...,1 0)(

)( 0

• Convex objective

• Convex inequality constraint functions

• Affine equality constraint functions 6

Page 7: Convex Optimization Modelling with CVXOPT

Linear Programming

• Supply Chain Modeling (Forestry)

7

Page 8: Convex Optimization Modelling with CVXOPT

Quadratic Programming

• Least Squares and Constrained Least Squares

• Quantitative Finance

8

Page 9: Convex Optimization Modelling with CVXOPT

Second Order Cone Programming

• Robust Linear Programming• Truss design, robotic grasping force, antenna

design

9

Page 10: Convex Optimization Modelling with CVXOPT

Example: Robust LP

mibxPxatosubject

xcMinimize

xPxaaxa

baxa

PuuPaE

miabxatosubject

xcMinimize

iTi

T

T

Ti

T

iiiTi

iiiTi

nxniiii

iiiTi

T

,...,1

}|sup{

}|sup{

}1|{

,...,1

2

_

2

_

2

_

10

Page 11: Convex Optimization Modelling with CVXOPT

Semidefinite Programming

• Structural optimization, experiment design

11

Page 12: Convex Optimization Modelling with CVXOPT

Geometric Programming

• Posynomial objective and inequality constraint functions.

• Monomial equality constraint functions

mjxh

nixftoSubject

xfMinimize

j

i

,...,1 1)(

,...,1 1)(

)( 0

12

Page 13: Convex Optimization Modelling with CVXOPT

Globally Optimal Points

• Any locally optimal point is globally optimal!

• No concern of getting stuck at suboptimal minimums.

Page 14: Convex Optimization Modelling with CVXOPT

Overview CVXOPT

• Created by L. Vandenberghe and J. Dahl of UCLA

• Extends pythons standard libraries– Objects matrix and spmatrix

• Defines new modules e.g. BLAS, LAPACK, modeling and solvers

14

Page 15: Convex Optimization Modelling with CVXOPT

cvxopt.solvers

• Cone solvers: conelp, coneqp

• Smooth nonlinear solvers: cp, cpl

• Geometric Program solver: gp

• Customizable: kktsolver

15

Page 16: Convex Optimization Modelling with CVXOPT

Cone Programs

• s belongs to C, the Cartesian product of a nonnegative orthant, a number of second order cones and a number of positive semidefinite cones

16

Page 17: Convex Optimization Modelling with CVXOPT

Cone Solvers

• Apply Primal-Dual Path following Interior Point algorithms with Nesterov-Todd Scaling to the previous problem

• Specify cone dimension with variable dims

• Separate QP and LP solvers17

Page 18: Convex Optimization Modelling with CVXOPT

solvers.coneqp

• coneqp(P, q, G, h, A, b, dims, kktsolver)

• Linearize Central Path Equations (Newton Equations)• Solving these is the most expensive step

• Transform N.E. into KKT system

18

Page 19: Convex Optimization Modelling with CVXOPT

solvers.coneqp

)( ,0),( ,

00

000

0

sgzzs

h

b

c

z

y

x

G

A

GAP

s

TT

c

b

a

z

y

x

WWG

A

GAP

T

TT

0

00

Central Path Equations

Newton Equations

19

Page 20: Convex Optimization Modelling with CVXOPT

solvers.coneqp

cW

b

a

Wz

y

x

IGW

A

WGAP

TT

TT

0

00

1

KKT System

20

Page 21: Convex Optimization Modelling with CVXOPT

Constrained Regression

21

Page 22: Convex Optimization Modelling with CVXOPT

>>> from cvxopt import matrix, solvers

>>> A = matrix([ [ .3, -.4, -.2, -.4, 1.3 ], [ .6, 1.2, -1.7, .3, -.3 ], /

[-.3, .0, .6, -1.2, -2.0 ] ])

>>> b = matrix([ 1.5, .0, -1.2, -.7, .0])

>>> m, n = A.size

>>> I = matrix(0.0, (n,n))

>>> I[::n+1] = 1.0

>>> G = matrix([-I, matrix(0.0, (1,n)), I])

>>> h = matrix(n*[0.0] + [1.0] + n*[0.0])

>>> dims = {'l': n, 'q': [n+1], 's': []}

>>> x = solvers.coneqp(A.T*A, -A.T*b, G, h, dims)['x']

>>> print(x)

[ 7.26e-01]

[ 6.18e-01]

[ 3.03e-01] 22

Page 23: Convex Optimization Modelling with CVXOPT

solvers.conelp

• Coneqp demands strict primal-dual feasibility. Conelp can detect infeasibility.

• Embeds primal and dual LPs into one LP

• Algorithm similar to coneqp except two QR factorizations used to solve KKT System

23

Page 24: Convex Optimization Modelling with CVXOPT

solvers.conelp

0),,,( ,

0

00

00

0

0

0

0

zsz

y

x

hbc

hG

bA

CGA

s

Minimize

TTT

TT

Self-dual Cone LP

24

Page 25: Convex Optimization Modelling with CVXOPT

dims = {'l': 2, 'q': [4, 4], 's': [3]}

25

Page 26: Convex Optimization Modelling with CVXOPT

Nonlinear Solvers

• Solvers.cpl for linear objective problems• User specifies F function to evaluate

gradients and hessian of constraints• Solvers.cpl(F, G, h, A, b, kktsolver)

26

Page 27: Convex Optimization Modelling with CVXOPT

solvers.cpl

TTm

m

kkk

z

y

x

z

y

x

T

TT

GxfxfGxfzH

b

b

b

u

u

u

WWG

A

GAH

] )( ... )([ ),(

,

0

00

1

~

0

2

~

~

KKT System

27

Page 28: Convex Optimization Modelling with CVXOPT

solvers.cp

• For problems with a nonlinear objective function

• Problem transformed into epigraph form and solvers.cpl algorithm applied

28

Page 29: Convex Optimization Modelling with CVXOPT

solvers.cp

]x'(F)['solvers.cpreturn

H Df, f,return

A * 3))-**(w*rho*]spdiag(z[0 * A.T = H

Df f,return :None is z if

A * w).Tdiv(y, = Df

sum(w) = f

*2)*y + sqrt(rho = w

b-x*A =y

(n,1)) ,matrix(0.0 0,return :None is x if

:None)=z None,=F(x def

A.size =n m,

:rho) b, robls(A, def

div sqrt, spdiag, matrix, solvers,import cvxopt from

Robust Least Squares

2

m

1k

)(

)

uuwhere

((Ax-b)Minimize k

29

Page 30: Convex Optimization Modelling with CVXOPT

Geometric Solver

• GP transformed to equivalent convex form and solvers.cp is applied

• Solvers.gp(F, G, h, A, b)

30

Page 31: Convex Optimization Modelling with CVXOPT

Exploiting Structure

• None of the previously mentioned solvers take advantage of problem structure

• User specified kktsolvers and python functions allow for customization

• Potential for better than commercial software performance

31

Page 32: Convex Optimization Modelling with CVXOPT

Exploiting Structure

M N CVXOPT CVXOPT/BLAS MOSEK 1.15 MOSEK 1.17

500 100 0.12 0.06 0.75 0.40

1000 100 0.22 0.11 1.53 0.81

1000 200 0.52 0.25 1.95 1.06

2000 200 1.23 0.60 3.87 2.19

1000 500 2.44 1.32 3.63 2.38

2000 500 5.00 2.68 7.44 5.11

2000 1000 17.1 9.52 32.4 12.8

• L1-norm approximation solution times for six randomly generated problems of dimension mxn (ref)

32

Page 33: Convex Optimization Modelling with CVXOPT

Interlude: iPython

• Interactive Programming Environment

• explore algorithms, and perform data analysis and visualization.

• It facilitates experimentation - new ideas can be tested on the fly

33

Page 34: Convex Optimization Modelling with CVXOPT

iPython - Features

• Magic Commands - e.g. %run

• Detailed Exception Traceback

• OS Shell Commands

• Extensive GUI support34

Page 35: Convex Optimization Modelling with CVXOPT

Facility Layout Problem

• As Nonlinearly Constrained Program

• As Geometric Program

• As Quadratic Program

35

Page 36: Convex Optimization Modelling with CVXOPT

Nonlinearly Constrained Facility Layout Problem

kk

kk

jkk

k

jk

kk

hw

Hhy

yhy

Ww

xw

AreahwtoSubject

HWMinimize

//1

x

x

k

k

min

36

Page 37: Convex Optimization Modelling with CVXOPT

200 Modules

Page 38: Convex Optimization Modelling with CVXOPT

Geometric Program

1

11min

11

11

11

11

*/1

1**

1**

1**

1**

1**

*

jj

jj

jj

ijij

jj

ijij

hw

hwArea

HhHy

yhyy

WwWx

xwxxtoSubject

HWMinimize

38

Page 39: Convex Optimization Modelling with CVXOPT

Quadratic Program

jj

j

j

jj

ijj

jj

ijj

i j ji

jiji

hw

Areah

Areaw

Hhy

yhy

Wwx

xwxtosubject

HWyy

xxflowMinimize

//1

)(*

min

min

2

2

,

39

Page 40: Convex Optimization Modelling with CVXOPT

65 Modules

Page 41: Convex Optimization Modelling with CVXOPT

Closing

• CVXOPT: Software for Convex Optimization

• How will you use it?

[email protected]

41

Page 42: Convex Optimization Modelling with CVXOPT

References

42


Recommended