- 在线时间
- 0 小时
- 最后登录
- 2009-9-12
- 注册时间
- 2009-8-31
- 听众数
- 0
- 收听数
- 0
- 能力
- 0 分
- 体力
- 82 点
- 威望
- 0 点
- 阅读权限
- 20
- 积分
- 27
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 4
- 主题
- 1
- 精华
- 0
- 分享
- 0
- 好友
- 0
升级   23.16% 该用户从未签到
 |
神经网络预测
3 h/ A7 m4 r, E* M8 [! W* s& j, N) C% 数据为1986年到2000年的交通量 ,网络为3输入,1输出. n! Y7 V6 C& S: M2 a
% 15组数据,其中9组为正常训练数据,3组为变量数据,3组为测试数据
3 P5 H N B$ }: h' u* `3 w- I; l%by akjuan
$ R( B) U# b9 ~ u7 c) K$ a2 X& D%all rights preserved by www.4math.cn
# X8 w/ a5 U9 o. s5 j' ^All_error=[];%所有误差存储
2 z, w4 q' d+ b9 Iyear=1986:2000;%数据是从1986到2000年的% H8 |8 J/ S8 z
p=[493 372 445;372 445 176;445 176 235;176 235 378;235 378 429;...8 x' M6 ?9 F' G: [( |9 j
378 429 561;429 561 651;561 651 467;651 467 527;467 527 668;...
/ x# P6 a: v; u5 C! u9 N" }4 `, ? 527 668 841; 668 841 526;841 526 480;526 480 567;480 567 685]';%输入数据,共15组,每组3个输入
* e' l4 A% ^; d7 T% Ct=[176 235 378 429 561 651 467 527 668 841 526 480 567 685 507];%输出数据,共15组,每组1个输出
8 a' G+ }) Y8 [- ?7 K; |, p[normInput,ps] = mapminmax(p);1 n$ p" U( W* F# `9 ]" S. n
[normTarget,ts] = mapminmax(t);, @+ d5 I7 _; w5 m
testPercent = 0.20; % Adjust as desired* a. b9 X, ], }; ]
validatePercent = 0.20; % Adust as desired/ l% ~2 B3 W, F8 P0 D
[trainSamples,validateSamples,testSamples] = dividevec(normInput,normTarget,validatePercent,testPercent);
5 {9 O4 f/ w" a& x, J4 P5 lfor j=1:2002 d3 e l! x9 ~7 p# H- e% M
NodeNum1 = 20; % 隐层第一层节点数
, G+ z) m5 K, k% GNodeNum2=40; % 隐层第二层节点数& p8 b) a6 F* ]6 L6 A0 F
TypeNum = 1; % 输出维数
* D Y/ @- U& [& O7 x9 J' h) @TF1 = 'tansig';TF2 = 'tansig'; TF3 = 'tansig';
4 t; }% h5 _9 \' ~0 l6 tnet=newff(minmax(normInput),[NodeNum1,NodeNum2,TypeNum],{TF1 TF2 TF3},'traingdx');%网络创建net.trainParam.epochs=10000;%训练次数设置! M5 R' L3 T$ r7 w$ R) B
net.trainParam.goal=1e-6;%训练目标设置
0 J) E+ F5 k' o3 XPL.lr=0.01;net.trainfcn='traingdm';
+ `8 J* A: S& [$ \- r# I* e$ I[net,tr] = train(net,trainSamples.P,trainSamples.T,[],[],validateSamples,testSamples);2 q1 j& T! n( e% }; }2 _
[normTrainOutput,Pf,Af,E,trainPerf] = sim(net,trainSamples.P,[],[],trainSamples.T);%正常输入的9组p数据,BP得到的结果t
$ a) q# b* ~' `: M* R6 g0 D[normValidateOutput,Pf,Af,E,validatePerf] = sim(net,validateSamples.P,[],[],validateSamples.T);%用作变量3的数据p,BP得到的结果t9 e8 s0 ~. T4 m+ e# ^
[normTestOutput,Pf,Af,E,testPerf] = sim(net,testSamples.P,[],[],testSamples.T);%用作测试的3组数据p,BP得到的结果t
3 X) `3 J! o3 n+ K% b5 O/ [trainOutput = mapminmax('reverse',normTrainOutput,ts);%正常输入的9组p数据,BP得到的归一化后的结果t
' y( f. d& E) f! W' Q- O( n6 mtrainInsect = mapminmax('reverse',trainSamples.T,ts);%正常输入的9组数据t
5 D. R9 g4 l! ~) ivalidateOutput = mapminmax('reverse',normValidateOutput,ts);%用作变量3的数据p,BP得到的归一化的结果t7 z6 `/ Q# N$ h+ L( x
validateInsect = mapminmax('reverse',validateSamples.T,ts);%用作变量3的数据t9 B" x( C4 _6 B; i. y) w
testOutput = mapminmax('reverse',normTestOutput,ts);%用作变量3组数据p,BP得到的归一化的结果t
( q' q. k" \% btestInsect = mapminmax('reverse',testSamples.T,ts);%用作变量3组数据t
! n- T$ e) s7 }8 W9 t%绝对误差计算8 J' r/ u0 I4 D
absTrainError = trainOutput-trainInsect;
1 J4 X6 \' O' [absTestError = testOutput-testInsect;
" o' X7 f* U- R6 b9 Merror_sum=sqrt(absTestError(1).^2+absTestError(2).^2+absTestError(3).^2);; b1 T5 l2 }) a6 f5 [5 C) a, f: S
All_error=[All_error error_sum];
, v t/ ~5 ~: f8 @7 W: c0 L1 ueps=90;%其为3组测试数据的标准差,或者每个数据偏差在一定范围内而判别, ]. ^1 Y4 ?% |: u
if ((abs(absTestError(1))<=30 )&(abs(absTestError(2))<=30)&(abs(absTestError(3))<=30)|(error_sum<=eps))
9 B% {6 x; `- ~" Q6 usave mynetdata net# ^/ y$ p! i! H
break
3 b- i. c; p6 Yend: p- |$ t9 p5 }6 i- h) F( O* N2 H
j
7 T* C* ]$ Z4 E4 |* b8 ^end q5 M1 C6 @4 {$ [: ?7 t& x
问题是:
+ f* N7 a g" Yif ((abs(absTestError(1))<=30 )&(abs(absTestError(2))<=30)&(abs(absTestError(3))<=30)|(error_sum<=eps))$ K8 e g' n! i' n: j) t/ x
中的30是怎么算出来的啊 |
zan
|