Obtain partial or intermediate (output) results from genetic algorithm
3 views (last 30 days)
Show older comments
Dear all,
I defined a very long function to be optimized by the genetic algorithm. How do I obtain the output of
(predict(Model{1,3},x)-min(Y1))/(Y1_target-min(Y1)) and predict(Model{1,3},x)
when a optimal solution is found?
I gather that you have to access the intermediate results of the genetic algorithm in some way, but I am not sure if that is the right approach and how one should accomplish this when it is the right approach.
%% Loading the Data
load([pwd,'\taguchi_sample_irregular.mat'])
%% Parameters
% Predictors
X = taguchi_multi_variate_samples;
Y = [Payload(:) Work(:) Overflow(:)];
% Response 1 (i.e. payload objective)
Y1 = Payload;
% Response 2 (i.e. work objective)
Y2 = Work;
% Response 3 (i.e. spillage objective)
Y3 = Overflow;
%% Surogate modeling of the data set
% SVM regression model with polynominal kernel functions
Model{1,3} = fitrsvm(X,Y1,'KernelFunction','polynomial', 'KernelScale','auto');
Model{2,3} = fitrsvm(X,Y2,'KernelFunction','polynomial', 'KernelScale','auto');
Model{3,3} = fitrsvm(X,Y3,'KernelFunction','polynomial', 'KernelScale','auto');
%% Optimization
% Target values for each response/objective
Y1_target = max(Y1);
Y2_target = max(Y2);
Y3_target = max(Y3);
fun = @(x) [-((((0.*(predict(Model{1,3},x) < min(Y1))) + ...
((predict(Model{1,3},x)-min(Y1))/(Y1_target-min(Y1))).*(min(Y1) < predict(Model{1,3},x) & predict(Model{1,3},x) < Y1_target) + ...
(1.*(predict(Model{1,3},x) > Y1_target))) .* ...
((0.*(predict(Model{2,3},x) < min(Y2))) + ...
((predict(Model{2,3},x)-min(Y2))/(Y2_target-min(Y2))).*(min(Y2) < predict(Model{2,3},x) & predict(Model{2,3},x) < Y2_target) + ...
(1.*(predict(Model{2,3},x) > Y2_target))) .* ...
((0.*(predict(Model{3,3},x) < min(Y3))) + ...
((predict(Model{3,3},x)-min(Y3))/(Y3_target-min(Y3))).*(min(Y3) < predict(Model{3,3},x) & predict(Model{3,3},x) < Y3_target) + ...
(1.*(predict(Model{3,3},x) > Y3_target))))^(1/3))];
[x, fval, exitflag,output] = ga(fun,4,[],[],[],[],[0 0 0 0], [200 200 200 200]);
2 Comments
Alan Weiss
on 29 Apr 2021
Sorry, I don't quite understand your question. After you get the result x what happens when you try to run
predict(Model{1,3},x)
This was one of your questions, and I am sure that you have tried this, but what happens?
Alan Weiss
MATLAB mathematical toolbox documentation
Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!