Collecting a value (Sigma ) over all of the objective function evaluations while using GA optimizer

1 次查看(过去 30 天)
I want to collect all the values of (Sigma ) over all of the objective function evaluations. I'm not really sure how to do this but I have started creating an output function as the following code and I heard this approach will not give me what I need.
I have another approach but I do not want to do it since it will take a lot of time which is based on getting all populations. Then run my main function (Stochastic_Model_Function_TOP) on the populations and store all the results. Please note this takes a lot of time. I want to store that variable (sigma) while my optimizer is running simultaneously. Is there any an efficient way to do it.
% the script to run the optimizer
clear gaoutfunction
options = optimoptions('ga','OutputFcn',@gaoutfunction,'UseParallel',true);
startTime = tic;
fun = @(x)Stochastic_Model_Function_TOP(x,Pi,Pa,LogNormal_G,d,lifetime,Demand,BasePrice,HighPrice,LowPrice,dis_rate_lamda,Geo,Wells_cost,Wells_rate,DStage,Operating_Fields,row);
[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);
%% My Main function to be Optimized
function [objective] = Stochastic_Model_Function_TOP(x,Pi,Pa,LogG,d,lifetime,Demand,BasePrice,HighPrice,...
LowPrice,dis_rate_lamda,Geo,Wells_cost,Wells_rate,DStage,Operating_Fields,row)
.
.
.
..
% just showing the final part. I'm optimizng the objective and I want to show sigma and objective for each population
NPV_C = (Revenue - CAPEX);
expectedNPV = mean(NPV_C);
sigma = std(NPV_C);
NewObjective = (expectedNPV + 0*sigma);
objective = - NewObjective;
end
% the output function (I heard this is not going to work)
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

回答(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