Convex Optimization - IHMC

Post on 13-Jan-2022

14 views 0 download

Transcript of Convex Optimization - IHMC

Convex OptimizationMay 25, 2012

Dynamic Walking 2012

Convex OptimizationMay 25, 2012

Dynamic Walking 2012

Examples from Dynamic Walking

● Fit return maps with linear model despite noisy sensors / animals

● Approximate inverse dynamics (w/ constraints)○ Find muscle activations to match data in

musculoskeletal model○ Linear optimal control○ Nonlinear stability analysis○ Region of attraction○ Nonlinear control design

Tools● Linear programming● Quadratic programming● Semidefinite programming

○ Sum of squares Optimization

Software● SeDuMi: Solver of semidefinite programs

○ SDP○ LP, QP, etc.

● YALMIP○ Matlab wrapper for many solvers

Referenceshttp://www.stanford.edu/~boyd/cvxbook/

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Convex programming

Constraints from a convex set

Linear half-space also a convex setCombinations of linear constraints result in convex sets

x1

x2any straight line intersecting set always has only one contiguous region inside set, never crosses out and then back in

Convex Optimization, Stephen BoydConvex Analysis, Rockafellar

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Example: linear_guassian.m [sic]sdpvar Ahat % defines the unknown variableerr = ...objective = err'*err;constraints = [Ahat<=1, Ahat>=-1]; % defines allowable bounds on Ahat% yalmip is pretty smart and allows all sorts of convex constraintssolvesdp(constraints, objectives) % picks an appropriate solver and runs it% returns a structure showing how well it did

Very noisy data being fit with a first-order model

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Solve arm muscle forcesload meas_arm_data; % previously provided data, including q_meas, qd_meas, etc.

n=length(t);

ahat = sdpvar(6,n); % define 6 x n matrix to be solved for

A = MuscleMapping; % matrix of moment arms of muscles

con =[];

for i=1:n

[H,C,B] = ArmDynamics(q_meas(:,i),qd_meas(:,i));

% ArmDynamics returns mass matrix, other terms numerically

con = [con; H*qdd_meas(:,i) + C - B*A*ahat(:,i) == 0];

end

obj = norm (ahat(:),2); % define quadratic objective

con = [con;ahat(:)>=0]; % with non-negativity constraints

solvesdp(con,obj) % puts soln in ahat

load true_arm_data;

plot(t,double(ahat(1,:)),t,a(1,:));

% note ahat is an object that can be cast into a

% double matrix

legend('ahat','a')

Example: min max problem

convert to

