12. qps and qcqps - laurent lessard - qps and qcqps.pdf · an expected return i and a standard...

31
CS/ECE/ISyE 524 Introduction to Optimization Spring 2017–18 12. QPs and QCQPs Ellipsoids Simple examples Convex quadratic programs Example: portfolio optimization Laurent Lessard (www.laurentlessard.com)

Upload: lehanh

Post on 09-Sep-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

CS/ECE/ISyE 524 Introduction to Optimization Spring 2017–18

12. QPs and QCQPs

� Ellipsoids

� Simple examples

� Convex quadratic programs

� Example: portfolio optimization

Laurent Lessard (www.laurentlessard.com)

Page 2: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Ellipsoids

� For linear constraints, the set of x satisfying cTx = b is ahyperplane and the set cTx ≤ b is a halfspace.

� For quadratic constraints, the set of x satisfying xTQx ≤ bis an ellipsoid if Q � 0.

� If Q � 0, then xTQx ≤ b ⇐⇒ ‖Q1/2x‖2 ≤ b.

12-2

Page 3: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Degenerate ellipsoids

Ellipsoid axes have length 1√λi

. When an eigenvalue is close tozero, contours are stretched in that direction.

-1.0 -0.5 0.5 1.0

-1.0

-0.5

0.5

1.0

x2 + y 2

-1.0 -0.5 0.5 1.0

-1.0

-0.5

0.5

1.0

110x2 + y 2

-1.0 -0.5 0.5 1.0

-1.0

-0.5

0.5

1.0

1100

x2 + y 2

� Warmer colors = larger values

� If λi = 0, then Q � 0. The ellipsoid xTQx ≤ 1 isdegenerate (stretches out to infinity in direction ui).

12-3

Page 4: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Ellipsoids with linear terms

If Q � 0, then the quadratic form with extra affine terms:

xTQx + rTx + s

is a shifted ellipsoid. To see why, complete the square!If they were scalars, we would have:

qx2 + rx + s = q

(x +

r

2q

)2

+

(s − r 2

4q

)In the matrix case, we have:

xTQx+rTx+s =(x + 1

2Q−1r

)TQ(x + 1

2Q−1r

)+(s − 1

4rTQ−1r

)12-4

Page 5: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Ellipsoids with linear terms

Therefore, the equation xTQx + rTx + s ≤ b is equivalent to:(x + 1

2Q−1r

)TQ(x + 1

2Q−1r

)≤(b − s + 1

4rTQ−1r

)This is an ellipse centered at −1

2Q−1r with shifted contours!

Writing this using the matrix square root, we have:∥∥Q1/2x + 12Q−1/2r

∥∥2 ≤ (b − s + 14rTQ−1r

)

12-5

Page 6: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Norm constraints

Constraints of the form ‖Ax − b‖2 ≤ care (possibly degenerate) ellipsoids.

Proof: When we expand the square, we get the quadraticxTATAx − 2bTAx + bTb. But notice that:

xTATAx = ‖Ax‖2 ≥ 0

Therefore, ATA � 0, so we must have an ellipsoid. In the casewhere ATA is invertible (A is tall with linearly independentcolumns), the ellipsoid will be non-degenerate.

12-6

Page 7: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example 1: feasible affine subspace

minimizex

‖x‖2

subject to: 12x1 + x2 = 2

x

-1 1 2 3 4-0.5

0.5

1.0

1.5

2.0

2.5

12-7

Page 8: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example 1: feasible affine subspace

minimizex

∥∥12x1 + x2 − 2

∥∥2 + λ‖x‖2

-1 1 2 3 4-0.5

0.5

1.0

1.5

2.0

2.5

12-8

Page 9: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example 2: feasible single point

minimizex

‖x‖2

subject to: 12x1 + x2 = 2

x1 − 2x2 = 0

x

-1 1 2 3 4-0.5

0.5

1.0

1.5

2.0

2.5

12-9

Page 10: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example 2: feasible single point

minimizex

∥∥∥∥[12

11 −2

]x −

[20

]∥∥∥∥2 + λ‖x‖2

-1 1 2 3 4-0.5

0.5

1.0

1.5

2.0

2.5

12-10

Page 11: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Quadratic programs

Quadratic program (QP) is like an LP, but with quadratic cost:

minimizex

xTPx + qTx + r

subject to: Ax ≤ b

� If P � 0, it is a convex QP

I feasible set is a polyhedron

I solution can be on boundary or in the interior

I relatively easy to solve

