disciplined convex optimization with cvxranqif/presentations/user18...convex optimization minimize f...

25
Disciplined Convex Optimization with CVXR Anqi Fu Bala Narasimhan Stephen Boyd EE & Statistics Departments Stanford University useR! Conference 2018 1

Upload: others

Post on 01-Apr-2021

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Disciplined Convex Optimization with CVXR

Anqi Fu Bala Narasimhan Stephen Boyd

EE & Statistics DepartmentsStanford University

useR! Conference 2018

1

Page 2: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Convex Optimization

CVXR

Examples

Future Work

2

Page 3: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Outline

Convex Optimization

CVXR

Examples

Future Work

Convex Optimization 3

Page 4: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Convex Optimization

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

Ax = b

with variable x ∈ Rn

I Objective and inequality constraints f0, . . . , fM are convexI Equality constraints are linear

Why?

I We can solve convex optimization problemsI There are many applications in many fields, including

machine learning and statistics

Convex Optimization 4

Page 5: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Convex Optimization

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

Ax = b

with variable x ∈ Rn

I Objective and inequality constraints f0, . . . , fM are convexI Equality constraints are linear

Why?

I We can solve convex optimization problemsI There are many applications in many fields, including

machine learning and statistics

Convex Optimization 4

Page 6: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Convex Problems in Statistics

I Least squares, nonnegative least squaresI Ridge and lasso regressionI Isotonic regressionI Huber (robust) regressionI Logistic regressionI Support vector machineI Sparse inverse covarianceI Maximum entropy and related problemsI . . . and new methods being invented every year!

Convex Optimization 5

Page 7: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Domain Specific Languages for Convex Optimization

I Special languages/packages for general convex optimizationI CVX, CVXPY, YALMIP, Convex.jlI Slower than custom code, but extremely flexible and

enables fast prototyping

from cvxpy import *beta = Variable(n)cost = norm(X * beta - y)prob = Problem(Minimize(cost))prob.solve()beta.value

Convex Optimization 6

Page 8: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Domain Specific Languages for Convex Optimization

I Special languages/packages for general convex optimizationI CVX, CVXPY, YALMIP, Convex.jlI Slower than custom code, but extremely flexible and

enables fast prototyping

from cvxpy import *beta = Variable(n)cost = norm(X * beta - y)prob = Problem(Minimize(cost))prob.solve()beta.value

Convex Optimization 6

Page 9: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Outline

Convex Optimization

CVXR

Examples

Future Work

CVXR 7

Page 10: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

CVXR

A modeling language in R for convex optimization

I Connects to many solvers: ECOS, SCS, MOSEK, etcI Mixes easily with general R code and other librariesI Uses disciplined convex programming to verify convexity

CVXR 8

Page 11: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Outline

Convex Optimization

CVXR

Examples

Future Work

Examples 9

Page 12: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Ordinary Least Squares (OLS)

I minimize ||Xβ − y ||22I β ∈ Rn is variable, X ∈ Rm×n and y ∈ Rm are constants

library(CVXR)beta <- Variable(n)obj <- sum_squares(y - X %*% beta)prob <- Problem(Minimize(obj))result <- solve(prob)result$valueresult$getValue(beta)

I X and y are constants; beta, obj, and prob are S4 objectsI solve method returns a list that includes optimal beta and

objective value

Examples 10

Page 13: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Ordinary Least Squares (OLS)

I minimize ||Xβ − y ||22I β ∈ Rn is variable, X ∈ Rm×n and y ∈ Rm are constants

library(CVXR)beta <- Variable(n)obj <- sum_squares(y - X %*% beta)prob <- Problem(Minimize(obj))result <- solve(prob)result$valueresult$getValue(beta)

I X and y are constants; beta, obj, and prob are S4 objectsI solve method returns a list that includes optimal beta and

objective value

Examples 10

Page 14: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Non-Negative Least Squares (NNLS)

I minimize ||Xβ − y ||22 subject to β ≥ 0

