1 简介

Biogeography-Based Optimizer (BBO) is employed as a trainer for Multi-Layer Perceptron (MLP). The current source codes are the demonstration of the BBO-MLP trainer for solving the Iris classification problem. There are also other trainers in this submission: Particle Swarm Optimization (PSO), Ant Colony Optimization (ACO), Genetic Algorithm (GA), Evolutionary Strategy (ES), and Probability-Based Incremental Learning (PBIL). The classification accuracy of BBO-MLP is calculated at the end of main.m file and compared to those of PSO, ACO, ES, GA, and PBIL. The convergence curve and classification accuracy of each algorithm are drawn at the end.

【优化求解】基于粒子群算法集合生物地理算法CPSOBBO求解MLP问题matlab源码_生物地理算法

【优化求解】基于粒子群算法集合生物地理算法CPSOBBO求解MLP问题matlab源码_生物地理算法_02

【优化求解】基于粒子群算法集合生物地理算法CPSOBBO求解MLP问题matlab源码_生物地理算法_03

2 部分代码

%%%%% Multi-layer Perceptron (MLP) Training using CPSOGSA %%%%%
  • 1.
clear all
  • 1.
close all
  • 1.
clc
  • 1.
Q=1; % ACO Parameter
  • 1.
tau0=10; % Initial Phromone (ACO)
  • 1.
alpha=0.3; % Phromone Exponential Weight (ACO)
  • 1.
rho=0.1; % Evaporation Rate (ACO)
  • 1.
beta_min=0.2; % Lower Bound of Scaling Factor (DE)
  • 1.
beta_max=0.8; % Upper Bound of Scaling Factor (DE)
  • 1.
pCR=0.2; % Crossover Probability (DE)
  • 1.
Runno=10;
  • 1.
SearchAgents_no=20; % Number of search agents
  • 1.
% classification datasets
  • 1.
Function_name='F2'; %MLP_Baloon dataset
  • 1.
% Load details of the selected data set
  • 1.
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
  • 1.
ElitistCheck=1;
  • 1.
min_flag=1;
  • 1.
Rpower=1;
  • 1.
Max_iteration=500; % Maximum numbef of iterations
  • 1.
%
  • 1.
load baloon.txt
  • 1.
x=sortrows(baloon,2);
  • 1.
%I2=x(1:150,1:4);
  • 1.
I2(:,1)=x(1:20,1);
  • 1.
I2(:,2)=x(1:20,2);
  • 1.
I2(:,3)=x(1:20,3);
  • 1.
I2(:,4)=x(1:20,4);
  • 1.
T=x(1:20,5);
  • 1.
Hno=9;
  • 1.
dim = 6*9+1;
  • 1.
for i=1:1:Runno
  • 1.
[Fbest,Lbest,BestChart]=GSA(SearchAgents_no,Max_iteration,ElitistCheck,min_flag,Rpower,lb,ub,dim,fobj);
  • 1.
BestSolutions1(i) = Fbest;
  • 1.
[gBestScore,gBest,GlobalBestCost]= CPSOGSA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
  • 1.
BestSolutions4(i) = gBestScore;
  • 1.
[BestSolACO,BestAnt,BestCostACO] = ACO(SearchAgents_no, Max_iteration,Q,tau0,alpha,rho,lb,ub,dim,fobj);
  • 1.
BestSolutions5(i) = BestSolACO.Cost;
  • 1.
[BestCost,Best_Hab,BestSol] = bbo( SearchAgents_no, Max_iteration,lb,ub,dim,fobj);
  • 1.
BestSolutions6(i) = BestSol.Cost;
  • 1.
[BestSolDE,DBestSol,BestCostDE] = DE(SearchAgents_no, Max_iteration,beta_min,beta_max,pCR,lb,ub,dim,fobj);
  • 1.
BestSolutions7(i) = BestSolDE.Cost ;
  • 1.
Rrate=0;
  • 1.
W=Lbest(1:45);
  • 1.
B=Lbest(46:55);
  • 1.
W=gBest(1:45);
  • 1.
B=gBest(46:55);
  • 1.
W=BestAnt(1:45);
  • 1.
