sostool toolbox ali molavi iran university of science and technology april 28

22
Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Upload: nicholas-watkins

Post on 01-Jan-2016

235 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Sostool Toolbox

Ali Molavi

Iran University Of Science and Technology

April 28

Page 2: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Intruduction Sum of Squares Polynomials

provide tractable relaxations for many hard optimization problems

SOS can be solved using the powerful tools of convex optimization

Page 3: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Solving sum of squares problem

•SOSTOOLS can solve two kinds of sum of squares programsFeasibilityOptimization To define and solve a SOSPInitialize the SOSPDeclare the SOSP variables.Define the SOSP constraints.Set objective function (for optimization problems)Call solver.Get solutions

1

Page 4: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Initializing a Sum of Squares Program• symbolic objects>> syms x y;

• Polynomial variables>> pvar x y;

• polynomial objects>> p = (x^4)+(5*x*y)+(x*y^2)

2

Page 5: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Initializing a Sum of Squares Program

>> Program1 = sosprogram([x;y]);[x,y] vector containing Independent variablep=(x^2)+(x*y)+(x*z)+(m*h) [x;y;z;m;h]

decision variablesScalar decision variablesPolynomial variablesSum of squares variablesMatrix of polynomial variablesMatrix of sum of squares variables 3

Page 6: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Declare the SOSP variables

Scalar decision variables or constant variable

>>Program1 = sosdecvar(Program1,[a;b]);>>Program1 = sosprogram([x;y],[a;b]);

ExampleP=ax+by>> syms x y a b;>> Program = sosprogram([x;y],[a,b]);>> Program1 = sosdecvar(Program1,[a;b]); 4

Page 7: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Declare the SOSP variables

Scalar Polynomial Variablespolynomials with unknown coefficients

>> Program1 = sosdecvar(Program1,[a;b;c]);>> v = a*x^2 + b*x*y + c*y^2;

[Program1,v] = sospolyvar(Program1,[x^2; x*y; y^2]; ’ wscoeff’);

V=coeff_1*x^2+coeff_2*x*y+coeff_3*y^25

Page 8: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Declare the SOSP variablesConstructing Vectors of MonomialsVEC = monomials([x; y],[1 2 3]) VEC = mpmonomials({[x1; x2],[y1; y2],[z1]},{1:2,1,3})

6

Page 9: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Declare the SOSP variablesSum of Squares Variables

[Program1,p] = sossosvar(Program1,[x; y]);P=coeff_4*y^2+(coeff_2+coeff_3)*x*y+coeff_1*x^2[Q,Z,f] = findsos(P);

7

Page 10: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Declare the SOSP variablesMatrix Variables[prog,P] = sospolymatrixvar(prog,monomials(x,0),[2 2]);

[prog,Q]=sospolymatrixvar(prog,monomials([x1],[1]),[2 2], ’symmetric’);

•Matrix dimention

8

Page 11: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Define the SOSP constraints

Adding ConstraintsEquality constraints Program1 = soseq(Program1,diff(p,x)-x^2);

Inequality Constraints

Program1 = sosineq(Program1,diff(p,x)-x^2);Inequlity constraints with an interval

Program2 = sosineq(Program2,diff(p,x)-x^2,[-1 2]);9

Page 12: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Define the SOSP constraintsMatrix Inequality Constraints syms theta1 theta2; or >>pvar theta1 theta2 theta = [theta1; theta2]; prog = sosprogram(theta);[prog,M]=sospolymatrixvar(prog,monomials(theta,0:2),[3,3],’symmetric’);There are 2 case prog = sosmatrixineq(prog,M,’quadraticMineq’);

prog = sosmatrixineq(prog,M,’Mineq’);

10

Page 13: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Define the SOSP constraints• Example

• Lyapunove Function V(X)=X’PX

• For Stability We can define “eps” then eps<<1

A’P+PA<0P>0

