Sums of squares - IME-USP

14
Sums of squares v (x) = (1, x, x 2 ,y,y 2 , xy ) p is a sum of squares () 9 Q 0 with p(x)= hQ, v (x)v (x) T i Q v (x)v (x) T 0 B B B B B B B B @ - 1 x x 2 y y 2 xy 1 q 11 q 12 q 13 q 14 q 15 q 16 x q 21 q 22 q 23 q 24 q 25 q 26 x 2 q 31 q 32 q 33 q 34 q 35 q 36 y q 41 q 42 q 43 q 44 q 45 q 46 y 2 q 51 q 52 q 53 q 54 q 55 q 56 xy q 61 q 62 q 63 q 64 q 65 q 66 1 C C C C C C C C A 0 B B B B B B B B @ - 1 x x 2 y y 2 xy 1 1 x x 2 y y 2 xy x x x 2 x 3 xy xy 2 x 2 y x 2 x 2 x 3 x 4 x 2 y x 2 y 2 x 3 y y y xy x 2 y y 2 y 3 xy 2 y 2 y 2 xy 2 x 2 y 2 y 3 y 4 xy 3 xy xy x 2 y x 3 y xy 2 xy 3 x 2 y 2 1 C C C C C C C C A p(x, y )= x 4 +2x 3 y + x 2 y 2 - 6x 2 y - 6xy 2 + 10x 2 + 10xy +9y 2 - 30y + 25 q 11 = 25 q 23 + q 32 =0 q 25 + q 52 + q 46 + q 64 = -6 Q = X u i u T i = ) p = X (u T i v (x)) 2

Transcript of Sums of squares - IME-USP

Page 1: Sums of squares - IME-USP

Sums of squares

v(x) = (1, x, x2, y, y

2, xy)

p is a sum of squares () 9 Q ⌫ 0 with p(x) = hQ, v(x)v(x)

Ti

Qv(x)v(x)T

0

BBBBBBBB@

� 1 x x

2y y

2xy

1 q11 q12 q13 q14 q15 q16

x q21 q22 q23 q24 q25 q26

x

2q31 q32 q33 q34 q35 q36

y q41 q42 q43 q44 q45 q46

y

2q51 q52 q53 q54 q55 q56

xy q61 q62 q63 q64 q65 q66

1

CCCCCCCCA

0

BBBBBBBB@

� 1 x x

2y y

2xy

1 1 x x

2y y

2xy

x x x

2x

3xy xy

2x

2y

x

2x

2x

3x

4x

2y x

2y

2x

3y

y y xy x

2y y

2y

3xy

2

y

2y

2xy

2x

2y

2y

3y

4xy

3

xy xy x

2y x

3y xy

2xy

3x

2y

2

1

CCCCCCCCA

p(x, y) = x

4 + 2x3y + x

2y

2 � 6x2y � 6xy2 + 10x2 + 10xy + 9y2 � 30y + 25

q11 = 25

q23 + q32 = 0

q25 + q52 + q46 + q64 = �6

Q =X

uiuTi =) p =

X(uT

i v(x))2

Page 2: Sums of squares - IME-USP

Sparse SDPA format: Setupmaximize hF0, Y i

hFi, Y i = ci for i = 1, . . . , mY ⌫ 0.

minimize c1x1 + · · ·+ cmxm

x1F1 + x2F2 + · · ·+ xmFm � F0 ⇥ 0.

1

2

3 Block 4, a diagonal block

Matrices have a block structure

Page 3: Sums of squares - IME-USP

Sparse SDPA format

maximize hF0, Y ihFi, Y i = ci for i = 1, . . . , mY ⌫ 0.

Text file ‘problem.sdpa’:

Matrix entries: hmatrix number i h block number i h i i h j i h entry i

Right-hand side: c1 c2 · · · cmBlock sizes: s1 s2 · · · sN

Number of constraint matrices: m

Number of blocks: N

Remarks: • Indices always start at 1 • Write the size of a block as a negative number to indicate a diagonal block • Only upper-diagonal entries need to be given!

Page 4: Sums of squares - IME-USP

A feasibility problem

p(x) = x

4 + 6x3 + 15x2 � 10x+ 17

F2 =

0

@0 1 01 0 00 0 0

1

AF1 =

0

@1 0 00 0 00 0 0

1

A

F3 =

0

@0 0 10 1 01 0 0

1

A F4 =

0

@0 0 00 0 10 1 0

1

A F5 =

0

@0 0 00 0 00 0 1

1

A

F0 =

0

@0 0 00 0 00 0 0

1

A

