optimizeCbModelNLP Optimize constraint-based model using a non-linear objective [currentSol,allObjValues,allSolutions] = optimizeCbModelNLP(model,osenseStr,objFunction,initFunction,nOpt,objArgs, initArgs) INPUT model COBRA model structure OPTIONAL INPUT objFunction Name of the non-linear matlab function to be optimized (the corresponding m-file must be in the current matlab path) initFunction Name of the matlab function used to generate random initial starting points osenseStr Optimization direction ('max' or 'min') nOpt Number of independent optimization runs performed objArgs Cell array of arguments to the 'objFunction' initArgs Cell array of arguments to the 'initFunction' OUTPUT currentSol Solution structure allObjValues Array of objective value of each iteration allSolutions Array of flux distribution of each iteration Markus Herrgard 8/24/07 Modified for new options in solveCobraNLP by Daniel Zielinski 3/19/10
0001 function [currentSol,allObjValues,allSolutions] = ... 0002 optimizeCbModelNLP(model,osenseStr,objFunction,initFunction,nOpt,objArgs,initArgs) 0003 %optimizeCbModelNLP Optimize constraint-based model using a non-linear objective 0004 % 0005 % [currentSol,allObjValues,allSolutions] = 0006 % optimizeCbModelNLP(model,osenseStr,objFunction,initFunction,nOpt,objArgs, 0007 % initArgs) 0008 % 0009 %INPUT 0010 % model COBRA model structure 0011 % 0012 %OPTIONAL INPUT 0013 % objFunction Name of the non-linear matlab function to be optimized (the 0014 % corresponding m-file must be in the current matlab path) 0015 % initFunction Name of the matlab function used to generate random initial 0016 % starting points 0017 % osenseStr Optimization direction ('max' or 'min') 0018 % nOpt Number of independent optimization runs performed 0019 % objArgs Cell array of arguments to the 'objFunction' 0020 % initArgs Cell array of arguments to the 'initFunction' 0021 % 0022 %OUTPUT 0023 % currentSol Solution structure 0024 % allObjValues Array of objective value of each iteration 0025 % allSolutions Array of flux distribution of each iteration 0026 % 0027 % Markus Herrgard 8/24/07 0028 % 0029 % Modified for new options in solveCobraNLP by Daniel Zielinski 3/19/10 0030 0031 if (nargin < 2) 0032 osenseStr = 'max'; 0033 end 0034 if strcmp(osenseStr,'max') 0035 osense = -1; 0036 else 0037 osense = 1; 0038 end 0039 if (nargin < 3) 0040 objFunction = 'NLPobjPerFlux'; 0041 objArgs{1} = osense*model.c; 0042 end 0043 if (nargin < 4) 0044 initFunction = 'randomObjFBASol'; 0045 initArgs{1} = osenseStr; 0046 initArgs{2} = .5; %Minimum fraction of the objective function to select start points from 0047 solOpt = optimizeCbModel(model,osenseStr); 0048 initArgs{3} = initArgs{2}*solOpt.f; %Same as above, sets a starting point within a certain fraction of the maximum linear objective 0049 end 0050 if (nargin < 5) 0051 nOpt = 100; 0052 end 0053 0054 [nMets,nRxns] = size(model.S); 0055 0056 NLPproblem.A = model.S; 0057 NLPproblem.b = model.b; 0058 NLPproblem.lb = model.lb; 0059 NLPproblem.ub = model.ub; 0060 NLPproblem.objFunction = objFunction; 0061 NLPproblem.csense(1:nMets) = 'E'; 0062 0063 % Current best solution 0064 currentSol.f = osense*inf; 0065 allObjValues = zeros(nOpt,1); 0066 allSolutions = zeros(nRxns,nOpt); 0067 0068 %Define additional options for solveCobraNLP 0069 majorIterationLimit = 100000; 0070 printLevel = 3; %3 prints every iteration. 1 does a summary. 0 = silent. 0071 NLPproblem.userParams.model = model; %pass the model into the problem for access by the nonlinear objective function 0072 0073 for i = 1:nOpt 0074 x0 = feval(initFunction,model,initArgs); 0075 NLPproblem.x0 = x0; %x0 now a cell within the NLP problem structure 0076 solNLP = solveCobraNLP(NLPproblem, 'printLevel', printLevel, 'intTol', 1e-7, 'iterationLimit', majorIterationLimit); %New function call 0077 %solNLP = solveCobraNLP(NLPproblem,[],objArgs); Old Code 0078 fprintf('%d\t%f\n',i,osense*solNLP.obj); 0079 allObjValues(i) = osense*solNLP.obj; 0080 allSolutions(:,i) = solNLP.full; 0081 if osense*solNLP.obj > currentSol.f 0082 currentSol.f = osense*solNLP.obj; 0083 currentSol.x = solNLP.full; 0084 currentSol.stat = solNLP.stat; 0085 end 0086 end 0087 0088