Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Matlab Optimization

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 14

Matlab Optimization

1. Optimization toolbox
2. Solution of linear programs
3. Metabolic flux balance analysis example
4. Solution of nonlinear programs
5. Batch fermentation example
Matlab Optimization Toolbox
Minimization
bintprog Solve binary integer programming problems
fgoalattain Solve multiobjective goal attainment problems
fminbnd Find minimum of single-variable function on fixed interval
fmincon Find minimum of constrained nonlinear multivariable function
fminimax Solve minimax constraint problem
fminsearch Find minimum of unconstrained multivariable function using derivative-free method
fminunc Find minimum of unconstrained multivariable function
fseminf Find minimum of semi-infinitely constrained multivariable nonlinear function
linprog Solve linear programming problems
quadprog Solve quadratic programming problems
Least Squares
lsqcurvefit Solve nonlinear curve-fitting (data-fitting) problems in least-squares sense
lsqlin Solve constrained linear least-squares problems
lsqnonlin Solve nonlinear least-squares (nonlinear data-fitting) problems
lsqnonneg Solve nonnegative least-squares constraint problem
Note: fsolve is also part of the optimization toolbox
Linear Programming (LP)
Optimization of a linear objective function with linear
equality and/or inequality constraints
Standard LP form:







Matrix A must have more columns than rows (under-
determined problem)
Common solvers: CPLEX, MOSEK, GLPK
Further information
0 x
b Ax
x c
x
>
= : subject to
min
T
http://www-unix.mcs.anl.gov/otc/Guide/faq/linear-programming-faq.html
x vector of variables to be determined (decision variables)
A matrix of known coefficients
b vector of known coefficients
c vector of weights
c
T
x scalar objective function; linear combination of the decision variables
Matlab LP Solver: linprog
Solves linear programming (LP) problems of the form:






Syntax:

x = linprog(f,A,b,Aeq,beq,lb,ub)

Set A=[]and b=[]if no inequality constraints exist
Set Aeq=[]and beq=[]if no equality constraints exist
Replace f with -f to find the maximum

Defaults to a large-scale interior point method with options for a
medium-scale simplex method variation or the simplex method
See help linprog for additional details and options
ub x lb
beq x Aeq
b x A
x f
T
x
s s
=
s : subject to
min
where f, x, b, beq, lb, and ub are vectors and A and Aeq are matrices
Metabolic Network Model
Intracellular reaction pathways describing carbon metabolism
Consumption of carbon energy sources (e.g. glucose)
Conversion of carbon sources to biomass precursors (cell growth)
Secretion of byproducts (e.g. ethanol)
Each node corresponds to a metabolite
Each path (line) corresponds to a reaction
Stoichiometric matrix, A
Row for each intracellular species (m rows)
Column for each reaction (n columns)
The entry at the i
th
row and j
th
column (a
i,j
) corresponds to the
stoichiometric coefficient of species i participating in reaction j
Av = 0, stoichiometric balance on the metabolites where v is the
vector of reaction fluxes
More reactions (unknowns) than species (equations)
Solution requires either enough measurements for the system to
become square (n-m measurements) or optimization
Flux Balance Analysis (FBA)
Linear programming (optimization) approach for resolving an under-
determined metabolic network model
Objective function based on an assumed cellular objective such as
maximization of growth
LP formulation:



Growth rate, , represented as a linear combination of intracellular
fluxes of the biomass precursors
Flux bounds represent physiochemical or thermodynamic constraints
on the reaction fluxes
Extracellular conditions place limits on fluxes (e.g. oxygen availability)
Thermodynamics constrain the direction a reaction may proceed:
reversible or irreversible
The solution is the set of fluxes that maximizes cellular growth while
satisfying the bounds and stoichiometric constraints
U L
T
v
v v v
Av
v w
s s
=
=
0 : subject to
max
Download the stoichiometric matrix to the
Matlab working directory and load into Matlab
>> load A.txt
Specify the indices of key fluxes: glucose,
ethanol, oxygen, and biomass
>> ig = 22; ie = 20;
>> io = 19; imu = 17;
Av = 0
>> [m n] = size(A);
>> b = zeros(m,1);
Objective function
>> w = zeros(n,1);
>> w(imu) = 1;
Specify flux bounds (all fluxes irreversible,
glucose uptake fixed)
>> vb = [zeros(n,1) Inf*ones(n,1)];
>> vb(ig,:) = [100 100];
Flux Balance Analysis Example
Yeast metabolic network model from HW #2
Slightly modified to improve suitability for Flux Balance Analysis
(FBA)
19x22 stoichiometric matrix
Under-determined with 3 degrees of freedom
Use FBA to determine solution corresponding to optimal cell growth
Solve the LP
>> v = linprog(-w,[],[],A,b,vb(:,1),vb(:,2));
Optimization terminated.
View predictions for growth, oxygen uptake, and ethanol
secretion
>> mu = w'*v, vo2 = v(io), ve = v(ie)
mu =

101.9302

vo2 =

108.3712

ve =

