FAQ4-How to compare the convergence curves of two algorithms

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_39286218/article/details/80769186

文件目录:

main.m

PSO_1.m

PSO_2.m

OptimizationProblem.m

main.m
clear
close all
clc

%Problem preparation
problem.nVar = 5;
problem.ub = [5,5,5,5,5];
problem.lb = [-5,-5,-5,-5,-5];
problem.fobj = @OptimizationProblem;

%PSO parameters
noP = 10;
maxIter = 100;
visFlag = 0;
 
RunNo = 20;
BestSolutions_PSO1 = zeros(1, RunNo);
BestSolutions_PSO2 = zeros(1, RunNo);

for k = [1 : RunNo]
    disp(['Run # ', num2str(k)])
    %PSO_1
    [GBEST,cgCurve1] = PSO_1(noP,maxIter, problem, visFlag);
    BestSolutions1(k) = GBEST.O;
    %PSO_2
    [GBEST,cgCurve2] = PSO_2(noP,maxIter, problem, visFlag);
    BestSolutions2(k) = GBEST.O;
end 

PSO1_Ave = mean(BestSolutions1);
PSO1_Std = std(BestSolutions1);

PSO2_Ave = mean(BestSolutions2);
PSO2_Std = std(BestSolutions2);

disp('Average(Std) obtained by PSO1')
disp([num2str(PSO1_Ave), '(',num2str(PSO1_Std), ') '])

disp('Average(Std) obtained by PSO2')
disp([num2str(PSO2_Ave), '(',num2str(PSO2_Std), ') '])

disp('Wilcoxon ranksum test')
p = ranksum(BestSolutions1,BestSolutions2);

%significant level is 5%
if p < 0.05
    disp(['P-value = ', num2str(p)])
    disp('The results of the better algorithm IS statistically significant')
else
    disp(['P-value = ', num2str(p)])
    disp('The results of the better algorithm IS NOT statistically significant')
end 

%show both curves in 2 subplots 
figure
subplot(1, 2, 1)
iter = 1 : maxIter;
semilogy(iter, cgCurve1)
xlabel('Iteration#')
ylabel(['Average obj values in ', num2str(RunNo), 'runs'])
title('PSO 1')

subplot(1, 2, 2)
iter = 1 : maxIter;
semilogy(iter, cgCurve2)
xlabel('Iteration#')
ylabel(['Average obj values in ', num2str(RunNo), 'runs'])
title('PSO 2')

%show both curves in 1 plot
figure
semilogy(iter, cgCurve1)
hold on 
semilogy(iter, cgCurve2, 'r')
xlabel('Iteration#')
ylabel(['Average obj values in ', num2str(RunNo), 'runs'])
title('PSO algorithms')
legend('PSO1','PSO2')

运行结果:



猜你喜欢

转载自blog.csdn.net/sinat_39286218/article/details/80769186