matlab预训练好的,BP神经网络训练好后如何预测?

close all

clear

clf reset

figure(gcf);

echo on

clc

%newff--生成一个新的bp前向神经网络

%train--训练

%sim--仿真

Pause

%任意键开始

clc

P=[0.2452,0.1466,0.1314,0.2243,0.5523,0.6642,0.7015,0.6981,0.6821,0.6945,0.7549,0.8215,0.2415,0.3027,0;

0.2217,0.1581,0.1408,0.2304,0.5134,0.5312,0.6819,0.7125,0.7265,0.6847,0.7826,0.8325,0.2385,0.3125,0;

0.2525,0.1627,0.1507,0.2406,0.5502,0.5636,0.7051,0.7352,0.7459,0.7015,0.8064,0.8156,0.2216,0.2701,1;

0.2016,0.1105,0.1243,0.1978,0.5021,0.5232,0.6819,0.6952,0.7015,0.6825,0.7825,0.7895,0.2352,0.2506,0.5;

0.2115,0.1201,0.1312,0.2019,0.5532,0.5736,0.7029,0.7032,0.7189,0.7019,0.7965,0.8025,0.2542,0.3125,0;

0.2335,0.1322,0.1534,0.2214,0.5623,0.5827,0.7198,0.7276,0.7359,0.7506,0.8092,0.8221,0.2601,0.3198,0;

0.2368,0.1432,0.1653,0.2205,0.5823,0.5971,0.7136,0.7129,0.7263,0.7153,0.8091,0.8217,0.2579,0.3099,0;

0.2342,0.1368,0.1602,0.2131,0.5726,0.5822,0.7101,0.7098,0.7127,0.7121,0.7995,0.8126,0.2301,0.2867,0.5;  0.2113,0.1212,0.1305,0.1819,0.4952,0.5312,0.6886,0.6898,0.6999,0.7323,0.7721,0.7956,0.2234,0.2799,1;

0.2005,0.1121,0.1207,0.1605,0.4556,0.5022,0.6553,0.6673,0.6798,0.7023,0.7521,0.7756,0.2314,0.2977,0]'

T=[0.2217,0.1581,0.1408,0.2304,0.5134,0.5312,0.6819,0.7125,0.7265,0.6847,0.7826,0.8325;

0.2525,0.1627,0.1507,0.2406,0.5502,0.5636,0.7051,0.7352,0.7459,0.7015,0.8064,0.8156;

0.2016,0.1105,0.1243,0.1978,0.5021,0.5232,0.6819,0.6952,0.7015,0.6825,0.7825,0.7895;

0.2115,0.1201,0.1312,0.2019,0.5532,0.5736,0.7029,0.7032,0.7189,0.7019,0.7965,0.8025; 0.2335,0.1322,0.1534,0.2214,0.5623,0.5827,0.7198,0.7276,0.7359,0.7506,0.8092,0.8221;   0.2368,0.1432,0.1653,0.2205,0.5823,0.5971,0.7136,0.7129,0.7263,0.7153,0.8091,0.8217;   0.2342,0.1368,0.1602,0.2131,0.5726,0.5822,0.7101,0.7098,0.7127,0.7121,0.7995,0.8126;   0.2113,0.1212,0.1305,0.1819,0.4952,0.5312,0.6886,0.6898,0.6999,0.7323,0.7721,0.7956;

0.2005,0.1121,0.1207,0.1605,0.4556,0.5022,0.6553,0.6673,0.6798,0.7023,0.7521,0.7756;   0.2123,0.1257,0.1343,0.2079,0.5579,0.5716,0.7059,0.7145,0.7205,0.7401,0.8019,0.8136]'

net=newff(minmax(P),[10,12],{'tansig','logsig'},'trainlm');

inputWeights=net.IW{1,1}

inputbias=net.b{1}

%

layerWeights=net.LW{2,1}

layerbias=net.b{2}

pause

clc

net.trainParam.show=10;

net.trainParam.lr=0.05;

net.trainParam.mem=3;

net.trainParam.mc=0.9;

net.trainParam.epochs=100000;

net.trainParam.goal=0.01;

pause

clc

%

[net,tr]=train(net,P,T);

pause

clc

%训练后网络权值和偏差

inputWeights=net.IW{1,1}

inputbias=net.b{1}

%

layerWeights=net.LW{2,1}

layerbias=net.b{2}

pause

%

A=sim(net,P)

%计算仿真误差

E=T-A

SSE=sse(E)  误差平方和,越接近0越好,说明总误差很小

pause

clc

echo off

%预测结果对比

p=[0.2123,0.1257,0.1343,0.2079,0.5579,0.5716,0.7059,0.7145,0.7205,0.7401,0.8019, 0.8136,0.2317,0.2936,0]'

t=0:2:24

t=t'

A=sim(net,p)

A(13)=A(1)

plot(t,A,':')       %用虚线表示预测值

hold on         %启动图形保持

%负荷的真实值

b=[0.2119,0.1215,0.1621,0.2161,0.6171,0.6159,0.7115,0.7201,0.7243,0.7298,0.8179, 0.8229,0.2119]'

plot(t,b, '-')      %用实线表示负荷真实值

xlabel('时间')

ylabel('负荷值')

title('预测值与实际值的对比')

能帮我看一下这个程序吗?里面的P是输入向量,是20日到29日的数据,T是输出向量,是21日到30日的数据,p是30日的数据,b是31日的数据,搞不懂训练样本是哪些?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值