matlab optimization
Short Description
Download matlab optimization...
Description
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
Linear Programming (LP)
Optimization of a linear objective function with linear equality and/or inequality constraints Standard LP form: min x
cT x
subject to: Ax b x0 x – vector of variables to be determined (decision variables) A – matrix of known coefficients b – vector of known coefficients c – vector of weights cT x – scalar objective function; linear combination of the decision variables
Matrix A must have more columns than rows (underdetermined problem)
Common solvers: CPLEX, MOSEK, GLPK
Further information http://www-unix.mcs.anl.gov/otc/Guide/faq/linear-programming-faq.html
Matlab LP Solver: linprog
Solves linear programming (LP) problems of the form: min x
f T x
subject to: A x b Aeq x beq lb x ub where f , x, b, beq, lb, and ub are vectors and A and Aeq are matrices
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
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 ith row and jth column (ai,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 underdetermined metabolic network model Objective function based on an assumed cellular objective such as maximization of growth LP formulation:
max v
m
wT v
subject to: Av 0 L U v vv
Growth rate, m, 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
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
Download the stoichiometric matrix to the Matlab working directory and load into Matlab
>> v = linprog(-w,[],[],A,b,vb(:,1),vb(:,2)); Optimization terminated.
>> load A.txt
Specify the indices of key fluxes: glucose, ethanol, oxygen, and biomass
Av = 0
101.9302
>> [m n] = size(A); >> b = zeros(m,1);
vo2 =
Objective function
108.3712
>> w = zeros(n,1); >> w(imu) = 1;
Specify flux bounds (all fluxes irreversible, glucose uptake fixed) >> vb = [zeros(n,1) Inf*ones(n,1)];
View predictions for growth, oxygen uptake, and ethanol secretion >> mu = w'*v, vo2 = v(io), ve = v(ie) mu =
>> ig = 22; ie = 20; >> io = 19; imu = 17;
Solve the LP
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
Nonlinear Programming (NLP)
Optimization of a nonlinear objective function with nonlinear equality and/or inequality constraints Standard NLP form: min f (x) x
subject to:
h ( x) 0 g ( x) 0
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
System must have more variables than equality constraints (under-determined problem) Common solvers: CONOPT, NPSOL Non-convex problems can converge to a local optimum
Matlab NLP Solvers: lsqnonlin and fmincon
Nonlinear least-squares: lsqnonlin n
min x
f ( x)
2
i
f 1 ( x) 2 f 2 ( x) 2 f 3 ( x) 2 f n ( x) 2
i 1
f 1 ( x ) f 2 ( x ) where fun is a user-defined function that returns the vector value F ( x) , F ( x ) f 3 ( x ) x0 is the initial guess (starting point), and lb and ub are the bounds on x f ( x ) n x = lsqnonlin(@fun,x0,lb,ub)
Constrained nonlinear multivariable optimization : fmincon
min x
s.t.:
f ( x) c( x) 0
where x, b, beq, lb, and ub are vectors, A and Aeq are matrices, c( x)
ceq( x) 0
and ceq( x) are functions that return vectors, and f ( x) is a function that
A x b
returns a scalar
Aeq x beq lb x ub 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)
Batch Fermentation Example
Parameter estimation problem for penicillin fermentation
Model equations » Batch cell growth is modeled by the logistic law
y k 1 y1 1 1 dt k 2
dy1
where y1 is the cell concentration, k 1 is the growth constant & k 2 is the cessation (limiting nutrient) constant » Penicillin production is modeled as dy2 k 3 y1 k 4 y2 dt where y2 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
Matlab Exercise: Batch Data Sets Batch 1 Time (hours) 0 10 22 34 46 58 70 82 94 106 118 130 142 154 166 178 190
Cell concentration (% dry weight) 0.4 0.99 1.95 2.52 3.09 4.06 4.48 4.25 4.36
Penicillin concentration (units/mL) 0 0 0.0089 0.0732 0.1446 0.523 0.6854 1.2566 1.6118 1.8243 2.217 2.2758 2.8096 2.6846 2.8738 2.8345 2.8828
Batch 2 Cell concentration (% dry weight) 0.18 0.12 0.48 1.46 1.56 1.73 1.99 2.62 2.88 3.43 3.37 3.92 3.96 3.58 3.58 3.34 3.47
Penicillin concentration (units/mL) 0 0 0.0089 0.0642 0.2266 0.4373 0.6943 1.2459 1.4315 2.0402 1.9278 2.1848 2.4204 2.4615 2.283 2.7078 2.6542
Matlab Exercise: Solution
Load & plot the experimental data: >> >> >> >> >> >>
Choose an initial guess, integrate the model, & plot the simulated profiles: >> >> >> >> >> >>
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,':');
Estimate parameter values that minimize the sum of squared errors between the experimental measurements & model predictions: >> >> >> >>
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
View more...
Comments