Particle Swarm Optimization cost value is different from real value
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sam Chak
2023-7-2
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?
回答(1 个)
Song-Hyun Ji
2023-7-3
2 个评论
Song-Hyun Ji
2023-7-7
올려주신 코드만으로는 문제의 원인 파악 및 해결책을 찾을 수가 없습니다. 동일 문제 재현되는 샘플 코드와 함께 아래의 링크를 통해 문제 리포트하여 주시기 바랍니다.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!