|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
4 T% ]5 Z2 a7 v2 [( u& [文章目录
# ?( \1 n G7 ^9 ?$ N \& r- BP神经网络 M+ E; n: J2 P+ H% ]
- MATLAB代码
- 效果
" ]' R* O- i6 O
: i" I5 j ^4 [5 O2 Z0 YBP神经网络* ^* X+ Y" Y' ~" y5 ]
BP(back propagation)神经网络是1986年由Rumelhart和McClelland为首的科学家提出的概念,是一种按照误差逆向传播算法训练的多层前馈神经网络,是目前应用最广泛的神经网络。% M& i! F) R3 a X
# |5 t5 v: m- k1 |5 d3 vBP神经网络的计算过程由正向计算过程和反向计算过程组成。正向传播过程,输入模式从输入层经隐单元层逐层处理,并转向输出层,每~层神经元的状态只影响下一层神经元的状态。如果在输出层不能得到期望的输出,则转入反向传播,将误差信号沿原来的连接通路返回,通过修改各神经元的权值,使得误差信号最小。
9 q& ?( c s) z- N# R1 T$ P6 y9 Y+ @& N7 @' e- f% `
MATLAB代码: I& Z1 g& U( p8 s: f9 R
% C$ a4 t7 a+ f( F
- 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 )
$ S8 G `0 R L Q/ u, w; p 6 @5 H$ A# L u! Q8 b0 g- ?% t
效果
% @& s; e( B9 \+ W8 p识别率是 97.333%
( F& `$ h& Q7 Y8 o2 F2 A/ a
6 v) ?! ?' R; `5 P/ s* Y, \! l# ?) ~/ U r
|
|