# Parameter tunning using GA

2 views (last 30 days)
Dawit Kefale on 28 May 2023
Commented: Dawit Kefale on 29 May 2023
Hello dears,
I need urgent help
I developed a simulink model on matlan 2023 and i tried to obtain the gain parameters using GA algorithm. A code is written by calling the simulink model , but the algorithm can not be excuted.
here is my code that calls the simulink model
function [cost]= optimization_SMC(z)
assignin('base','cz',z(1));
assignin('base','kz',z(2));
assignin('base','cp',z(3));
assignin('base','kp' ,z(4));
assignin('base','ct',z(5));
assignin('base','kt',z(6));
assignin('base','cs',z(7));
assignin('base','ks',z(8));
sim("SMC_designed_Completed_airdrag_pqr.slx");
cost(1)= ITAEZ(length(ITAEZ));
cost(2) = ASEP(length(ASEP));
cost(3) = ITAET(length(ITAET));
cost(4) = ASES(length(ASES));
end
.......
.......and Here is the GA command
% GA parameter
var=8;
lb=[1 1 1 0.4 1.3 1 1 0.3];
ub=[700 700 700 700 700 700 700 700];
%% Set solver options
options = optimoptions('ga','PopulationSize',200,...
'MaxGenerations',inf,'MaxStallGenerations',inf,...
'SelectionFcn','selectionstochunif','CrossoverFcn',...
'FunctionTolerance',1e-9,'ConstraintTolerance',1e-6,...
'Display','iter','PlotFcn','gaplotbestf');
%% Solve
obj_fn = @(z)optimization_SMC(z);
z= ga(obj_fn,var,[],[],[],[],lb,ub,[],options);
........
Here is the error after simulation
>> GA_Tunning
Error using makeState (line 61)
Your fitness function must return a scalar value.
Error in galincon (line 22)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 402)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in GA_Tunning (line 28)
z= ga(obj_fn,var,[],[],[],[],lb,ub,[],options);
How can I solve???

Walter Roberson on 28 May 2023
You cannot fix that. You are calculating four costs each time, but ga() can only handle one cost at a time. ga() will never be able to handle this.
There is a related function, gamultiobj which uses genetic algorithm search to explore the pareto front -- looking for places where the curl of the function is positive in all directions (and so changing any of the parameters by a small value results in a worse outcome.) gamultiobj() does not optimize each function individually: it looks for places that are local minima in all of the functions.
Dawit Kefale on 29 May 2023
Thank you ,.
yes there is a coupling among the parameters , that is the case that makes the system somewhat difficult to be excuteud with the algorithm.
May I get your genuine cooperation Mr. Walter Roberson, if I inbox my compllet work with email.