一、麻雀搜索算法
麻雀搜索算法(sparrow search algorithm,SSA)由Jiankai Xue等人于2020年提出,该算法是根据麻雀觅食并逃避捕食者的行为而提出的群智能优化算法。SSA 主要是受麻雀的觅食行为和反捕食行为的启发而提出的。该算法比较新颖,具有寻优能力强,收敛速度快的优点。麻雀群觅食过程也是发现者-跟随者模型的一种,同时还叠加了侦查预警机制。麻雀中找到食物较好的个体作为发现者,其他个体作为跟随者,同时种群中选取一定比例的个体进行侦查预警,如果发现危险则放弃食物,安全第一。
二、灰色神经网络
灰色神经网络(grey neural network,GNN)是在灰色系统理论中融入了神经网络的思想,具体思想如下:
参考文献:[1]徐涛,孙媛媛,卢敏.基于灰色神经网络的航线客流量预测[J].计算机应用与软件,2020,37(01):31-36.
三、数值实验
在灰色神经网络中,待优化参数包含a,b1,b2,…,bn-1。麻雀搜索算法中每个个体由灰色神经网络中的待定参数构成,适应度函数为真实值与预测值的均方误差(MSE)。
部分训练数据:前10列为输入,最后一列为输出
1.66677305993571 -1.94268993978165 0.489449832737471 -1.51224321671635 1.14535231311110 -0.883256405545140 1.00634032165387 1.55762734750974 1.96790562620673 -1.24217679754850 0.458281833604995
-1.56568720611531 -1.71327282562511 0.801929130822506 0.496389916974755 0.668445525391571 0.826702692326603 -1.48283837432703 0.719507962869618 0.115386965760348 -0.463656965345554 0.996889754058664
-0.194846246222833 0.966172267890872 -1.76631756342904 -1.33133196695539 -0.225851120193687 -0.616905615940662 0.243961483940174 1.16793910165914 -0.285092530832716 0.627025379384089 0.893081104727232
-1.73076907380105 -1.15413520840624 -1.59398989199303 -0.733224399100334 -0.377056823816238 0.376756697235356 1.20674170368505 0.216289501340440 1.95657645323322 0.0523647659372721 0.808645754971443
-1.75904978608269 -0.180680731159226 1.68487432622126 -0.137025816490393 1.87880395000244 -0.178267980620547 0.647178608776808 0.289921092974758 0.702685213947254 -0.0600051287703374 0.688542054537435
0.580596011657764 -1.27942241548387 1.76894005512722 1.33309466787806 1.85463875508363 -1.92786018107102 0.469508030635121 1.26283911384558 1.03964757842660 -1.36954263584738 -0.979718878120857
-0.121732731645297 -1.32525638465858 0.401173627008139 -1.34206476314948 -0.715124529820503 -1.36935993061050 1.60289581833775 1.79138916769928 1.40242263299552 -1.36112583405961 -0.0312387868576671
0.601384746215789 1.96423582569557 0.794044976924123 -1.48515580426318 1.42991437862182 0.462024538106109 0.733754056062351 -0.755143196753921 -0.580789738031025 1.96917462941494 0.302800781724529
-0.406254654205704 0.246667901908159 1.32642019962311 -0.179256155109124 -0.782003245832257 -0.552767126421021 -1.31880875556800 -0.633107037862690 0.657559538774678 0.666387131822449 -0.214427877417769
0.305908624797548 -1.21015438580076 -0.722212870739422 0.624043949348139 0.621803254567230 -0.699534708154122 0.655329056722533 -1.18210906319641 1.02850974995301 -1.45479707043088 0.182516086829478
-1.68336509328530 -0.697422560437838 -1.38136873626895 -0.510417709686711 -1.80957827945015 -0.485310120156396 0.438063930945711 1.08489853239399 0.677635945700612 -1.00309026862856 0.391167478161387
0.954789136073853 1.27711657985055 -1.55240328888337 0.0614937002943408 -1.79678357933547 -0.615724298992505 -1.66347691611382 -0.0810670733911727 0.309427403223358 0.0531080764255498 -0.261153692550195
1.29852704854012 0.862559852885852 -0.448411590110243 0.933381819739321 0.917012176629304 -0.424737491609093 1.90267024739830 1.99560198117783 -0.413703283459984 0.768628974492609 -0.182413551093968
-1.99026840469837 1.66273029934930 -1.87553975966573 -1.02569536155465 -1.26060303738212 0.366050973696060 -1.51659999299615 0.966293176717787 -0.805849798599091 0.183712157472140 0.178386076843652
-0.0819597584213900 -0.463429934668162 -0.572021999285017 0.128831625658504 -1.88789347483496 1.59935031057624 0.617864221325217 0.459555530233958 -1.75586982881390 1.04270484633380 -0.392168056621745
0.437529783257309 -1.29255684440892 -1.24193501812910 -1.41476401223407 -1.29903654974950 -1.39412007560462 1.47533327370397 -1.33418806792125 -0.529313169727564 -1.76189228192461 0.0678601496144694
0.796290910802568 -1.16238547235072 -0.119538332546390 0.940045417979305 -1.64034683963738 -0.676643624986502 0.442371452801224 -0.279820985781024 1.49649106716057 -0.374784863601952 -0.986554756240633
0.465308340202914 1.70155151964922 -1.01130256845789 -1.25980710734642 -1.12048597999356 -0.874963279714825 -0.679307311993994 -1.62550587218355 0.310910591465122 0.848652519010229 0.305124810813379
1.80008913305386 1.08176468279729 0.151524343499310 1.23281630116091 -1.38136481388801 -0.604418149063603 -1.12581001461775 0.229172144395380 -0.834264359612619 -1.59365248222472 -0.00916288186826945
1.22055904669529 -0.407272692685185 0.636727445358434 0.164244480634120 1.43002131075324 -0.689874717330266 0.422199485156880 0.966365923049702 1.51225316650522 1.22783518560361 0.564328788330139
部分代码如下:
close all
clear
clc
global inputnum outputnum TrainNum
inputnum=10;%神经网络输入层神经元个数(输入样本维度)
outputnum=1;%神经网络输出层神经元个数(输出样本维度)
TrainNum=100;%训练集数目
%% 麻雀搜索算法SSA优化灰色神经网络(GNN),目标函数是均方误差MSE
SearchAgents_no=50; % 种群大小(可以修改)
Function_name='F1';
Max_iteration=200; % 最大迭代次数(可以修改)
[lb,ub,dim,fobj]=fun_info(Function_name);% 在fun_info.m中可以查看上下限及目标函数
[fMin,bestX,SSA_curve]=SSA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj); %bestX是GNN的最优参数
save bestX bestX %保留SSA优化GNN得到的最佳参数
%%
save SSA_curve SSA_curve %保留曲线
%% 画出SSA优化GNN的均方误差随迭代次数的图
figure
semilogy(SSA_curve,'Color','g')
title('Objective space')
xlabel('Iteration');
ylabel('MSE');
%axis tight
grid on
box on
legend('SSA')
%%
display(['The best solution obtained by SSA is : ', num2str(bestX)]);
display(['The best optimal value of the objective funciton found by SSA is : ', num2str(fMin)]);%fMin越小说明SSA优化GNN效果越好
实验结果:
均方误差收敛曲线图:
测试样本的真实值与预测值绝对误差图:
四、参考代码