|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
/ ^: W2 Y2 ]$ R文章目录, `3 `8 G! K7 z' h! d
- BP神经网络
- ?3 L- B% T# V) d- L9 T4 n
- MATLAB代码
- 效果
* |" J9 b& t3 f* s# o! M, h, F 3 Z3 f: i8 }& \' M" Z( @
BP神经网络8 j. V% n9 y9 O( v4 Z& S5 Q
BP(back propagation)神经网络是1986年由Rumelhart和McClelland为首的科学家提出的概念,是一种按照误差逆向传播算法训练的多层前馈神经网络,是目前应用最广泛的神经网络。
7 y: ]9 h; T# Z3 B: f
' s& \4 }* Y5 M4 EBP神经网络的计算过程由正向计算过程和反向计算过程组成。正向传播过程,输入模式从输入层经隐单元层逐层处理,并转向输出层,每~层神经元的状态只影响下一层神经元的状态。如果在输出层不能得到期望的输出,则转入反向传播,将误差信号沿原来的连接通路返回,通过修改各神经元的权值,使得误差信号最小。3 Q& r9 w5 f& |& c4 h
/ Q. X) |5 w, Y+ o
MATLAB代码% h+ ^% A1 A, U* j
. u: w. q/ ~& A8 V9 Q
- 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 )
- $ A" z( h; @9 G% q$ L0 z! K( i
5 s2 C8 i! L" y# K5 V效果
1 }9 P0 H0 ^* O; ^识别率是 97.333%& E0 S8 B% c8 x% T% h, m
& K! `! \1 y. y d: ^% q
% A" Z3 \2 G/ D% u9 h |
|