单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)

一、麻雀搜索算法SSA

单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)_第1张图片

二、小波神经网络WNN

WNN是一种以小波基函数为隐含层节点、激励函数误差反向传播的神经网络,如下图所示:

单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)_第2张图片

图中X为WNN的输入样本,Y为WNN的预测输出,ωij和ωjk分别为连接输入层与隐含层、隐含层与输出层的权值,ψ(x)为小波基函数。本文所采用的小波基函数为Morlet小波函数,其表达式为:
单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)_第3张图片

参考文献:钱建国,樊意广.基于改进小波神经网络的GPS高程拟合研究[J].大地测量与地球动力学,2022,42(03):253-257.DOI:10.14075/j.jgg.2022.03.007.

三、数值实验

求解定义在[0,1]x[0,1]的如下偏微分方程:
单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)_第4张图片
小波神经网络WNN中待优化参数为:输入层与隐含层的权值、小波基函数的伸缩因子、小波基函数的平移因子、隐含层与输出层的权值。麻雀搜索算法SSA的个体由WNN中输入层与隐含层的权值、小波基函数的伸缩因子、小波基函数的平移因子、隐含层与输出层的权值构成,目标函数为真实值与预测值的均方误差MSE。构建结构为2-1-2的小波神经网络WNN,通过SSA优化WNN结构参数,使其MSE最小。

部分数据如下:前2列为输入,后1列为输出

0	0	0
0	0.0300000000000000	0
0	0.0600000000000000	0
0	0.0900000000000000	0
0	0.120000000000000	0
0	0.150000000000000	0
0	0.180000000000000	0
0	0.210000000000000	0
0	0.240000000000000	0
0	0.270000000000000	0
0	0.300000000000000	0
0	0.330000000000000	0
0	0.360000000000000	0
0	0.390000000000000	0
0	0.420000000000000	0
0	0.450000000000000	0
0	0.480000000000000	0
0	0.510000000000000	0
0	0.540000000000000	0
0	0.570000000000000	0
0	0.600000000000000	0
0	0.630000000000000	0
0	0.660000000000000	0
0	0.690000000000000	0
0	0.720000000000000	0
0	0.750000000000000	0
0	0.780000000000000	0
0	0.810000000000000	0
0	0.840000000000000	0
0	0.870000000000000	0
0	0.900000000000000	0
0	0.930000000000000	0
0	0.960000000000000	0
0	0.990000000000000	0
0.0300000000000000	0	0.000366462568482550
0.0300000000000000	0.0300000000000000	0.000769143358330812
0.0300000000000000	0.0600000000000000	0.00121162188808696
0.0300000000000000	0.0900000000000000	0.00169783144719936
0.0300000000000000	0.120000000000000	0.00223209405990187
0.0300000000000000	0.150000000000000	0.00281915890464245
0.0300000000000000	0.180000000000000	0.00346424453058009
0.0300000000000000	0.210000000000000	0.00417308524642171
0.0300000000000000	0.240000000000000	0.00495198209395963
0.0300000000000000	0.270000000000000	0.00580785885942477
0.0300000000000000	0.300000000000000	0.00674832362055272
0.0300000000000000	0.330000000000000	0.00778173637646831
0.0300000000000000	0.360000000000000	0.00891728336156557
0.0300000000000000	0.390000000000000	0.0101650587039756
0.0300000000000000	0.420000000000000	0.0115361541545026
0.0300000000000000	0.450000000000000	0.0130427576836482
0.0300000000000000	0.480000000000000	0.0146982618231750
0.0300000000000000	0.510000000000000	0.0165173827152819
0.0300000000000000	0.540000000000000	0.0185162909276440
0.0300000000000000	0.570000000000000	0.0207127551971631
0.0300000000000000	0.600000000000000	0.0231263003801975
0.0300000000000000	0.630000000000000	0.0257783810133250
0.0300000000000000	0.660000000000000	0.0286925720274610
0.0300000000000000	0.690000000000000	0.0318947783106298
0.0300000000000000	0.720000000000000	0.0354134649822397
0.0300000000000000	0.750000000000000	0.0392799104258209
0.0300000000000000	0.780000000000000	0.0435284843294899
0.0300000000000000	0.810000000000000	0.0481969532057037
0.0300000000000000	0.840000000000000	0.0533268161061360
0.0300000000000000	0.870000000000000	0.0589636735159202
0.0300000000000000	0.900000000000000	0.0651576327064397
0.0300000000000000	0.930000000000000	0.0719637531499389
0.0300000000000000	0.960000000000000	0.0794425359553407
0.0300000000000000	0.990000000000000	0.0876604616759758
0.0600000000000000	0	0.00139371603043500
0.0600000000000000	0.0300000000000000	0.00219550338693351
0.0600000000000000	0.0600000000000000	0.00307653297569092
0.0600000000000000	0.0900000000000000	0.00404463646344842
0.0600000000000000	0.120000000000000	0.00510841953608058
0.0600000000000000	0.150000000000000	0.00627733839643924
0.0600000000000000	0.180000000000000	0.00756178382263061
0.0600000000000000	0.210000000000000	0.00897317353393848
0.0600000000000000	0.240000000000000	0.0105240536854545
0.0600000000000000	0.270000000000000	0.0122282103936237
0.0600000000000000	0.300000000000000	0.0141007922840807
0.0600000000000000	0.330000000000000	0.0161584451511311
0.0600000000000000	0.360000000000000	0.0184194599258962
0.0600000000000000	0.390000000000000	0.0209039352684422
0.0600000000000000	0.420000000000000	0.0236339562292122
0.0600000000000000	0.450000000000000	0.0266337905679204
0.0600000000000000	0.480000000000000	0.0299301044750322
0.0600000000000000	0.510000000000000	0.0335521996134251
0.0600000000000000	0.540000000000000	0.0375322735873459
0.0600000000000000	0.570000000000000	0.0419057061540318
0.0600000000000000	0.600000000000000	0.0467113737221917
0.0600000000000000	0.630000000000000	0.0519919949329961
0.0600000000000000	0.660000000000000	0.0577945103955199
0.0600000000000000	0.690000000000000	0.0641704999521916
0.0600000000000000	0.720000000000000	0.0711766411834129
0.0600000000000000	0.750000000000000	0.0788752132270975
0.0600000000000000	0.780000000000000	0.0873346503916937
0.0600000000000000	0.810000000000000	0.0966301504838772
0.0600000000000000	0.840000000000000	0.106844343258475
0.0600000000000000	0.870000000000000	0.118068024932619