� If P � 0, it is very hard to solve in general.

12-11

Page 12: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Quadratic programs

minimizex

xTPx + qTx + r

subject to: Ax ≤ b

0.5 1.0 1.5 2.0

0.5

1.0

1.5First case:If the ellipsoid center isfeasible, then it is alsothe optimal point.

12-12

Page 13: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Quadratic programs

minimizex

xTPx + qTx + r

subject to: Ax ≤ b

0.5 1.0 1.5 2.0

0.5

1.0

1.5 Second case:If the ellipsoid center isinfeasible, optimal pointis on the boundary.(not always at a vertex!)

12-13

Page 14: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

QCQPs

Quadratically constrained quadratic program (QCQP) hasboth a quadratic cost and quadratic constraints:

minimizex

xTP0x + qT0 x + r0

subject to: xTPix + qTi x + ri ≤ 0 for i = 1, . . . ,m

� If Pi � 0 for i = 0, 1, . . . ,m, it is a convex QCQP

I feasible set is convex

I solution can be on boundary or in the interior

I relatively easy to solve

� If any Pi � 0, the QCQP becomes very hard to solve.

12-14

Page 15: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

QCQPs

minimizex

xTP0x + qT0 x + r0

subject to: xTPix + qTi x + ri ≤ 0 for i = 1, . . . ,m

0.5 1.0 1.5 2.0

0.5

1.0

1.5

The feasible set is theintersection of multipleellipsoids.

12-15

Page 16: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

QCQPs

minimizex

xTP0x + qT0 x + r0

subject to: xTPix + qTi x + ri ≤ 0 for i = 1, . . . ,m

0.5 1.0 1.5 2.0

0.5

1.0

1.5First case:If the ellipsoid center isfeasible, then it is alsothe optimal point.

12-16

Page 17: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

QCQPs

minimizex

xTP0x + qT0 x + r0

subject to: xTPix + qTi x + ri ≤ 0 for i = 1, . . . ,m

0.5 1.0 1.5 2.0

0.5

1.0

1.5 Second case:If the ellipsoid center isinfeasible, optimal pointis on the boundary.(not always at a vertex!)

12-17

Page 18: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Difficult quadratic constraints

The following types of quadratic constraints make a problemnonconvex and generally difficult to solve (but not always).

Indefinite quadratic constraints.

� Example: x2 + 2y 2 − z2 ≤ 1corresponds to the nonconvexregion on the right.

� Note: be mindful of ≤ vs ≥ !e.g. x2 + y 2 ≥ 1 is nonconvex.

Quadratic equalities.

� Using quadratic equalities, you can encode booleanconstraints. Example: x2 = 1 is equivalent to x ∈ {−1, 1}.

12-18

Page 19: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Where do quadratics commonly occur?

1. As a regularization or penalty termI (cost) + λ‖x‖2 : standard L2 regularizer

I (cost) + λ xTQ x (with Q � 0) : weighted L2 regularizer

2. Hard norm bounds on a decision variableI ‖x‖2 ≤ r : a way to ensure that x doesn’t get too big.

3. Allowing some tolerance in constraint satisfactionI ‖Ax − b‖2 ≤ e : we allow a tolerance e.

4. Energy quantities (physics/mechanics)I examples: 1

2mv2,(kinetic)

12kx

2,(spring)

12CV

2,(capacitor)

12 Iω

2,(rotational)

12VEε

2.(strain)

5. Covariance constraints (statistics)

12-19

Page 20: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimizationWe must decide how to invest our money, and we can choosebetween i = 1, 2, . . . ,N different assets.

� Each asset can be modeled as a random variable (RV) withan expected return µi and a standard deviation σi .

� Standard deviation is a measure of uncertainty.

12-20

Page 21: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

If Z is the RV representing an asset:

� The expected return is µ = E(Z ) (expected value)

� The variance is var(Z ) = σ2 = E ((Z − µ)2)

� The standard deviation is the square root of the variance.

� Sometimes write Z ∼ (µ, σ2) for short.

If Z1 ∼ (µ1, σ21) and Z2 ∼ (µ2, σ

22) are two RVs

� The covariance is cov(Z1,Z2) = E ((Z1 − µ1)(Z2 − µ2)).

� Note that: var(Z ) = cov(Z ,Z )

� covariance measures tendency of RVs to move together.

12-21

Page 22: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

If Z1 ∼ (µ1, σ21) and Z2 ∼ (µ2, σ

22), what is x1Z1 + x2Z2?

