modeling with mosek fusion
play

Modeling with MOSEK Fusion Ulf Worse INFORMS Minneapolis October 5 - PowerPoint PPT Presentation

Modeling with MOSEK Fusion Ulf Worse INFORMS Minneapolis October 5 2013 http://www.mosek.com What is Fusion? 2 / 24 What is Fusion? What is Fusion? Fusion is a modern object oriented API for conic What is Fusion? optimization in


  1. Modeling with MOSEK Fusion Ulf Worsøe INFORMS Minneapolis October 5 2013 http://www.mosek.com

  2. What is Fusion? 2 / 24

  3. What is Fusion? What is Fusion? Fusion is a modern object oriented API for conic ■ What is Fusion? optimization in MOSEK available for Why Fusion? Let’s get to the code ◆ Matlab part! ◆ Java 1.6+ Performance ◆ .NET 2.2+ Conclusions ◆ Python 2.6+ Fusion is designed to be as efficient as possible while ■ making it easy to develop models. Fusion includes a library of generic functionality to assist ■ model building. 3 / 24

  4. Why Fusion? What is Fusion? Developing complex models in the optimizer API is time ■ What is Fusion? consuming and error prone — especially so for Why Fusion? semi-definite programming introduced in MOSEK 7.0. Let’s get to the code part! Several customers have built their own Fusion-like ■ Performance functionality to be able to implement complex models. Conclusions Fusion allows only conic models which can be solved ■ very efficiently in MOSEK. Fusion allows and encourages vectorized formulations ■ making the model building more efficient than many third party interfaces and modeling languages. Finally, Fusion is implemented to be as efficient as possible: Conic optimization can be solved very efficiently, and the model building phase should not dominate in terms of time. Even if the last seconds mean everything, using Fusion for prototyping decreases the model development time. 4 / 24

  5. Let’s get to the code part! 5 / 24

  6. Portfolio model What is Fusion? This is a variant of the Markowitz portfolio model that we Let’s get to the code often see: part! Portfolio model n Portfolio model x T ( G T G ) x + transformed � m i x 3 / 2 minimize Portfolio in Fusion/Python i =1 Traffic flow network r T x = t Traffic flow network: such that original form x ∈ R n , x ≥ 0 Traffic flow network: conic form Traffic flow in Fusion/Python This model assumes that we have no initial investment and Modeling a complex cone: Geometric that we require a certain return. mean cone GM cone of power 2 Here: GM cone Geometric mean x T G T Gx is the variance (or risk ) of the portfolio x , ■ cone in Fusion/Python i =1 m i x 3 / 2 is the market impact term, and � n ■ Performance r T x is the expected return of the portfolio x ■ Conclusions 6 / 24

  7. Portfolio model transformed What is Fusion? The conic form of this: Let’s get to the code part! z + m T y minimize Portfolio model Portfolio model r T x = t transformed such that Portfolio in Fusion/Python 2 · (1 / 2) · z ≥ || Gx || 2 2 Traffic flow network Traffic flow network: 2 y i w i ≥ x 2 i , for i = 1 . . . n original form Traffic flow network: 2 · (1 / 8) · x i ≥ w 2 i , for i = 1 . . . n conic form Traffic flow in x ∈ R n , x ≥ 0 G Fusion/Python Modeling a complex cone: Geometric mean cone The three non-linear constraints can be implemented using GM cone of power 2 the rotated quadratic cone of dimension 3: GM cone Geometric mean cone in Q 3 r = { x ∈ R 3 | 2 x 1 x 2 ≥ x 2 Fusion/Python 3 } Performance Conclusions 7 / 24

  8. Portfolio in Fusion/Python from mosek.fusion import * def portfolio(G,m,r,t): n = len(m) with Model("Markowitz") as M: x = M.variable(n,Domain.greaterThan(0.0)) y = M.variable(n,Domain.unbounded()) z = M.variable(1,Domain.unbounded()) w = M.variable(n,Domain.unbounded()) M.constraint(Expr.mul(r,x), Domain.equalsTo(t)) M.constraint(Expr.vstack(0.5,z,Expr.mul(G,x)), Domain.inRotatedQCone()) M.constraint(Expr.hstack(y,w,x), Domain.inRotatedQCone()) M.constraint(Expr.hstack(Expr.constTerm(n,.125),x,w), Domain.inRotatedQCone()) M.objective(ObjectiveSense.Minimize, Expr.add(z,Expr.dot(m,y))) M.solve() return x.level() if __name__ == ’__main__’: G = DenseMatrix(3,3, [ 0.16667,0.02322, 0.00126, 0, 0.10286,-0.00223, 0, 0, 0.03381 ]) r = [ 0.1073, 0.0737, 0.0627 ] m = [ 0.01, 0.01, 0.01 ] print "x =",portfolio(G,m,r,0.08) 8 / 24

  9. Traffic flow network What is Fusion? Traffic network model based on a presentation by Robert Let’s get to the code Fourer (Convexity Detection in Large-Scale Optimization., part! Portfolio model 2011. OR 53 Nottingham 6-8 September 2011). Portfolio model transformed Portfolio in Fusion/Python 1 x 13 x 01 Traffic flow network Traffic flow network: original form Traffic flow network: conic form x 21 Traffic flow in source sink 0 3 Fusion/Python Modeling a complex cone: Geometric mean cone x 30 x 02 x 23 GM cone of power 2 GM cone 2 Geometric mean cone in Fusion/Python Performance The red arc is added to simplify the formulation of the model, Conclusions but it has infinite capacity and is not included in the objective. 9 / 24

  10. Traffic flow network: original form What is Fusion? Let’s get to the code � t ij x ij /T minimize part! Portfolio model ( i,j ) ∈ A Portfolio model transformed s ij x ij Portfolio in t ij = b ij , ( i, j ) ∈ A such that Fusion/Python 1 − x ij c ij Traffic flow network Traffic flow network: � � x ij = x ji , i ∈ N original form Traffic flow network: j :( i,j ) ∈ A + j :( j,i ) ∈ A + conic form Traffic flow in x es = T Fusion/Python Modeling a complex 0 ≤ x ij ≤ c ij , ( i, j ) ∈ A cone: Geometric mean cone GM cone of power 2 where N is the set of nodes, A is the set of arcs and A + is the GM cone Geometric mean set of arcs plus an arc from sink to source. c ij is the capacity cone in Fusion/Python and s ij is the sensitivity of arc ( i, j ) . Performance Conclusions 10 / 24

  11. Traffic flow network: conic form What is Fusion? 1 Let’s get to the code � part! minimize T ( b ij x ij + y ij ) (1) Portfolio model Portfolio model ( i,j ) ∈ A transformed 21 − x ij c ij Portfolio in y ij ≥ x 2 such that ij , ( i, j ) ∈ A (2) Fusion/Python 2 s ij Traffic flow network Traffic flow network: � � original form x ij = x ji , i ∈ N (3) Traffic flow network: conic form j :( i,j ) ∈ A + j :( j,i ) ∈ A + Traffic flow in Fusion/Python x es = T (4) Modeling a complex cone: Geometric 0 ≤ x ij ≤ c ij , ( i, j ) ∈ A (5) mean cone GM cone of power 2 GM cone Geometric mean Objective (1) is now linear. ■ cone in Fusion/Python The term t is completely gone (in fact we substituted t ■ Performance into the original objective). Conclusions Constraint (2) is a rotated quadratic cone. ■ 11 / 24

  12. Traffic flow in Fusion/Python def main(N,E, source,sink, arc_sensitivity, arc_capacity, arc_baseTravelTime, T): with Model("Traffic Network") as M: arc_i = [ i for i,j in E ] arc_j = [ j for i,j in E ] e = Matrix.sparse(N,N, arc_i,arc_j, 1.0) c = Matrix.sparse(N,N,arc_i,arc_j, arc_capacity) cplus = Matrix.sparse(N,N,arc_i + [sink],arc_j + [source], arc_capacity + [T]) # Set up (5) x = M.sparseVariable(’x’, NDSet(N,N), Domain.inRange(0.0, cplus)) y = M.sparseVariable(’y’, NDSet(N,N), Domain.unbounded()) # Set up (1) b = Matrix.sparse(N,N, arc_i,arc_j,arc_baseTravelTime) M.objective(ObjectiveSense.Minimize, Expr.mul(1.0/T, Expr.add((Expr.dot(x,b), Expr.dot(y,e))))) # Set up (2) y_sel = y.pick_flat([ i*N+j for (i,j) in E]) x_sel = x.pick_flat([ i*N+j for (i,j) in E]) one_div_2s = [0.5/s for s in arc_sensitivity] M.constraint(’(2)’, Expr.hstack(Expr.mulElm(Expr.sub(1.0,Expr.mulElm(x_sel,[ 1.0/c for c in arc_capacity ])), one_div_2s), y_sel, x_sel), Domain.inRotatedQCone()) # Set up (3) eplus_T = Matrix.sparse(N,N, arc_j+[source],arc_i+[sink], 1.0) M.constraint(’(3)’, Expr.sub(Expr.mulDiag(x,eplus_T), Expr.mulDiag(eplus_T,x)), Domain.equalsTo(0.0)) # Set up (4) M.constraint(’(4)’, x.index(sink,source), Domain.equalsTo(T)) M.solve() return x_sel.level() 12 / 24

  13. Modeling a complex cone: Geometric mean cone What is Fusion? It is possible to model several complex sets using quadratic Let’s get to the code cones. One example: The geometric mean (GM) cone: part! Portfolio model Portfolio model � n � 1 /n transformed Portfolio in � t ≤ x i , x i ≥ 0 Fusion/Python Traffic flow network i =1 Traffic flow network: original form We notice first that the GM cone of size 3 is in fact almost the Traffic flow network: conic form rotated quadratic cone of size 3: Traffic flow in Fusion/Python √ Modeling a complex 2 x 1 x 2 ⇔ ( x 1 , x 2 , t ) ∈ Q 3 t ≤ cone: Geometric r mean cone GM cone of power 2 GM cone so, e.g., the GM cone of size 5 can then be implemented as: Geometric mean cone in √ √ √ 2 t ≤ , √ 2 t 1 t 2 , 2 t 1 ≤ √ 2 x 1 x 2 , 2 t 2 ≤ √ 2 x 3 x 4 Fusion/Python Performance ⇔ Conclusions √ √ √ 2 t 2 ) ∈ Q 3 ( t 1 , t 2 2 t ) , ( x 1 , x 2 , 2 t 1 ) , ( x 3 , x 4 , r 13 / 24

Recommend


More recommend