Particle Swarm Optimization cost value is different from real value

조회 수: 2 (최근 30일)
종원 이
종원 이 2023년 7월 2일
댓글: Song-Hyun Ji 2023년 7월 7일
Hello,
I am trying to find optimal controller gain in Simulink file using particle swarm optimization.
The Entire structure follows:
  1. 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.
  2. 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
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?
종원 이
종원 이 2023년 7월 6일
Oh, I am sorry I made a mistake.
Yes, you are right, I editted the code like below
addAttachedFiles(gcp,'Plant_test_version.slx');
But result was the same.

댓글을 달려면 로그인하십시오.

답변 (1개)

Song-Hyun Ji
Song-Hyun Ji 2023년 7월 3일
I am not sure if you consider the solution as the global optimum like this example. If you think there is a product problem, please contact the Technical Support team with the reproducible sample files.
  댓글 수: 2
종원 이
종원 이 2023년 7월 6일
Yes, I tried some example function, and it worked well so I think It's not a product problem.
That's why I am suspecting the reason problem occurs is parallel computing process in Simulink file.
Song-Hyun Ji
Song-Hyun Ji 2023년 7월 7일
올려주신 코드만으로는 문제의 원인 파악 및 해결책을 찾을 수가 없습니다. 동일 문제 재현되는 샘플 코드와 함께 아래의 링크를 통해 문제 리포트하여 주시기 바랍니다.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by