2.4147e-014
All calculated values relative to a fixed glucose uptake rate
normalized to 100%
FBA Example cont.
Determine sensitivity of model predictions to the oxygen uptake
rate to assess the tradeoff between achievable ethanol yields and
cellular growth
Create a vector of oxygen uptake rates to be considered
>> vo = 1:1:125;
Implement a for loop to iterate over each entry in the oxygen
uptake vector (vo). For each iteration (inside the loop), update
the upper bound* on oxygen uptake, solve the LP, and store the
solution (mu, ve)
>> for i=1:length(vo)
vb(io,2) = vo(i);
v = linprog(-w,[],[],A,b,vb(:,1),vb(:,2));
mu(i) = w'*v;
ve(i) = v(ie);
end
Plot the results
>> plot(vo,mu,vo,ve);
>> xlabel('Oxygen Flux')
>> legend('Growth Rate','Ethanol Flux)
Notice the tradeoff between cell growth and ethanol production.
Highest ethanol productivity is achieved in batch fermentation
by initially operating aerobically to rapidly increase cell density
then switching to anaerobic conditions to produce ethanol.
*A fixed oxygen uptake rate (lower bound equal to upper bound) was not specified to avoid forcing the cell to
take up more oxygen than necessary (cell should only use as much oxygen as it needs).
Nonlinear Programming (NLP)
Optimization of a nonlinear objective function with
nonlinear equality and/or inequality constraints
Standard NLP form:






System must have more variables than equality constraints
(under-determined problem)
Common solvers: CONOPT, NPSOL
Non-convex problems can converge to a local optimum
x vector of variables to be determined (decision variables)
h(x) vector function of equality constraints
g(x) vector function of inequality constraints
f(x) scalar objective function
0 x g
0 x h
x
x
s
=
) (
) (
: subject to
) ( min f
Nonlinear least-squares: lsqnonlin


x = lsqnonlin(@fun,x0,lb,ub)

where fun is a user-defined function that returns the vector value F(x),
x0 is the initial guess (starting point), and lb and ub are the bounds on x

Constrained nonlinear multivariable optimization : fmincon

where x, b, beq, lb, and ub are vectors, A and Aeq are matrices, c(x)
and ceq(x) are functions that return vectors, and f(x) is a function that
returns a scalar


x = fmincon(@fun,x0,A,b,Aeq,beq,lb,ub,@cfun)

where fun is the function for f(x) and cfun is a function that returns c(x) and ceq(x)
f = fun(x) [c,ceq] = cfun(x)
Matlab NLP Solvers: lsqnonlin and fmincon
ub x lb
beq x Aeq
b x A
x ceq
x c
x f
x
s s
=
s
=
s
0 ) (
0 ) ( : s.t.
) ( min
2 2
3
2
2
1
2
1
2
) ( ) ( ) ( ) ( ) ( min x f x f x f x f x f
n
n
i
i
x
+ + + + =

=

(
(
(
(

=
) (
) (
) (
) (
) (
3
2
1
x f
x f
x f
x f
x F
n

Batch Fermentation Example


Parameter estimation problem for penicillin fermentation
Model equations
Batch cell growth is modeled by the logistic law



where y
1
is the cell concentration, k
1
is the growth constant & k
2
is the
cessation (limiting nutrient) constant

Penicillin production is modeled as


where y
2
is the penicillin concentration, k
3
is the production constant &
k
4
is the degradation (hydrolysis) constant
Dynamic parameter estimation
Use experimental data from two batch penicillin fermentations
Find values for the unknown parameters (k
1
, k
2
, k
3
, k
4
) that minimize the
sum of squared errors between the data & model predictions
|
|
.
|

\
|
=
2
1
1 1
1
1
k
y
y k
dt
dy
2 4 1 3
2
y k y k
dt
dy
=
Matlab Exercise: Batch Data Sets
Cell Penicillin Cell Penicillin
Time concentration concentration concentration concentration
(hours) (% dry weight) (units/mL) (% dry weight) (units/mL)
0 0.4 0 0.18 0
10 0 0.12 0
22 0.99 0.0089 0.48 0.0089
34 0.0732 1.46 0.0642
46 1.95 0.1446 1.56 0.2266
58 0.523 1.73 0.4373
70 2.52 0.6854 1.99 0.6943
82 1.2566 2.62 1.2459
94 3.09 1.6118 2.88 1.4315
106 1.8243 3.43 2.0402
118 4.06 2.217 3.37 1.9278
130 2.2758 3.92 2.1848
142 4.48 2.8096 3.96 2.4204
154 2.6846 3.58 2.4615
166 4.25 2.8738 3.58 2.283
178 2.8345 3.34 2.7078
190 4.36 2.8828 3.47 2.6542
Batch 1 Batch 2
Load & plot the experimental data:




Choose an initial guess, integrate the model, & plot the simulated profiles:




Estimate parameter values that minimize the sum of squared errors between
the experimental measurements & model predictions:

Matlab Exercise: Solution
>> pendat = xlsread('penicillin.xls');
>> tdat = pendat(:,1);
>> ydat = pendat(:,2:end);
>> plot(tdat,ydat,'o');
>> xlabel('Time [h]');
>> ylabel('Concentration');
>> k0 = [0.1 4 0.01 0.01];
>> y0 = [0.29 0];
>> ts = [min(tdat) max(tdat)];
>> dy = @(t,y,k) [k(1)*y(1)*(1-y(1)/k(2)); k(3)*y(1)-k(4)*y(2)];
>> [tsim,ysim] = ode45(dy,ts,y0,[],k0);
>> hold on, plot(tsim,ysim,':');
>> options = optimset('Display','iter');
>> k = lsqnonlin(@simerr,k0,[],[],options,dy,ts,y0,tdat,ydat);
>> [tsim,ysim] = ode45(dy,ts,y0,[],k);
>> plot(tsim,ysim);
Matlab Exercise: simerr.m
function e = simerr(k0,dy,ts,y0,tdat,ydat)

% Integrate the model
sol = ode45(dy,ts,y0,[],k0);

% Evaluate solution at the data points
y = deval(sol,tdat)';

% Error between data and model
e = ydat - y;

% Find missing measurements
n = find(isnan(ydat));

% Zero error for missing measurements
if ~isempty(n)
e(n) = zeros(size(n));
end

You might also like