基于 BP/GRNN 神经网络的安全数据预测 matlab 仿真
最编程
2024-04-30 22:36:31
...
............................................................
SAFE=[0.4659, 0.4542, 0.4366, 0.4042, 0.3854, 0.3801, 0.3820, 0.3857, 0.3722, 0.3665, 0.3843, 0.3688, 0.3900, 0.4000, 0.4522, 0.4692,0.4953, 0.5184, 0.5243];
% 基本安全
% 基本安全
% 基本安全
% 基本安全
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 基本安全
% 基本安全
% 基本安全
% 基本安全
% 基本安全
% 基本安全
SAFE10=[1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1];
%GRNN神经网络训练
char = [D]';
T = [SAFE];
Net = newgrnn(char,T,25);
save Grnn.mat Net;
%%
%通过拟合的方法,得到未来的指标的数据
X0=Time';
%设置预测年份
X1=[Time,2016,2017,2018,2019,2020];
Y1=D(:,1);
Y2=D(:,2);
Y3=D(:,3);
Y4=D(:,4);
Y5=D(:,5);
Y6=D(:,6);
Y7=D(:,7);
Y8=D(:,8);
Y9=D(:,9);
Y10=D(:,10);
Y11=D(:,11);
Y12=D(:,12);
Y13=D(:,13);
Y14=D(:,14);
Y15=D(:,15);
%开始拟合
p=polyfit(X0,Y1,5);Y1_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y2,5);Y2_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y3,5);Y3_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y4,5);Y4_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y5,5);Y5_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y6,5);Y6_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y7,5);Y7_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y8,5);Y8_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y9,5);Y9_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y10,5);Y10_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y11,5);Y11_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y12,5);Y12_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y13,5);Y13_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y14,5);Y14_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y15,5);Y15_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
figure;
subplot(4,4,1);plot(X0,Y1,'r*');hold on;plot(X1,Y1_,'b');
subplot(4,4,2);plot(X0,Y2,'r*');hold on;plot(X1,Y2_,'b');
subplot(4,4,3);plot(X0,Y3,'r*');hold on;plot(X1,Y3_,'b');
subplot(4,4,4);plot(X0,Y4,'r*');hold on;plot(X1,Y4_,'b');
subplot(4,4,5);plot(X0,Y5,'r*');hold on;plot(X1,Y5_,'b');
subplot(4,4,6);plot(X0,Y6,'r*');hold on;plot(X1,Y6_,'b');
subplot(4,4,7);plot(X0,Y7,'r*');hold on;plot(X1,Y7_,'b');
subplot(4,4,8);plot(X0,Y8,'r*');hold on;plot(X1,Y8_,'b');
subplot(4,4,9);plot(X0,Y9,'r*');hold on;plot(X1,Y9_,'b');
subplot(4,4,10);plot(X0,Y10,'r*');hold on;plot(X1,Y10_,'b');
subplot(4,4,11);plot(X0,Y11,'r*');hold on;plot(X1,Y11_,'b');
subplot(4,4,12);plot(X0,Y12,'r*');hold on;plot(X1,Y12_,'b');
subplot(4,4,13);plot(X0,Y13,'r*');hold on;plot(X1,Y13_,'b');
subplot(4,4,14);plot(X0,Y14,'r*');hold on;plot(X1,Y14_,'b');
subplot(4,4,15);plot(X0,Y15,'r*');hold on;plot(X1,Y15_,'b');
chars = [Y1_',Y2_',Y3_',Y4_',Y5_',Y6_',Y7_',Y8_',Y9_',Y10_',Y11_',Y12_',Y13_',Y14_',Y15_'];
char2 = [D;chars(size(D,2)+1:end,:)]';
%%
%开始预测
y=sim(Net,char2);
figure;
plot(T,'b-s','linewidth',2);
hold on
plot(y(1:length(T)+5),'r--','linewidth',2);
legend('安全性数据','预测安全性数据');
grid on
axis([0,32,0.3,0.6]);
title('GRNN神经网络预测结果');
%预测误差
Err = mean(abs(T-y(1:length(T))))
SAFE=[0.4659, 0.4542, 0.4366, 0.4042, 0.3854, 0.3801, 0.3820, 0.3857, 0.3722, 0.3665, 0.3843, 0.3688, 0.3900, 0.4000, 0.4522, 0.4692,0.4953, 0.5184, 0.5243];
% 基本安全
% 基本安全
% 基本安全
% 基本安全
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 危险
% 基本安全
% 基本安全
% 基本安全
% 基本安全
% 基本安全
% 基本安全
SAFE10=[1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1];
%GRNN神经网络训练
char = [D]';
T = [SAFE];
Net = newgrnn(char,T,25);
save Grnn.mat Net;
%%
%通过拟合的方法,得到未来的指标的数据
X0=Time';
%设置预测年份
X1=[Time,2016,2017,2018,2019,2020];
Y1=D(:,1);
Y2=D(:,2);
Y3=D(:,3);
Y4=D(:,4);
Y5=D(:,5);
Y6=D(:,6);
Y7=D(:,7);
Y8=D(:,8);
Y9=D(:,9);
Y10=D(:,10);
Y11=D(:,11);
Y12=D(:,12);
Y13=D(:,13);
Y14=D(:,14);
Y15=D(:,15);
%开始拟合
p=polyfit(X0,Y1,5);Y1_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y2,5);Y2_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y3,5);Y3_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y4,5);Y4_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);
p=polyfit(X0,Y5,5);Y5_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y6,5);Y6_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y7,5);Y7_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y8,5);Y8_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y9,5);Y9_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y10,5);Y10_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y11,5);Y11_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y12,5);Y12_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y13,5);Y13_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y14,5);Y14_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
p=polyfit(X0,Y15,5);Y15_=p(1)*X1.^5+p(2)*X1.^4+p(3)*X1.^3+p(4)*X1.^2+p(5)*X1.^1+p(6);;
figure;
subplot(4,4,1);plot(X0,Y1,'r*');hold on;plot(X1,Y1_,'b');
subplot(4,4,2);plot(X0,Y2,'r*');hold on;plot(X1,Y2_,'b');
subplot(4,4,3);plot(X0,Y3,'r*');hold on;plot(X1,Y3_,'b');
subplot(4,4,4);plot(X0,Y4,'r*');hold on;plot(X1,Y4_,'b');
subplot(4,4,5);plot(X0,Y5,'r*');hold on;plot(X1,Y5_,'b');
subplot(4,4,6);plot(X0,Y6,'r*');hold on;plot(X1,Y6_,'b');
subplot(4,4,7);plot(X0,Y7,'r*');hold on;plot(X1,Y7_,'b');
subplot(4,4,8);plot(X0,Y8,'r*');hold on;plot(X1,Y8_,'b');
subplot(4,4,9);plot(X0,Y9,'r*');hold on;plot(X1,Y9_,'b');
subplot(4,4,10);plot(X0,Y10,'r*');hold on;plot(X1,Y10_,'b');
subplot(4,4,11);plot(X0,Y11,'r*');hold on;plot(X1,Y11_,'b');
subplot(4,4,12);plot(X0,Y12,'r*');hold on;plot(X1,Y12_,'b');
subplot(4,4,13);plot(X0,Y13,'r*');hold on;plot(X1,Y13_,'b');
subplot(4,4,14);plot(X0,Y14,'r*');hold on;plot(X1,Y14_,'b');
subplot(4,4,15);plot(X0,Y15,'r*');hold on;plot(X1,Y15_,'b');
chars = [Y1_',Y2_',Y3_',Y4_',Y5_',Y6_',Y7_',Y8_',Y9_',Y10_',Y11_',Y12_',Y13_',Y14_',Y15_'];
char2 = [D;chars(size(D,2)+1:end,:)]';
%%
%开始预测
y=sim(Net,char2);
figure;
plot(T,'b-s','linewidth',2);
hold on
plot(y(1:length(T)+5),'r--','linewidth',2);
legend('安全性数据','预测安全性数据');
grid on
axis([0,32,0.3,0.6]);
title('GRNN神经网络预测结果');
%预测误差
Err = mean(abs(T-y(1:length(T))))
推荐阅读
-
基于 BP/GRNN 神经网络的安全数据预测 matlab 仿真
-
温度预测] 基于 Matlab BP 神经网络的温度预测 [含 Matlab 源代码 第 714 期]。
-
基于 PSO 的优化 BP 神经网络 PID 控制器 matlab 仿真
-
预测模型] 基于随机蛙跳算法的 SFLA 优化神经网络,用 matlab 代码实现数据回归预测
-
[MATLAB 源代码 - 第 148 期] 基于 Matlab 的 BP 神经网络 2/4ASK、2/4FSK、2/4PSK 信号识别仿真。-1、算法描述
-
【预测模型】基于天牛须算法BAS优化BP神经网络实现数据预测matlab源码
-
使用PSO粒子群算法改进RBF神经网络在MATLAB中的数据预测仿真研究
-
基于PSO粒子群算法优化RBF网络的数据预测matlab仿真
-
使用改进的粒子群算法优化BP神经网络进行数据预测的MATLAB代码示例