1 简介

采用狮群算法优化BP神经网络模型,对房屋价格预测问题进行研究,通过房屋的户型,面积等相关指标有效地对青岛市的二手房价格进行预测.改进后的狮群算法对BP神经网络的权值和偏置进行优化,提高BP神经网络的收敛速度和训练精度.试验结果表明,狮群和BP结合算法模型在房价预测问题上预测效果更好.

【BP预测】基于狮群算法优化BP神经网络实现数据预测Matlab代码_神经网络模型

【BP预测】基于狮群算法优化BP神经网络实现数据预测Matlab代码_神经网络_02

2 部分代码

%_________________________________________________________________________%
%狮群算法 %
%_________________________________________________________________________%
function [Best_pos,Best_score,curve]=LSO(pop,Max_iter,lb,ub,dim,fobj)
beta = 0.5;%成年狮所占比列
Nc = round(pop*beta);%成年狮数量
Np = pop-Nc;%幼师数量
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
[value, index]= min(fitness);%找最小值
GBestF = value;%全局最优适应度值
GBestX = X(index,:);%全局最优位置
curve=zeros(1,Max_iter);
XhisBest = X;
fithisBest = fitness;
indexBest = index;
gbest = GBestX;
for t = 1: Max_iter
%母狮移动范围扰动因子计算
stepf = 0.1*(mean(ub) - mean(lb));
alphaf = stepf*exp(-30*t/Max_iter)^10;
%幼狮移动范围扰动因子计算
alpha = (Max_iter - t)/Max_iter;
%母狮位置更新
for i = 1:Nc
index = i;
while(index == i)
index = randi(Nc);%随机挑选一只母狮
end
X(i,:) = (X(i,:) + X(index,:)).*(1 + alphaf.*randn())./2;
end
%幼师位置更新
for i = Nc+1:pop
q=rand;
if q<=1/3
X(i,:) = (gbest + XhisBest(i,:)).*( 1 + alpha.*randn())/2;
elseif q>1/3&&q<2/3
indexT = i;
while indexT == i
indexT = randi(Nc) + pop - Nc;%随机位置
end
X(i,:) = (X(indexT,:) + XhisBest(i,:)).*( 1 + alpha.*randn())/2;
else
gbestT = ub + lb - gbest;
X(i,:) = (gbestT + XhisBest(i,:)).*( 1 + alpha.*randn())/2;
end
end
%边界控制
for j = 1:pop
for a = 1: dim
if(X(j,a)>ub)
X(j,a) =ub(a);
end
if(X(j,a)<lb)
X(j,a) =lb(a);
end
end
end
%计算适应度值
for j=1:pop
fitness(j) = fobj(X(j,:));
end
for j = 1:pop
if(fitness(j)<fithisBest(j))
XhisBest(j,:) = X(j,:);
fithisBest(j) = fitness(j);
end
if(fitness(j) < GBestF)
GBestF = fitness(j);
GBestX = X(j,:);
indexBest = j;
end
end
%% 狮王更新
Temp = gbest.*(1 + randn().*abs(XhisBest(indexBest,:) - gbest));
Temp(Temp>ub)=ub(Temp>ub);
Temp(Temp<lb) = lb(Temp<lb);
fitTemp = fobj(Temp);
if(fitTemp<GBestF)
GBestF =fitTemp;
GBestX = Temp;
X(indexBest,:)=Temp;
fitness(indexBest) = fitTemp;
end
[value, index]= min(fitness);%找最小值
gbest = X(index,:);%当前代,种群最优值
curve(t) = GBestF;
end
Best_pos = GBestX;
Best_score = curve(end);
end

3 仿真结果

【BP预测】基于狮群算法优化BP神经网络实现数据预测Matlab代码_神经网络_03

4 参考文献

[1]丁飞, 江铭炎. 基于改进狮群算法和BP神经网络模型的房价预测[J]. 山东大学学报:工学版, 2021, 51(4):9.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

【BP预测】基于狮群算法优化BP神经网络实现数据预测Matlab代码_神经网络模型_04