Can anyone please help by showing the code how can I return an additional value (Sigma) that is not part of my fitness function (Mean). I know how to return all the populations, scores but I'm not sure how to return this additional value (sigma). I see many have asked this question but no one showed in a code rather than just directing us to use the nested functions. Here is my code:
[objective] = Optimization_Function(x,Pi,Pa,LogG,d,lifetime,Demand,BasePrice,HighPrice,...
LowPrice,dis_rate_lamda,Geo,Wells_cost,Wells_rate,DStage,Operating_Fields,row,Amt,FOPEX,VOPEX)
.
.
.
.
expectedNPV = mean(NPV_C);
sigma = std(NPV_C);
NewObjective = (expectedNPV)
objective = - NewObjective;
clear gaoutfunction
options = optimoptions('ga','OutputFcn',@gaoutfunction,'UseParallel',true);
startTime = tic;
fun = @(x)Optimization_Function(x,Pi,Pa,LogNormal_G,d_cline,lifetime,Demand,BasePrice,...
HighPrice,LowPrice,dis_rate_lamda,Geo,Wells_cost,Wells_rate,DStage,Operating_Fields,row,Amt,FOPEX,VOPEX);
[xGA,fval] = ga(fun,nvars,[],[],[],[],lowbond,upbond,[],[],options);
time_ga_parallel = toc(startTime);
record = gaoutfunction();
gapopulationhistory = vertcat(record.Population);
gabesthistory = vertcat(record.Best);
gascorehistory = vertcat(record.Score);
Results = [gapopulationhistory gascorehistory];
function [state,options,optchanged] = gaoutfunction(options,state,flag)
persistent state_record
if isempty(state_record)
state_record = struct('Population', {}, 'Best', {}, 'Score', {});
end
if nargin == 0
state = state_record;
options = [];
optchanged = [];
else
state_record(end+1) = struct('Population', state.Population, 'Best', state.Best', 'Score', state.Score);
optchanged = false;
end
end
Can anyone please show me how to return sigma as I’m returning all the populations and their scores. Please note the score here is only the objective which is the mean. The sigma value is not part of the optimization but I need it to save the time rather than running the model again to evaluate it. Please help.
0 Comments
Sign in to comment.