% -----------------------------------------------------------------------------------------------------------
% Dung Beetle Optimizer: (DBO) (demo)
% Programmed by Jian-kai Xue
% Updated 28 Nov. 2022.
%
% This is a simple demo version only implemented the basic
% idea of the DBO for solving the unconstrained problem.
% The details about DBO are illustratred in the following paper.
% (To cite this article):
% Jiankai Xue & Bo Shen (2022) Dung beetle optimizer: a new meta-heuristic
% algorithm for global optimization. The Journal of Supercomputing, DOI:
% 10.1007/s11227-022-04959-6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% qq群:439115722
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear
%读取数据
load data input output
%节点个数
inputnum=2;
hiddennum=5;
outputnum=1;
%训练数据和预测数据
input_train=input(1:1900,:)';
input_test=input(1901:2000,:)';
output_train=output(1:1900)';
output_test=output(1901:2000)';
%选连样本输入输出数据归一化
[inputn,inputps]=mapminmax(input_train);
[outputn,outputps]=mapminmax(output_train);
%构建网络
net=newff(inputn,outputn,hiddennum);
% 参数初始化
dim=21;
maxgen=100; % 进化次数
sizepop=30; %种群规模
popmax=5;
popmin=-5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P_percent = 0.2; % The population size of producers accounts for "P_percent" percent of the total population size
pNum = round( sizepop * P_percent ); % The population size of the producers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:sizepop
pop(i,:)=5*rands(1,21);
% V(i,:)=rands(1,21);
fitness(i)=fun(pop(i,:),inputnum,hiddennum,outputnum,net,inputn,outputn);
end
XX= pop;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pFit = fitness;
[ fMin, bestI ] = min( fitness ); % fMin denotes the global optimum fitness value
bestX = pop( bestI, : ); % bestX denotes the global optimum position corresponding to fMin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 蜣螂优化算法 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for t = 1 : maxgen
[ ans, sortIndex ] = sort( pFit );% Sort.
[fmax,B]=max( pFit );
worse= pop(B,:);
r2=rand(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1 : pNum
if(r2<0.9)
r1=rand(1);
a=rand(1,1);
if (a>0.1)
a=1;
else
a=-1;
end
pop( i , : ) = pop( i , :)+0.3*abs(pop(i , : )-worse)+a*0.1*(XX( i , :)); % Equation (1)
else
aaa= randperm(180,1);
if ( aaa==0 ||aaa==90 ||aaa==180 )
pop( i , : ) = pop( i , :);
end
theta= aaa*pi/180;
pop( i , : ) = pop( i , :)+tan(theta).*abs( pop(i , : )-XX( i , :)); % Equation (2)
end
fitness( i )=fun(pop(i ,:),inputnum,hiddennum,outputnum,net,inputn,outputn);
end
[ fMMin, bestII ] = min( fitness );
bestXX = pop( bestII, : );
R=1-t/maxgen; %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xnew1 = bestXX.*(1-R);
Xnew2 =bestXX.*(1+R); %%% Equation (3)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xnew11 = bestX.*(1-R);
Xnew22 =bestX.*(1+R); %%% Equation (5)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = ( pNum + 1 ) :12 % Equation (4)
pop( i, : )=bestXX+((rand(1,dim)).*(pop( i , : )-Xnew1)+(rand(1,dim)).*(pop( i , : )-Xnew2));
fitness( i )=fun(pop(i ,:),inputnum,hiddennum,outputnum,net,inputn,outputn);
end
for i = 13: 19 % Equation (6)
pop( i, : )=pop( i , : )+((randn(1)).*(pop( i , : )-Xnew11)+((rand(1,dim)).*(pop( i , : )-Xnew22)));
fitness( i )=fun(pop(i ,:),inputnum,hiddennum,outputnum,net,inputn,outputn);
end
for j = 20 : sizepop % Equation (7)
pop( j,: )=bestX+randn(1,dim).*((abs(( pop(j,: )-bestXX)))+(abs(( pop(j,: )-bestX))))./2;
fitness( j )=fun(pop(j ,:),inputnum,hiddennum,outputnum,net,inputn,outputn);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XX=pop;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1 : sizepop
if ( fitness( i ) < pFit( i ) )
pFit( i ) = fitness( i );
pop(i,:) = pop(i,:);
end
if( pFit( i ) < fMin )
fMin= pFit( i );
bestX =pop( i, : );
end
end
yy(t)=fMin;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 迭代寻优
x=bestX
%% 结果分析
plot(yy)
title(['适应度曲线 ' '终止代数=' num2str(maxgen)]);
xlabel('进化代数');ylabel('适应度');
%% 把最优初始阀值权值赋予网络预测
% %用蜣螂优化算法优化的BP网络进行值预测
w1=x(1:inputnum*hiddennum);
B1=x(inputnum*hiddennum+1:inputnum*hiddennum+hiddennum);
w2=x(inputnum*hiddennum+hiddennum+1:inputnum*hiddennum+hiddennum+hiddennum*outputnum);
B2=x(inputnum*hiddennum+hiddennum+hiddennum*outputnum+1:inputnum*hiddennum+hiddennum+hiddennum*outputnum+outputnum);
net.iw{1,1}=reshape(w1,hiddennum,inputnum);
net.lw{2,1}=reshape(w2,outputnum,hiddennum);
net.b{1}=reshape(B1,hiddennum,1);
net.b{2}=B2;
%% 训练
%网络进化参数
net.trainParam.epochs=100;
net.trainParam.lr=0.1;
net.trainParam.goal=0.00001;
%网络训练
[net,tr]=train(net,inputn,outputn);
%%预测
%数据归一化
inputn_test=mapminmax('apply',input_test,inputps);
an=sim(net,inputn_test);
test_simu=mapminmax('reverse',an,outputps);
error=test_simu-output_test;
figure(2)
plot(error)
title('仿真预测误差','fontsize',12);
xlabel('仿真次数','fontsize',12);ylabel('误差百分值','fontsize',12);
蜣螂优化算法(DBO)优化bp网络
5星 · 超过95%的资源 需积分: 0 13 浏览量
更新于2022-12-11
11
收藏 48KB RAR 举报
蜣螂优化算法(DBO)是一种受到自然界蜣螂行为启发的新型全局优化算法,它在解决复杂优化问题方面表现出色,特别是在神经网络如BP(BackPropagation)网络的权重优化上。BP网络是一种广泛应用的多层前馈神经网络,用于非线性函数拟合和分类任务。然而,BP网络在训练过程中易陷入局部最小值,导致优化效果不佳。DBO算法的引入为解决这一问题提供了新思路。
蜣螂,又称屎壳郎,以其在寻找食物源时的独特滚动行为而闻名。DBO算法模仿了这种行为,通过搜索空间中的滚动操作来探索潜在的最优解。在算法中,每个个体代表一个可能的解决方案,就像蜣螂滚动粪球一样,个体在解决方案空间中滚动,寻找最佳位置。在滚动过程中,个体的适应度评价、滚动距离和滚动方向等因素都会影响其滚动行为,从而驱动算法向全局最优解靠近。
在BP神经网络中,DBO算法可以用于调整网络的权重和阈值,以提高网络的学习效率和泛化能力。将网络的参数初始化为随机值,然后用DBO算法进行优化。在每一代迭代中,DBO会更新这些参数,使其逐渐接近最优状态。算法通过评估网络在训练集上的性能来确定参数的优劣,从而决定滚动的方向和距离。
DBO算法的优势在于其自然启发式搜索策略,能够有效地跳出局部最优,避免早熟现象。同时,由于其简单的数学模型,实现起来相对容易,适用于各种复杂问题。在实际应用中,DBO与BP网络结合,能有效提高神经网络的训练速度,降低误差,提升预测或分类的准确率。
在"蜣螂优化算法(DBO)优化bp网络"这个主题中,我们可以深入研究以下几个方面:
1. **DBO算法原理**:详细阐述DBO算法的基本思想,包括个体的初始化、滚动策略、适应度函数以及种群更新规则。
2. **DBO与BP网络结合**:探讨如何将DBO算法应用于BP网络的权重和阈值优化,包括参数设置、迭代过程和性能指标。
3. **优化效果分析**:对比DBO优化前后的BP网络性能,通过实验结果展示优化效果,如学习曲线、误差变化等。
4. **应用场景**:介绍DBO-BP网络组合在图像识别、语音识别、时间序列预测等领域的应用实例。
5. **算法改进与扩展**:讨论DBO算法的可能改进策略,如引入精英策略、自适应调整滚动参数等,以及与其他优化算法的融合,如遗传算法、粒子群优化等。
6. **未来研究方向**:探讨DBO算法在深度学习、强化学习等现代机器学习框架中的潜在应用,以及可能遇到的挑战和解决策略。
"蜣螂优化算法(DBO)优化bp网络"这一主题涵盖了生物启发式算法、神经网络优化、全局优化等多个IT领域的知识点,不仅具有理论研究价值,也具有广阔的实际应用前景。通过深入研究和实践,我们可以进一步挖掘DBO算法的潜力,提高人工智能系统的性能。
智聚客
- 粉丝: 25
- 资源: 9
最新资源
- 社区二手物品交易小程序ssm.zip
- 基于java+springboot+mysql+微信小程序的图书馆座位预约系统 源码+数据库+论文(高分毕业设计).zip
- “返家乡”高校暑期社会实践微信小程序设计与开发ssm.zip
- 校园失物招领小程序ssm.zip
- 基于小程序的社区超市管理系统springboot.zip
- 基于java+springboot+mysql+微信小程序的微信小程序的居民健康监测系统 源码+数据库+论文(高分毕业设计).zip
- 基于java+springboot+mysql+微信小程序的网上花店微信小程序 源码+数据库+论文(高分毕业设计).zip
- 校园反诈骗微信小程序的设计与开发ssm.zip
- 高校学生事务管理系统ssm.zip
- 健身达人微信小程序的设计与实现ssm.zip
- 发布.zip
- 基于微信小程序的电影院订票选座系统ssm.zip
- 基于微信平台的文玩销售小程序ssm.zip
- 基于微信小程序的教学质量评价系统ssm.zip
- 澡堂预订的微信小程序的设计和利用ssm.zip
- 微信小程序软件缺陷管理系统ssm.zip