Particle Swarm Optimization cost value is different from real value
3 views (last 30 days)
Show older comments
Hello,
I am trying to find optimal controller gain in Simulink file using particle swarm optimization.
The Entire structure follows:
- Generate a cost function. Input of this cost function is controller gain. If input is applied, this parameter is applied to simulink file and run by sim() function. After simulation is executed, the tracking error signal is saved in workspace and error is calculated. the output value of this cost function is this norm of tracking error vector.
- Execute particle swarm optimization with 1. cost function with parallel computing.
For that, I wrote below code
delete(gcp('nocreate')); %First delete processor if there is any.
parpool('AttachedFiles',{'Plant_test_version.slx'}); % Attach file to processor
spmd
load_system('Plant_test_version'); % Load simulink file to processors.
end
addAttachedFiles(gcp,'Plant_parallel.slx'); % I am not sure this line is needed, but to make sure, I wrote this line.
option1 = optimoptions('particleswarm','UseParallel',true,'UseVectorized',false,'Display','iter','PlotFcn','pswplotbestf');
[sol1,fval1,exitflag1,output1] = particleswarm(@cost_function,26,0.05*ones(26,1),15*ones(26,1),option1); % # of Input parameter is 26.
This code runs well.
The problem is, the cost value that particle swarm give is different when I actually put the solution in cost function.
To make sure what I mean, I will explain it again.
If pso results was,
sol1 = [1 2 3]
fval1 = 100
Then If I put sol1 value into @cost_function, then the output should be 100 but it isn't.
I suspect this is because of parallel computing, but I totally cannot figure out why this occurs.
Can anyone help me?
Thank you,
2 Comments
Sam Chak
on 2 Jul 2023
This is strange. Could you confirm whether the model in Plant_test_version.slx is exactly the same as the one in Plant_parallel.slx? Also, did you run the test version for the same simulation time as the original model?
Answers (1)
Song-Hyun Ji
on 3 Jul 2023
2 Comments
Song-Hyun Ji
on 7 Jul 2023
올려주신 코드만으로는 문제의 원인 파악 및 해결책을 찾을 수가 없습니다. 동일 문제 재현되는 샘플 코드와 함께 아래의 링크를 통해 문제 리포트하여 주시기 바랍니다.
See Also
Categories
Find more on Particle Swarm 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!