Clear Filters
Clear Filters

Parameter tunning using GA

5 views (last 30 days)
Dawit Kefale
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',...
'crossoverheuristic','MutationFcn','mutationadaptfeasible',...
'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???

Accepted Answer

Walter Roberson
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.
  3 Comments
Walter Roberson
Walter Roberson on 28 May 2023
"it doesn't work" is not something that we can act on. You have not posted your code and model for us to test, and you have not described what exactly you are hoping for.
If you want to find *z *p *t *s parameter values that minimize all four functions simultaneously, then that is not necessarily impossible as the functions just might happen to be such that the same set of parameters minimizes all of them (for example, all parameters zero might happen to be a provable minimum for all four functions.) It is, however, not common. Most of the time when you have multiple functions to minimize, the values that minimize one function are not the values that minimize a different function.
Now, it might happen to be the case that the first function is only affected by cz and kz, and the second function is only affected by cp and kp, and so on. If so then you should be able to call gamultiobj() with two outputs, then use min() to locate the minimum of the second output, and retrieve the corresponding row of the first output, and that would be the simultaneous minimization .
But if the inputs affect multiple outputs, then to get simultaneous minimization, you might need to add extra inputs.
Dawit Kefale
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!