Calculating the mean:

E(x1Z1 + x2Z2) = x1µ1 + x2µ2

=

[x1x2

]T [µ1

µ2

]Calculating the variance:

var(x1Z1 + x2Z2) = E (x1(Z1 − µ1) + x2(Z2 − µ2))2

= x21 var(Z1) + 2x1x2 cov(Z1,Z2) + x22 var(Z2)

=

[x1x2

]T [cov(Z1,Z1) cov(Z1,Z2)cov(Z2,Z1) cov(Z2,Z2)

] [x1x2

]12-22

Page 23: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

If Z1, . . . ,Zn are jointly distributed with:

� mean µ =

E(Z1)...

E(Zn)

� covariance matrix Σ =

cov(Z1,Z1) . . . cov(Z1,Zn)...

. . ....

cov(Zn,Z1) . . . cov(Zn,Zn)

� short form: Z ∼ (µ,Σ).

n∑i=1

xiZi ∼(xTµ , xTΣx

)12-23

Page 24: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

-1.0 -0.5 0.5 1.0Z1

-1.0

-0.5

0.5

1.0Z2

uncorrelated

Σ =

[1 00 1

]

-1.0 -0.5 0.5 1.0Z1

-1.0

-0.5

0.5

1.0Z2

somewhat correlated

Σ =

[1 .5.5 1

]

-1.0 -0.5 0.5 1.0Z1

-1.0

-0.5

0.5

1.0Z2

highly correlated

Σ =

[1 .99.99 1

]

Correlation is modeled by a confidence ellipsoid

12-24

Page 25: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

Example:

� There are 16 different stocks: Z1, . . . ,Z16. Each hasexpected return of 2% with standard deviation of 5%.You have $100 in total to invest.

� If you invest in just one of them, you will earn $102± $5.

� If the stocks are all correlated (e.g. all the same industry)and you invest evenly in all stocks, you still earn: $102± $5.

� If the stocks are uncorrelated (e.g. very diverse) and youinvest evenly in all stocks, the new variance is 16× ( 5

16)2.

Therefore, you will earn $102± $1.25.

Julia code: Portfolio.ipynb

12-25

Page 26: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

Dataset containing 225 assets. How should we invest?

� We know the expected return µi for each asset

� We know the covariance Σij for each pair of assets

0 50 100 150 2002

3

4

5

6

7

8

Sta

ndard

devia

tion (

%)

Standard deviation and expected return of all 225 assets

0 50 100 150 2001.0

0.8

0.6

0.4

0.2

0.0

0.2

0.4

Expect

ed r

etu

rn (

%)

12-26

Page 27: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

Dataset containing 225 assets. How should we invest?

� We know the expected return µi for each asset

� We know the covariance Σij for each pair of assets

0 50 100 150 200

0

50

100

150

200

Correlation matrix for 225 assets

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1.0

12-27

Page 28: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

Suppose we buy xi of asset Zi . We want:

� A high total return. Maximize xTµ.

� Low variance (risk). Minimize xTΣx .

Pose the optimization problem as a tradeoff:

minimizex

− xTµ + λxTΣx

subject to: x1 + · · ·+ x225 = 1

xi ≥ 0

Fun fact: This is the basic idea behind “Modern portfoliotheory”. Introduced by economist Harry Markowitz in 1952,for which he was later awarded the Nobel Prize.

12-28

Page 29: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

Quality of each individual asset:

2 3 4 5 6 7 8std deviation (%)

1.0

0.8

0.6

0.4

0.2

0.0

0.2

0.4

expect

ed r

etu

rn (

%)

12-29

Page 30: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

Some solutions:

0 50 100 150 2000.00

0.05

0.10

0.15

0.20Optimal asset selection for λ=1 ( µ=0.027%, σ=1.75% )

0 50 100 150 2000.00

0.05

0.10

0.15

0.20

0.25

0.30

0.35

0.40Optimal asset selection for λ=3×10−2 ( µ=0.342%, σ=2.45% )

12-30

Page 31: 12. QPs and QCQPs - Laurent Lessard - QPs and QCQPs.pdf · an expected return i and a standard deviation ... Each has expected return of 2% with standard deviation of 5%. ... If you

Example: portfolio optimization

Pareto curve (“efficient front”)

1.5 2.0 2.5 3.0 3.5 4.0 4.5std deviation (%)

0.00

0.05

0.10

0.15

0.20

0.25

0.30

0.35

0.40

expect

ed r

etu

rn (

%)

12-31