maximize hF0, Y ihFi, Y i = ci for i = 1, . . . , 5

Y ⌫ 0.

Is the polynomial

a sum of squares?

c1 = 17, c2 = �10, c3 = 15, c4 = 6, c5 = 1

v(x) = (1, x, x2)

Page 5: Sums of squares - IME-USP

The SDPA file

F2 =

0

@0 1 01 0 00 0 0

1

AF1 =

0

@1 0 00 0 00 0 0

1

A

F3 =

0

@0 0 10 1 01 0 0

1

A F4 =

0

@0 0 00 0 10 1 0

1

A F5 =

0

@0 0 00 0 00 0 1

1

A

F0 =

0

@0 0 00 0 00 0 0

1

A

c1 = 17, c2 = �10, c3 = 15, c4 = 6, c5 = 1

File ‘sos1.sdpa’: 5 ▷ Number of constraint matrices!1 ▷ We have only one block!3 ▷ Which is 3x3!17 -10 15 6 1 ▷ The right-hand side 1 1 1 1 1.0 ▷ Matrix entries!2 1 1 2 1.0 !3 1 1 3 1.0 !3 1 2 2 1.0!4 1 2 3 1.0 !5 1 3 3 1.0

Page 6: Sums of squares - IME-USP

CSDP output

p1(x) = �0.719209404617218x2 � 1.21267812518166x+ 4.12310562561766

p2(x) = 0.482351656352516x2 + 4.41136763929902x

p3(x) = 0.500074706343094x2

p

21 + p

22 + p

23 = x

4 + 6x3 + 15x2 � 10x+ 17

Y =

0

@17.0000000000000 �5.00000000000000 �2.96537634217438

�5.00000000000000 20.9307526843488 3.00000000000000�2.96537634217438 3.00000000000000 1.00000000000000

1

A

0.0 0.0 0.0 0.0 0.0 ▷ Dual solution, only numbers!1 1 1 1 2.886751345948129001e-11 ▷ Dual solution, matrix!1 1 2 2 2.886751345948129001e-11 !1 1 3 3 2.886751345948129001e-11 !2 1 1 1 1.700000000000000000e+01 ▷ Primal solution, matrix!2 1 1 2 -5.000000000000000000e+00 !2 1 1 3 -2.965376342174380397e+00 !2 1 2 2 2.093075268434876079e+01 !2 1 2 3 3.000000000000000000e+00 !2 1 3 3 1.000000000000000000e+00

Page 7: Sums of squares - IME-USP

Minimum of a polynomial

minimize �p(x) + � is SOS.

minimize �hA1, Xi � � = c1,hAi, Xi = ci for i = 2, . . . , 5,X ⌫ 0.

� is free: � = �+ � ��, with �+, �� � 0

Find the minimum of the polynomial

A0 =

0

@0 0 00 0 00 0 0

1

A A1 =

0

@1 0 00 0 00 0 0

1

A A2 =

0

@0 1 01 0 00 0 0

1

A

A3 =

0

@0 0 10 1 01 0 0

1

A A4 =

0

@0 0 00 0 10 1 0

1

A A5 =

0

@0 0 00 0 00 0 1

1

A

c1 = 4, c2 = 3, c3 = �10, c4 = 0, c5 = 1

maximize hB,LihA1, Xi+ hB,Li = c1,hAi, Xi = ci for i = 2, . . . , 5,X, L ⌫ 0.

B =

✓1 00 �1

◆and hB,Li = ��

p(x) = x

4 � 10x2 + 3x+ 4

Page 8: Sums of squares - IME-USP

The SDPA fileEach Fi and Y has two blocks:

• a 3� 3 block, corresponding to Ai and X

• a 2� 2 diagonal block, corresponding to L

File ‘sos2.sdpa’: 5!2!3 -2!4 3 -10 0 1!1 1 1 1 1.0!1 2 1 1 1.0!1 2 2 2 -1.0!2 1 1 2 1.0!3 1 1 3 1.0!3 1 2 2 1.0!4 1 2 3 1.0!5 1 3 3 1.0!0 2 1 1 1.0!0 2 2 2 -1.0

c1 = 4, c2 = 3, c3 = �10, c4 = 0, c5 = 1

A0 =

0

@0 0 00 0 00 0 0

1

A A1 =

0

@1 0 00 0 00 0 0

1

A A2 =

0

@0 1 01 0 00 0 0

1

A

A3 =

0

@0 0 10 1 01 0 0

1

A A4 =

0

@0 0 00 0 10 1 0

1

A A5 =

0

@0 0 00 0 00 0 1

