1 简介
为实现精准施肥"减施增效"的数字化农业施肥技术,本文基于并运用了麻雀搜索算法,对广义回归神经网络(GRNN)进行了结合与改进,并构建作物广义回归神经网络(GRNN)结合麻雀搜索算法的预测施肥量模型.通过采集得到的数据样本会被用来输入MATLAB进行仿真和实验验证.仿真和实验结果表明,基于麻雀搜索算法的GRNN神经网络模型比BP神经网络具有更少的输入参数,能更好地反映施肥量与诸多影响因素之间的关系,具有实用价值.且基于麻雀搜索算法改进的GRNN神经网络算法模型人为设定量更少,更为客观,预测值与实际值之间的误差更小,预测结果更加准确.
2 部分代码
%_________________________________________________________________________%
% 麻雀优化算法 %
%_________________________________________________________________________%
function [Best_pos,Best_score,curve]=SSA(pop,Max_iter,lb,ub,dim,fobj)
ST = 0.6;%预警值
PD = 0.7;%发现者的比列,剩下的是加入者
SD = 0.1;%意识到有危险麻雀的比重
PDNumber = round(pop*PD); %发现者数量
SDNumber = round(pop*SD);%意识到有危险麻雀数量
if(max(size(ub)) == 1)
ub = ub.*ones(1,dim);
lb = lb.*ones(1,dim);
end
%种群初始化
X0=initialization(pop,dim,ub,lb);
X = X0;
%计算初始适应度值
fitness = zeros(1,pop);
for i = 1:pop
fitness(i) = fobj(X(i,:));
end
[fitness, index]= sort(fitness);%排序
BestF = fitness(1);
WorstF = fitness(end);
GBestF = fitness(1);%全局最优适应度值
for i = 1:pop
X(i,:) = X0(index(i),:);
end
curve=zeros(1,Max_iter);
GBestX = X(1,:);%全局最优位置
X_new = X;
for i = 1: Max_iter
BestF = fitness(1);
WorstF = fitness(end);
R2 = rand(1);
for j = 1:PDNumber
if(R2<ST)
X_new(j,:) = X(j,:).*exp(-j/(rand(1)*Max_iter));
else
X_new(j,:) = X(j,:) + randn()*ones(1,dim);
end
end
for j = PDNumber+1:pop
% if(j>(pop/2))
if(j>(pop - PDNumber)/2 + PDNumber)
X_new(j,:)= randn().*exp((X(end,:) - X(j,:))/j^2);
else
%产生-1,1的随机数
A = ones(1,dim);
for a = 1:dim
if(rand()>0.5)
A(a) = -1;
end
end
AA = A'*inv(A*A');
X_new(j,:)= X(1,:) + abs(X(j,:) - X(1,:)).*AA';
end
end
Temp = randperm(pop);
SDchooseIndex = Temp(1:SDNumber);
for j = 1:SDNumber
if(fitness(SDchooseIndex(j))>BestF)
X_new(SDchooseIndex(j),:) = X(1,:) + randn().*abs(X(SDchooseIndex(j),:) - X(1,:));
elseif(fitness(SDchooseIndex(j))== BestF)
K = 2*rand() -1;
X_new(SDchooseIndex(j),:) = X(SDchooseIndex(j),:) + K.*(abs( X(SDchooseIndex(j),:) - X(end,:))./(fitness(SDchooseIndex(j)) - fitness(end) + 10^-8));
end
end
%边界控制
for j = 1:pop
for a = 1: dim
if(X_new(j,a)>ub(a))
X_new(j,a) =ub(a);
end
if(X_new(j,a)<lb(a))
X_new(j,a) =lb(a);
end
end
end
%更新位置
for j=1:pop
fitness_new(j) = fobj(X_new(j,:));
end
for j = 1:pop
if(fitness_new(j) < GBestF)
GBestF = fitness_new(j);
GBestX = X_new(j,:);
end
end
X = X_new;
fitness = fitness_new;
%排序更新
[fitness, index]= sort(fitness);%排序
BestF = fitness(1);
WorstF = fitness(end);
for j = 1:pop
X(j,:) = X(index(j),:);
end
curve(i) = GBestF;
end
Best_pos =GBestX;
Best_score = curve(end);
end
3 仿真结果
4 参考文献
[1]倪贤达, 杨得航, 左桐,等. 基于遗传算法改进GRNN神经网络的施肥量预测研究[J]. 2020.
[2]印雷, 顾德, & 刘飞. (2021). 基于改进麻雀搜索算法优化的dv-hop定位算法. 传感技术学报, 34(5), 6.
部分理论引用网络文献,若有侵权联系博主删除。
版权归原作者 Matlab科研工作室 所有, 如有侵权,请联系我们删除。