Returning an additional value that is not part of the fitness function or objective for all population evaluation in GA

1 次查看(过去 30 天)
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:
% the function to be optimized
[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); %%%%% I need this value for every population evaluation
NewObjective = (expectedNPV)
objective = - NewObjective;
% my optimization code
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];
% my output funciton which includes populations, scores but does not include sigma :(
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.

采纳的回答

Matt J
Matt J 2019-8-22
编辑:Matt J 2019-8-22
function run_optimization
allSigmas=[];
[xGA,fval] = ga(fun,nvars,[],[],[],[],lowbond,upbond,[],[],options);
% the function to be optimized
function [objective] = Optimization_Function(x,Pi,Pa,...) .
....
objective = - NewObjective;
allSigmas(end+1) = std(NPV_C); %%%%% I need this value for every population evaluation
end
end
  13 个评论
Matt J
Matt J 2019-8-23
编辑:Matt J 2019-8-23
UseVectorized can be faster than parfor-parallelization when the fitness of all population members can be computed all at once without a for-loop. I assumed that that was not the case for you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by