P>eps*IA’P+PA<-eps*I

11

Page 14: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Define the SOSP constraintssyms x; G = rss(4,2,2); A = G.a; eps = 1e-6; I = eye(4);prog = sosprogram(x);[prog,P]=sospolymatrixvar(prog,monomials(x,0),[4,4],’symmetric’);

prog = sosmatrixineq(prog,P-eps*I,’quadraticMineq’);d= A’*P+P*A; prog = sosmatrixineq(prog,-d-eps*I,’quadraticMineq’);

12

Page 15: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Setting an Objective Function and calling solver

Setting objective function Program1 = sossetobj(Program1,a-b);(a ,b )are decision variable

Calling solver Program1 = sossolve(Program1,options);

Getting SolutionsSOLp1 = sosgetsol(Program6,p1,5);P1 is in fact SOSP variable For example a polynomial variable 1

3

Page 16: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Application of sum of Squares programming Sum of Square TestGiven a polynomial p(x), determine if p(x)>0 is feasible

syms x1 x2;vartable = [x1, x2];prog = sosprogram(vartable)% define the inequalityp = 2*x1^4 + 2*x1^3*x2 - x1^2*x2^2 + 5*x2^4;prog = sosineq(prog,p);prog = sossolve(prog); % call solver[Q,Z]=findsos(p,’rational’); % P=Z’QZ 1

4

Page 17: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Application of sum of Squares programming

Lyapunov Function Search

Finding a V(X)>0

Derivative of V(X)

15

Page 18: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Application of sum of Squares programming

syms x1 x2 x3;prog = sosprogram([x1;x2;x3])f=[-x1^3-x1*x3^2;-x2-x1^2*x2;x3+3*x1^2*x33*x3/(x3^2+1)][prog,V] = sospolyvar(prog,[x1^2; x2^2; x3^2],’wscoeff’);V=coeff_4*x1^2 + coeff_5*x2^2 + coeff_6*x3^2%For example “eps=1”prog = sosineq(prog,V-(x1^2+x2^2+x3^2));dd=-(diff(V,x1)*f(1)+diff(V,x2)*f(2)+diff(V,x3)*f(3))*(x3^2+1);prog = sosineq(prog,dd);prog = sossolve(prog);SOLV = sosgetsol(prog,V) 1

6

Page 19: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Application of sum of Squares programming

• Another Way to Find Lyapunov Function

syms x1 x2; V = findlyap([-x1^3+x2; -x1-x2],[x1; x2],2)

The function ‘’findlyap’’ has three argumentThe first one Vector FieldThe second one Ordering of the independent variableThe third one Degree of lyapunov function 1

7

Page 20: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Application of sum of Squares programming

Global and Constrained OptimizationMinimum ( -Gama ) such thatsyms x1 x2 gam;prog = sosprogram([x1,x2]);prog = sosdecvar(prog,[gam]);f = x1+x2-3*x1^2+6*x2*x1prog = sosineq(prog,(f-gam))prog = sossetobj(prog,-gam);prog = sossolve(prog);SOLgamma = sosgetsol(prog,gam)

18

Page 21: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Application of sum of Squares programming

Another way to find minimum of an objective function

syms a b c d;F=(a^4+1)*(b^4+1)*(c^4+1)*(d^4+1)+2*a + 3*b + 4*c + 5*d; [bnd,vars,xopt] = findbound(F)

bnd=lower bound for polynomialVars=A vector of variable of the polynomialXopt=A Point Where The Result is achieved

19

Page 22: Sostool Toolbox Ali Molavi Iran University Of Science and Technology April 28

Application of sum of Square programmingMinimization of polynomial with constraintExample:Minimizing (X1^2)+(X2^2) subject to

syms x1 x2;degree = 4;[gam,vars,opt] = findbound(x1+x2,[x1, x2-0.5],...[x1^2+x2^2-1, x2-x1^2-0.5],degree);

20