Convex Optimization - IHMC

94
Convex Optimization May 25, 2012 Dynamic Walking 2012

Transcript of Convex Optimization - IHMC

Page 1: Convex Optimization - IHMC

Convex OptimizationMay 25, 2012

Dynamic Walking 2012

Page 2: Convex Optimization - IHMC

Convex OptimizationMay 25, 2012

Dynamic Walking 2012

Page 3: Convex Optimization - IHMC

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

Page 4: Convex Optimization - IHMC

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/

Page 5: Convex Optimization - IHMC

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Page 6: Convex Optimization - IHMC

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Page 7: Convex Optimization - IHMC

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

Page 8: Convex Optimization - IHMC

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Page 9: Convex Optimization - IHMC

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

Page 10: Convex Optimization - IHMC

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Page 11: Convex Optimization - IHMC

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Page 13: Convex Optimization - IHMC

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')

Page 14: Convex Optimization - IHMC

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:

Page 15: Convex Optimization - IHMC

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Page 16: Convex Optimization - IHMC

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

Page 17: Convex Optimization - IHMC

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

Page 18: Convex Optimization - IHMC

Polynomial dynamics

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

Page 19: Convex Optimization - IHMC
Page 20: Convex Optimization - IHMC

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

Page 21: Convex Optimization - IHMC
Page 22: Convex Optimization - IHMC

S-procedure

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

Page 23: Convex Optimization - IHMC

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Page 24: Convex Optimization - IHMC

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!

Page 25: Convex Optimization - IHMC

References

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

Page 26: Convex Optimization - IHMC

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

Page 27: Convex Optimization - IHMC

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/

Page 28: Convex Optimization - IHMC

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Page 29: Convex Optimization - IHMC

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Page 30: Convex Optimization - IHMC

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

Page 31: Convex Optimization - IHMC

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Page 32: Convex Optimization - IHMC

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

Page 33: Convex Optimization - IHMC

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Page 34: Convex Optimization - IHMC

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Page 36: Convex Optimization - IHMC

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')

Page 37: Convex Optimization - IHMC

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:

Page 38: Convex Optimization - IHMC

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Page 39: Convex Optimization - IHMC

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

Page 40: Convex Optimization - IHMC

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

Page 41: Convex Optimization - IHMC

Polynomial dynamics

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

Page 42: Convex Optimization - IHMC
Page 43: Convex Optimization - IHMC

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

Page 44: Convex Optimization - IHMC
Page 45: Convex Optimization - IHMC

S-procedure

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

Page 46: Convex Optimization - IHMC

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Page 47: Convex Optimization - IHMC

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!

Page 48: Convex Optimization - IHMC

References

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

Page 49: Convex Optimization - IHMC

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

Page 50: Convex Optimization - IHMC

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/

Page 51: Convex Optimization - IHMC

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Page 52: Convex Optimization - IHMC

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Page 53: Convex Optimization - IHMC

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

Page 54: Convex Optimization - IHMC

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Page 55: Convex Optimization - IHMC

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

Page 56: Convex Optimization - IHMC

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Page 57: Convex Optimization - IHMC

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Page 59: Convex Optimization - IHMC

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')

Page 60: Convex Optimization - IHMC

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:

Page 61: Convex Optimization - IHMC

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Page 62: Convex Optimization - IHMC

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

Page 63: Convex Optimization - IHMC

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

Page 64: Convex Optimization - IHMC

Polynomial dynamics

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

Page 65: Convex Optimization - IHMC
Page 66: Convex Optimization - IHMC

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

Page 67: Convex Optimization - IHMC
Page 68: Convex Optimization - IHMC

S-procedure

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

Page 69: Convex Optimization - IHMC

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Page 70: Convex Optimization - IHMC

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!

Page 71: Convex Optimization - IHMC

References

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

Page 72: Convex Optimization - IHMC

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

Page 73: Convex Optimization - IHMC

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/

Page 74: Convex Optimization - IHMC

Optimization

Problemsf(x) has local minimaslow convergence

Decision Variables

Scalar Objective

Page 75: Convex Optimization - IHMC

Convex programming

No local minima (only 1 global minimum)

Definition of convex functions

Examples: linear function, quadratic, etc.x

f(x)

Page 76: Convex Optimization - IHMC

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

Page 77: Convex Optimization - IHMC

Example: Fit model to data

t

y

trip

noisy data of recovery from trip

Quadratic Objectives

Linear Constraints

Page 78: Convex Optimization - IHMC

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

Page 79: Convex Optimization - IHMC

Dynamics

Approximate inverse dynamics as QP

inertial matrixCoriolis, gravity Applied

torqueq1

q2

q3

Page 80: Convex Optimization - IHMC

Example: approximate inverse dynamics

ground reaction forces

Quadratic program

Page 82: Convex Optimization - IHMC

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')

Page 83: Convex Optimization - IHMC

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:

Page 84: Convex Optimization - IHMC

Semidefinite programming

The set of semidefinite matrices is convex.Semidefinite matrix:

Convex combination of semidefinite matrices:

Page 85: Convex Optimization - IHMC

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

Page 86: Convex Optimization - IHMC

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

Page 87: Convex Optimization - IHMC

Polynomial dynamics

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

Page 88: Convex Optimization - IHMC
Page 89: Convex Optimization - IHMC

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

Page 90: Convex Optimization - IHMC
Page 91: Convex Optimization - IHMC

S-procedure

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

Page 92: Convex Optimization - IHMC

Example: van der Pol Oscillator

Find region of attraction represented as a sum of squares

Page 93: Convex Optimization - IHMC

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!

Page 94: Convex Optimization - IHMC

References

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