|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
- T& ]3 `. E# I1 H$ F) b
文章目录
9 H* V2 K2 ?+ b/ G- BP神经网络
' s5 H/ \, L2 a [* J, O! A
- MATLAB代码
- 效果
- B( U, N; s! A& x ; G+ u& _& t% y% r7 |" b
BP神经网络
+ p+ D* u m) i# r4 B, w% C2 V6 E: qBP(back propagation)神经网络是1986年由Rumelhart和McClelland为首的科学家提出的概念,是一种按照误差逆向传播算法训练的多层前馈神经网络,是目前应用最广泛的神经网络。
7 N( e# L, h/ P. ?' S9 }7 \* [9 x/ t$ U
BP神经网络的计算过程由正向计算过程和反向计算过程组成。正向传播过程,输入模式从输入层经隐单元层逐层处理,并转向输出层,每~层神经元的状态只影响下一层神经元的状态。如果在输出层不能得到期望的输出,则转入反向传播,将误差信号沿原来的连接通路返回,通过修改各神经元的权值,使得误差信号最小。+ p3 `) B2 ~8 J9 h9 k8 x) _& r
- g( D: e" @( S" `0 }" `
MATLAB代码
) Z I- W! e$ S$ ?8 K3 {4 [( I* \ o3 ?2 q5 X+ Y k
- clc
- clear all
- %读取训练数据
- [f1,f2,f3,f4,class] = textread('trainData.txt' , '%f%f%f%f%f',150);
- %特征值归一化
- [input,minI,maxI] = premnmx( [f1 , f2 , f3 , f4 ]') ;
- %构造输出矩阵
- s = length( class) ;
- output = zeros( s , 3 ) ;
- for i = 1 : s
- output( i , class( i ) ) = 1 ;
- end
- %创建神经网络
- net = newff( minmax(input) , [10 3] , { 'logsig' 'purelin' } , 'traingdx' ) ;
- %设置训练参数
- net.trainparam.show = 50 ;
- net.trainparam.epochs = 500 ;
- net.trainparam.goal = 0.01 ;
- net.trainParam.lr = 0.01 ;
- %开始训练
- net = train( net, input , output' ) ;
- %读取测试数据
- [t1 t2 t3 t4 c] = textread('testData.txt' , '%f%f%f%f%f',150);
- %测试数据归一化
- testInput = tramnmx ( [t1,t2,t3,t4]' , minI, maxI ) ;
- %仿真
- Y = sim( net , testInput )
- %统计识别正确率
- [s1 , s2] = size( Y ) ;
- hitNum = 0 ;
- for i = 1 : s2
- [m , Index] = max( Y( : , i ) ) ;
- if( Index == c(i) )
- hitNum = hitNum + 1 ;
- end
- end
- sprintf('识别率是 %3.3f%%',100 * hitNum / s2 )
- 7 c8 g5 V: t2 O( `( Z& S
" D5 z; g3 p+ g8 K# s7 e效果* _& t) c. e% {, y8 x* s" r$ r* N9 z
识别率是 97.333%% z1 X; ^" F. ^: S- o: t
; Y7 a$ X1 \1 V V/ f, W
. y1 \! q# T/ `6 h; j
|
|