clear all
clear,clc
load B;
P=[B(1:3,:),B(2:4,:),B(3:5,:),B(4:6,:),B(5:7,:),...
B(6:8,:),B(7:9,:),B(8:10,:),B(9:11,:),B(10:12,:),...
B(11:13,:),B(12:14,:),B(13:15,:),B(14:16,:),B(15:17,:),...
B(16:18,:),B(17:19,:),B(18:20,:),B(19:21,:),B(20:22,:)];
T=[B(4,:),B(5,:),B(6,:),B(7,:),B(8,:),B(9,:),...
B(10,:),B(11,:),B(12,:),B(13,:),B(14,:),B(15,:),...
B(16,:),B(17,:),B(18,:),B(19,:),B(20,:),B(21,:),...
B(22,:),B(23,:)];
[inputn,inputps]=mapminmax(P);
[outputn,outputps]=mapminmax(T);
th1=[0,1;0,1;0,1];
th2=[0,1];
net=newelm(th1,th2,[50,20]);
net.trainparam.show=25;
net.trainparam.epochs=1000;
net.trainparam.goal=0.001;
net=init(net);
net=train(net,inputn,outputn);
inputn_test=mapminmax('apply',B(21:23,:),inputps);
test_P=B(21:23,:);
y=sim(net, inputn_test);
elmanoutput=mapminmax('reverse',y,outputps);
figure(1)
plot(elmanoutput,':or')
hold on
plot(B(24,:),'-*');
legend('预测输出','实际输出')
title('改进前预测输出','fontsize',12)
ylabel('函数输出','fontsize',12)
xlabel('时间','fontsize',12)
%预测误差
error=elmanoutput-B(24,:);
figure(2)
plot(error,'-*')
title('elman网络预测误差','fontsize',12)
ylabel('误差','fontsize',12)
xlabel('样本','fontsize',12)
figure(3)
plot((B(24,:)-elmanoutput)./elmanoutput,'-*');
title('预测误差百分比')
errorsum=sum(abs(error))