Turn into a convex program by introducing new variable cThere are many ways to convert particular optimization problems (that don't necessarily look convex) into convex programs

This often arises when we have a piecewise linear objective function. We can write it like:

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Stability

Another option: Lyapunov stability

Convert into an SDP by optimizing a positive semi-definite matrix S that defines a Lyapunov function.Hard to check eigenvalues of A, but easier to find an S

meaning that we need an S such that

suggestion: use ^{\top} instead of ^T for transpose

Could check stability using

Robust stabilitySuppose A is not known precisely, but that it has possible perturbations that can be expressed as a weighted sum of matrices.Now find an S (i.e. Lyapunov function) that yields a stable closed-loop system despite any weights/perturbations within defined allowable bounds.

Robust stability via Common-Lyapunov function

Polynomial dynamics

Approximate ODE's state-derivative function with a polynomial in xAlso make V a polynomial in xWrite polynomial as sum of squares

Example: Test stability of a simple system%% Example 1

%% prove that \dot{x} = -x^3 is globally stable

sdpvar x;

f = -x^3;

V = x^2;

constraint = sos(-jacobian(V,x)*f);

sol = solvesos(constraint)

%% Example 2

%% prove that \dot(X) = -x + x^3 is stable for x in (-1,1)

sdpvar x;

f = -x + x^3;

V = x^2;

[lambda,c] = polynomial(x,2);

constraint = [sos(-jacobian(V,x)*f + lambda*(V-1)), sos(lambda)];

sol = solvesos(constraint,[],[],c)

x

xdot

1-1

S-procedure

To write as a SOS program, replace positivity with SOS where lambda is a polynomial in x of a specified degree

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Polynomial representation of equations of motion

H(s,c) sines and cosinesH(s,c) qddot - ... = B us^2 + c^2 = 1

Apply as a constraint!

References

Toolbox: http://drake.csail.mit.edu

Examples from Dynamic Walking

● Fit return maps with linear model despite noisy sensors / animals

● Approximate inverse dynamics (w/ constraints)○ Find muscle activations to match data in

musculoskeletal model○ Linear optimal control○ Nonlinear stability analysis○ Region of attraction○ Nonlinear control design

Tools● Linear programming● Quadratic programming● Semidefinite programming

○ Sum of squares Optimization

Software● SeDuMi: Solver of semidefinite programs

○ SDP○ LP, QP, etc.

● YALMIP○ Matlab wrapper for many solvers

Referenceshttp://www.stanford.edu/~boyd/cvxbook/

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Convex programming

Constraints from a convex set

Linear half-space also a convex setCombinations of linear constraints result in convex sets

x1

x2any straight line intersecting set always has only one contiguous region inside set, never crosses out and then back in

Convex Optimization, Stephen BoydConvex Analysis, Rockafellar

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Example: linear_guassian.m [sic]sdpvar Ahat % defines the unknown variableerr = ...objective = err'*err;constraints = [Ahat<=1, Ahat>=-1]; % defines allowable bounds on Ahat% yalmip is pretty smart and allows all sorts of convex constraintssolvesdp(constraints, objectives) % picks an appropriate solver and runs it% returns a structure showing how well it did

Very noisy data being fit with a first-order model

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Solve arm muscle forcesload meas_arm_data; % previously provided data, including q_meas, qd_meas, etc.

n=length(t);

ahat = sdpvar(6,n); % define 6 x n matrix to be solved for

A = MuscleMapping; % matrix of moment arms of muscles

con =[];

for i=1:n

[H,C,B] = ArmDynamics(q_meas(:,i),qd_meas(:,i));

% ArmDynamics returns mass matrix, other terms numerically

con = [con; H*qdd_meas(:,i) + C - B*A*ahat(:,i) == 0];

end

obj = norm (ahat(:),2); % define quadratic objective

con = [con;ahat(:)>=0]; % with non-negativity constraints

solvesdp(con,obj) % puts soln in ahat

load true_arm_data;

plot(t,double(ahat(1,:)),t,a(1,:));

% note ahat is an object that can be cast into a

% double matrix

legend('ahat','a')

Example: min max problem

convert to

Turn into a convex program by introducing new variable cThere are many ways to convert particular optimization problems (that don't necessarily look convex) into convex programs

This often arises when we have a piecewise linear objective function. We can write it like:

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Stability

Another option: Lyapunov stability

Convert into an SDP by optimizing a positive semi-definite matrix S that defines a Lyapunov function.Hard to check eigenvalues of A, but easier to find an S

meaning that we need an S such that

suggestion: use ^{\top} instead of ^T for transpose

Could check stability using

Robust stabilitySuppose A is not known precisely, but that it has possible perturbations that can be expressed as a weighted sum of matrices.Now find an S (i.e. Lyapunov function) that yields a stable closed-loop system despite any weights/perturbations within defined allowable bounds.

Robust stability via Common-Lyapunov function

Polynomial dynamics

Approximate ODE's state-derivative function with a polynomial in xAlso make V a polynomial in xWrite polynomial as sum of squares

Example: Test stability of a simple system%% Example 1

%% prove that \dot{x} = -x^3 is globally stable

sdpvar x;

f = -x^3;

V = x^2;

constraint = sos(-jacobian(V,x)*f);

sol = solvesos(constraint)

%% Example 2

%% prove that \dot(X) = -x + x^3 is stable for x in (-1,1)

sdpvar x;

f = -x + x^3;

V = x^2;

[lambda,c] = polynomial(x,2);

constraint = [sos(-jacobian(V,x)*f + lambda*(V-1)), sos(lambda)];

sol = solvesos(constraint,[],[],c)

x

xdot

1-1

S-procedure

To write as a SOS program, replace positivity with SOS where lambda is a polynomial in x of a specified degree

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Polynomial representation of equations of motion

H(s,c) sines and cosinesH(s,c) qddot - ... = B us^2 + c^2 = 1

Apply as a constraint!

References

Toolbox: http://drake.csail.mit.edu

Examples from Dynamic Walking

● Fit return maps with linear model despite noisy sensors / animals

● Approximate inverse dynamics (w/ constraints)○ Find muscle activations to match data in

musculoskeletal model○ Linear optimal control○ Nonlinear stability analysis○ Region of attraction○ Nonlinear control design

Tools● Linear programming● Quadratic programming● Semidefinite programming

○ Sum of squares Optimization

Software● SeDuMi: Solver of semidefinite programs

○ SDP○ LP, QP, etc.

● YALMIP○ Matlab wrapper for many solvers

Referenceshttp://www.stanford.edu/~boyd/cvxbook/

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Convex programming

Constraints from a convex set

Linear half-space also a convex setCombinations of linear constraints result in convex sets

x1

x2any straight line intersecting set always has only one contiguous region inside set, never crosses out and then back in

Convex Optimization, Stephen BoydConvex Analysis, Rockafellar

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Example: linear_guassian.m [sic]sdpvar Ahat % defines the unknown variableerr = ...objective = err'*err;constraints = [Ahat<=1, Ahat>=-1]; % defines allowable bounds on Ahat% yalmip is pretty smart and allows all sorts of convex constraintssolvesdp(constraints, objectives) % picks an appropriate solver and runs it% returns a structure showing how well it did

Very noisy data being fit with a first-order model

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Solve arm muscle forcesload meas_arm_data; % previously provided data, including q_meas, qd_meas, etc.

n=length(t);

ahat = sdpvar(6,n); % define 6 x n matrix to be solved for

A = MuscleMapping; % matrix of moment arms of muscles

con =[];

for i=1:n

[H,C,B] = ArmDynamics(q_meas(:,i),qd_meas(:,i));

% ArmDynamics returns mass matrix, other terms numerically

con = [con; H*qdd_meas(:,i) + C - B*A*ahat(:,i) == 0];

end

obj = norm (ahat(:),2); % define quadratic objective

con = [con;ahat(:)>=0]; % with non-negativity constraints

solvesdp(con,obj) % puts soln in ahat

load true_arm_data;

plot(t,double(ahat(1,:)),t,a(1,:));

% note ahat is an object that can be cast into a

% double matrix

legend('ahat','a')

Example: min max problem

convert to

Turn into a convex program by introducing new variable cThere are many ways to convert particular optimization problems (that don't necessarily look convex) into convex programs

This often arises when we have a piecewise linear objective function. We can write it like:

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Stability

Another option: Lyapunov stability

Convert into an SDP by optimizing a positive semi-definite matrix S that defines a Lyapunov function.Hard to check eigenvalues of A, but easier to find an S

meaning that we need an S such that

suggestion: use ^{\top} instead of ^T for transpose

Could check stability using

Robust stabilitySuppose A is not known precisely, but that it has possible perturbations that can be expressed as a weighted sum of matrices.Now find an S (i.e. Lyapunov function) that yields a stable closed-loop system despite any weights/perturbations within defined allowable bounds.

Robust stability via Common-Lyapunov function

Polynomial dynamics

Approximate ODE's state-derivative function with a polynomial in xAlso make V a polynomial in xWrite polynomial as sum of squares

Example: Test stability of a simple system%% Example 1

%% prove that \dot{x} = -x^3 is globally stable

sdpvar x;

f = -x^3;

V = x^2;

constraint = sos(-jacobian(V,x)*f);

sol = solvesos(constraint)

%% Example 2

%% prove that \dot(X) = -x + x^3 is stable for x in (-1,1)

sdpvar x;

f = -x + x^3;

V = x^2;

[lambda,c] = polynomial(x,2);

constraint = [sos(-jacobian(V,x)*f + lambda*(V-1)), sos(lambda)];

sol = solvesos(constraint,[],[],c)

x

xdot

1-1

S-procedure

To write as a SOS program, replace positivity with SOS where lambda is a polynomial in x of a specified degree

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Polynomial representation of equations of motion

H(s,c) sines and cosinesH(s,c) qddot - ... = B us^2 + c^2 = 1

Apply as a constraint!

References

Toolbox: http://drake.csail.mit.edu

Examples from Dynamic Walking

● Fit return maps with linear model despite noisy sensors / animals

● Approximate inverse dynamics (w/ constraints)○ Find muscle activations to match data in

musculoskeletal model○ Linear optimal control○ Nonlinear stability analysis○ Region of attraction○ Nonlinear control design

Tools● Linear programming● Quadratic programming● Semidefinite programming

○ Sum of squares Optimization

Software● SeDuMi: Solver of semidefinite programs

○ SDP○ LP, QP, etc.

● YALMIP○ Matlab wrapper for many solvers

Referenceshttp://www.stanford.edu/~boyd/cvxbook/

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Convex programming

Constraints from a convex set

Linear half-space also a convex setCombinations of linear constraints result in convex sets

x1

x2any straight line intersecting set always has only one contiguous region inside set, never crosses out and then back in

Convex Optimization, Stephen BoydConvex Analysis, Rockafellar

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Example: linear_guassian.m [sic]sdpvar Ahat % defines the unknown variableerr = ...objective = err'*err;constraints = [Ahat<=1, Ahat>=-1]; % defines allowable bounds on Ahat% yalmip is pretty smart and allows all sorts of convex constraintssolvesdp(constraints, objectives) % picks an appropriate solver and runs it% returns a structure showing how well it did

Very noisy data being fit with a first-order model

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Solve arm muscle forcesload meas_arm_data; % previously provided data, including q_meas, qd_meas, etc.

n=length(t);

ahat = sdpvar(6,n); % define 6 x n matrix to be solved for

A = MuscleMapping; % matrix of moment arms of muscles

con =[];

for i=1:n

[H,C,B] = ArmDynamics(q_meas(:,i),qd_meas(:,i));

% ArmDynamics returns mass matrix, other terms numerically

con = [con; H*qdd_meas(:,i) + C - B*A*ahat(:,i) == 0];

end

obj = norm (ahat(:),2); % define quadratic objective

con = [con;ahat(:)>=0]; % with non-negativity constraints

solvesdp(con,obj) % puts soln in ahat

load true_arm_data;

plot(t,double(ahat(1,:)),t,a(1,:));

% note ahat is an object that can be cast into a

% double matrix

legend('ahat','a')

Example: min max problem

convert to

Turn into a convex program by introducing new variable cThere are many ways to convert particular optimization problems (that don't necessarily look convex) into convex programs

This often arises when we have a piecewise linear objective function. We can write it like:

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Stability

Another option: Lyapunov stability

Convert into an SDP by optimizing a positive semi-definite matrix S that defines a Lyapunov function.Hard to check eigenvalues of A, but easier to find an S

meaning that we need an S such that

suggestion: use ^{\top} instead of ^T for transpose

Could check stability using

Robust stabilitySuppose A is not known precisely, but that it has possible perturbations that can be expressed as a weighted sum of matrices.Now find an S (i.e. Lyapunov function) that yields a stable closed-loop system despite any weights/perturbations within defined allowable bounds.

Robust stability via Common-Lyapunov function

Polynomial dynamics

Approximate ODE's state-derivative function with a polynomial in xAlso make V a polynomial in xWrite polynomial as sum of squares

Example: Test stability of a simple system%% Example 1

%% prove that \dot{x} = -x^3 is globally stable

sdpvar x;

f = -x^3;

V = x^2;

constraint = sos(-jacobian(V,x)*f);

sol = solvesos(constraint)

%% Example 2

%% prove that \dot(X) = -x + x^3 is stable for x in (-1,1)

sdpvar x;

f = -x + x^3;

V = x^2;

[lambda,c] = polynomial(x,2);

constraint = [sos(-jacobian(V,x)*f + lambda*(V-1)), sos(lambda)];

sol = solvesos(constraint,[],[],c)

x

xdot

1-1

S-procedure

To write as a SOS program, replace positivity with SOS where lambda is a polynomial in x of a specified degree

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Polynomial representation of equations of motion

H(s,c) sines and cosinesH(s,c) qddot - ... = B us^2 + c^2 = 1

Apply as a constraint!

References

Toolbox: http://drake.csail.mit.edu