1

A

B =

✓1 00 �1

Y =

0

BBBB@

X11 X12 X13

X21 X22 X23

X31 X32 X33

L11

L22

1

CCCCA

maximize hB,LihA1, Xi+ hB,Li = c1,hAi, Xi = ci for i = 2, . . . , 5,X, L ⌫ 0.

Page 9: Sums of squares - IME-USP

Fan’s theorem

maximize hA,XitrX = k,I ⌫ X ⌫ 0.

Now Y has two blocks: one for X and one for X 0.

Find sum of k largest eigenvalues of symmetric A 2 Rn⇥n.

• Eij � Rn⇥n: 1 exactly at position (i, j)

maximize hA,XitrX = k,X 0

= I �X,X,X 0 ⌫ 0.

maximize hA,XihI,Xi = k,hEij , Xi+ hEij , X 0i = �ij ,X,X 0 ⌫ 0.

E11 =

✓1 00 0

◆E22 =

✓0 00 1

◆E12 =

✓0 1/21/2 0

• Eij � Rn⇥n = 12 (Eij + Eji)

Page 10: Sums of squares - IME-USP

Fan’s theorem: example

6!2!3 3!2 1 1 1 0 0 0!1 1 1 1 1.0 ▷ F1 is identity!1 1 2 2 1.0!1 1 3 3 1.0!2 1 1 1 1.0 ▷ F2 = E11!2 2 1 1 1.0!3 1 2 2 1.0 ▷ F3 = E22!3 2 2 2 1.0!4 1 3 3 1.0 ▷ F4 = E33!4 2 3 3 1.0!

5 1 1 2 0.5 ▷ F5 = E12!5 2 1 2 0.5!6 1 1 3 0.5 ▷ F6 = E13!6 2 1 3 0.5!7 1 2 3 0.5 ▷ F7 = E23!7 2 2 3 0.5!0 1 1 1 2.0 ▷ F0 = A!0 1 1 2 1.0!0 1 1 3 2.0!0 1 2 2 2.0!0 1 2 3 28.0!0 1 3 3 -6.0!

File ‘fan.sdpa’:

A =

0

@2 1 21 2 282 28 �6

1

A

Page 11: Sums of squares - IME-USP

Using CSDP from SAGE• Simple SAGE module to solve problems with CSDP • Allows you to read the solution given by CSDP as SAGE matrices • NO WARRANTY!

Module csdp: Example of use >> import csdp!>> ret = run_csdp(‘problem.sdpa’)!>> ret = run_csdp(‘problem.sdpa’, ‘solution.sol’)!>> ret.primal_value!13.4!>> ret.msg!‘SDP solved’!>> sol = read_csdp_solution(‘solution.sol’, [ 4, 5, -2 ])!>> sol[0]!(Matrix corresponding to block 1)!>> sol[1]!(Matrix corresponding to block 2)!>> sol[2]!(Vector giving diagonal of diagonal block 3)

Page 12: Sums of squares - IME-USP

The MAXCUT SDP in SAGE

max hC,XihEi, Xi = 1 for all i 2 VX ⌫ 0.

Ei is one exactly at (i, i)

Cij =

(w(�(i)) if i = j

�w(ij) if i 6= j

Then: MAXCUT relaxation =

14SDP value

Laplacian matrix

Page 13: Sums of squares - IME-USP

Program

File maxcut.sage: def maxcut_sdp(G, w):! n = G.num_verts()! idx = dict(zip(G.vertices(), range(n)))!! # Cost matrix! C = matrix(RDF, n)! for u, v in G.edge_iterator(labels = False):! i, j = idx[u], idx[v]! C[i, j] = C[j, i] = -w[u, v]!! for u in G:! i = idx[u]! for e in G.edge_iterator(u, labels = False):! C[i, i] += w[e]!! outfile = open('maxcut.sdpa', 'w')!

Page 14: Sums of squares - IME-USP

Program (cont.)File maxcut.sage: def maxcut_sdp(G, w):! (…)! outfile.write('%d\n' % n)! outfile.write('1\n')! outfile.write('%d\n' % n)! outfile.write(n * '1 ' + '\n')!! for i in xrange(n):! outfile.write('%d 1 %d %d 1.0\n' % (i+1, i+1, i+1))!! for i in xrange(C.nrows()):! for j in xrange(i, C.ncols()):! outfile.write('0 1 %d %d %f\n' % (i+1, j+1, C[i,j]))!! outfile.close()!! ret = csdp.run_csdp('maxcut.sdpa')! return ret.primal_value / 4!