constr <- list(beta >= 0)prob2 <- Problem(Minimize(obj), constr)result2 <- solve(prob2)result2$valueresult2$getValue(beta)

I Construct new problem with list constr of constraintsformed from constants and variables

I Variables, parameters, expressions, and constraints existoutside of any problem

Examples 11

Page 15: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Non-Negative Least Squares (NNLS)

I minimize ||Xβ − y ||22 subject to β ≥ 0

constr <- list(beta >= 0)prob2 <- Problem(Minimize(obj), constr)result2 <- solve(prob2)result2$valueresult2$getValue(beta)

I Construct new problem with list constr of constraintsformed from constants and variables

I Variables, parameters, expressions, and constraints existoutside of any problem

Examples 11

Page 16: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

True vs. Estimated Coefficients

−0.5

0.0

0.5

1.0

1.5

b0 b1 b2 b3 b4 b5 b6 b7 b8 b9Coefficient

Est

imat

eType NNLS True OLS

Examples 12

Page 17: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

True vs. Estimated Coefficients

−0.5

0.0

0.5

1.0

1.5

b0 b1 b2 b3 b4 b5 b6 b7 b8 b9Coefficient

Est

imat

eType NNLS True OLS

Examples 13

Page 18: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Sparse Inverse Covariance Estimation

I Samples xi ∈ Rn drawn i.i.d. from N(0,Σ)I Know covariance Σ ∈ Sn

+ has sparse inverse S = Σ−1

I One way to estimate S is by maximizing the log-likelihoodwith a sparsity constraint:

maximizeS

log det(S)− tr(SQ)subject to S ∈ Sn

+,∑n

i=1∑n

j=1 |Sij | ≤ α

I Q = 1m−1

∑mi=1(xi − x̄)(xi − x̄)> is sample covariance

I α ≥ 0 is a parameter controlling the degree of sparsity

Examples 14

Page 19: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Sparse Inverse Covariance Estimation

I Samples xi ∈ Rn drawn i.i.d. from N(0,Σ)I Know covariance Σ ∈ Sn

+ has sparse inverse S = Σ−1

I One way to estimate S is by maximizing the log-likelihoodwith a sparsity constraint:

maximizeS

log det(S)− tr(SQ)subject to S ∈ Sn

+,∑n

i=1∑n

j=1 |Sij | ≤ α

I Q = 1m−1

∑mi=1(xi − x̄)(xi − x̄)> is sample covariance

I α ≥ 0 is a parameter controlling the degree of sparsity

Examples 14

Page 20: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Sparse Inverse Covariance Estimation

S <- Semidef(n)obj <- log_det(S) - matrix_trace(S %*% Q)constr <- list(sum(abs(S)) <= alpha)prob <- Problem(Maximize(obj), constr)result <- solve(prob)result$getValue(S)

I Semidef restricts variable to positive semidefinite coneI Must use log_det(S) instead of log(det(S)) since det is

not a supported atomI result$getValue(S) returns an R matrix

Examples 15

Page 21: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

True vs. Estimated Sparsity of Inverse

True Inverse Estimate (α = 1)

Examples 16

Page 22: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

True vs. Estimated Sparsity of Inverse

True Inverse Estimate (α = 6)

Examples 17

Page 23: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

True vs. Estimated Sparsity of Inverse

True Inverse Estimate (α = 10)

Examples 18

Page 24: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Outline

Convex Optimization

CVXR

Examples

Future Work

Future Work 19

Page 25: Disciplined Convex Optimization with CVXRanqif/presentations/useR18...Convex Optimization minimize f 0(x) subject to f i(x) ≤0, i = 1,...,M Ax = b with variable x ∈Rn I Objective

Future Work

I Flesh out convex functions in libraryI Develop more applications and examplesI Make connecting new solvers easierI Add warm start supportI Further speed improvements

Official site: cvxr.rbind.ioCRAN page: CRAN.R-project.org/package=CVXR

Future Work 20