部分代码如下:WNN隐藏层神经元个数可以自己修改

close all
clear
clc
global inputnum hiddennum outputnum TrainNum 
inputnum=2;%神经网络输入层神经元个数(输入样本维度)
hiddennum=8;%神经网络隐藏层神经元个数(可以自己修改) 
outputnum=1;%神经网络输出层神经元个数(输出样本维度)
TrainNum=1156;%训练集数目 
%% 麻雀搜索算法SSA优化小波神经网络WNN,目标函数是均方误差MSE
SearchAgents_no=50; %  种群大小(可以修改)
Function_name='F1'; 
Max_iteration=1000; %  最大迭代次数(可以修改)
[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是WNN的最优参数
save bestX bestX %保留SSA优化WNN得到的最佳参数
%%
save SSA_curve SSA_curve %保留曲线
%% 画出SSA优化WNN的均方误差随迭代次数的图
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优化WNN效果越好



SSA求解结果如下:

MSE收敛图:
单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)_第5张图片

每个样本点的预测值与真实值如下图所示:

单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)_第6张图片
每个样本点的预测值与真实值的绝对误差图如下所示:
单目标应用:基于麻雀搜索算法优化小波神经网络的偏微分方程求解(提供MATLAB代码)_第7张图片

由此可见SSA优化WNN用于偏微分方程的求解十分不错,设置合适的隐藏层神经元个数,加大种群规模和迭代次数效果更佳。

四、参考代码

参考代码见评论区或添加博主微信获取。

你可能感兴趣的:(单目标应用,MATLAB,智能优化算法,matlab,神经网络,机器学习)