B=BestAnt(46:55);
  • 1.
W=Best_Hab(1:45);
  • 1.
B=Best_Hab(46:55);
  • 1.
W=DBestSol(1:45);
  • 1.
B=DBestSol(46:55);
  • 1.
for pp=1:20
  • 1.
actualvalue=my_simulate(4,9,1,W,B,I2(pp,:));
  • 1.
if(T(pp)==1)
  • 1.
if (actualvalue>=0.95)
  • 1.
Rrate=Rrate+1;
  • 1.
end
  • 1.
end
  • 1.
if(T(pp)==0)
  • 1.
if (actualvalue(1)<0.05)
  • 1.
Rrate=Rrate+1;
  • 1.
end
  • 1.
end
  • 1.
end
  • 1.
end
  • 1.
% % %
  • 1.
figure
  • 1.
semilogy(1:Max_iteration,BestChart,'DisplayName','GSA','Color','g','Marker','o','LineStyle','-','LineWidth',2,...
  • 1.
'MarkerEdgeColor','g','MarkerFaceColor',[.49 1 .63],'MarkerSize',5);
  • 1.
hold on
  • 1.
semilogy(1:Max_iteration,GlobalBestCost,'DisplayName','CPSOGSA', 'Color', 'r','Marker','diamond','LineStyle','-','LineWidth',2,...
  • 1.
'MarkerEdgeColor','r','MarkerFaceColor',[.49 1 .63],'MarkerSize',5);
  • 1.
% semilogy(1:Max_iteration,BestCostACO,'DisplayName','ACO','Color','c','Marker','square','LineStyle','-','LineWidth',2,...
  • 1.
% 'MarkerEdgeColor','c','MarkerFaceColor',[.49 1 .63],'MarkerSize',5);
  • 1.
% semilogy(1:Max_iteration,BestCost,'DisplayName','BBO','Color','b','Marker','*','LineStyle','-','LineWidth',2,...
  • 1.
% 'MarkerEdgeColor','b','MarkerFaceColor',[.49 1 .63],'MarkerSize',5);
  • 1.
% semilogy(1:Max_iteration,BestCostDE,'DisplayName','DE','Color','y','Marker','+','LineStyle','-','LineWidth',2,...
  • 1.
% 'MarkerEdgeColor','y','MarkerFaceColor',[.49 1 .63],'MarkerSize',5);
  • 1.
title ('\fontsize{12}\bf XOR Dataset');
  • 1.
% title ('\fontsize{12}\bf Baloon Dataset');
  • 1.
% title ('\fontsize{12}\bf Iris Dataset');
  • 1.
% title ('\fontsize{12}\bf Cancer Dataset');
  • 1.
% title ('\fontsize{12}\bf Heart Dataset');
  • 1.
% title ('\fontsize{12}\bf Sigmoid Dataset');
  • 1.
% title ('\fontsize{12}\bf Cosine Dataset');
  • 1.
% title ('\fontsize{12}\bf Sine Dataset');
  • 1.
xlabel('\fontsize{12}\bf Iteration');
  • 1.
ylabel('\fontsize{12}\bf log(MSE)');
  • 1.
legend('\fontsize{10}\bf GSA','\fontsize{10}\bf CPSOGSA')
  • 1.
% legend('\fontsize{10}\bf GSA','\fontsize{10}\bf CPSOGSA','\fontsize{10}\bf ACO','\fontsize{10}\bf BBO','\fontsize{10}\bf DE',1);
  • 1.
axis tight
  • 1.
box on
  • 1.
img =gcf; %获取当前画图的句柄
  • 1.
print(img, '-dpng', '-r600', './img.png') %即可得到对应格式和期望dpi的图像
  • 1.

3 仿真结果

【优化求解】基于粒子群算法集合生物地理算法CPSOBBO求解MLP问题matlab源码_生物地理算法_04

4 参考文献

S. Mirjalili, S. M. Mirjalili, A. Lewis, Let A Biogeography-Based Optimizer Train Your Multi-Layer Perceptron, Information Sciences, In press, 2014

【优化求解】基于粒子群算法集合生物地理算法CPSOBBO求解MLP问题matlab源码_生物地理算法_05