|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
|& H' K8 d0 ?) Y: ~5 Y5 V文章目录- {& R+ W3 l. H A) b# S# Z$ s
- BP神经网络
7 u3 ~2 U( S, Y n3 |
- MATLAB代码
- 效果5 ^! E' u- l$ a5 x
: C# p& s' h( x1 iBP神经网络
# Y/ h* n* S9 M, DBP(back propagation)神经网络是1986年由Rumelhart和McClelland为首的科学家提出的概念,是一种按照误差逆向传播算法训练的多层前馈神经网络,是目前应用最广泛的神经网络。
. y+ t( p, W5 w+ E; e7 O1 S* R- Q7 [
BP神经网络的计算过程由正向计算过程和反向计算过程组成。正向传播过程,输入模式从输入层经隐单元层逐层处理,并转向输出层,每~层神经元的状态只影响下一层神经元的状态。如果在输出层不能得到期望的输出,则转入反向传播,将误差信号沿原来的连接通路返回,通过修改各神经元的权值,使得误差信号最小。( Y) P# j4 A! N! l, U
, g% b @0 q7 {0 F* F+ c& Z
MATLAB代码 a& s& F# p) z2 r% Q
0 K+ P( ~' b8 b: V$ l' S4 a! Z- 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 )
- ' T/ F5 g/ t5 _, y/ z7 G4 u4 y. G
- C: n- `! [$ p5 ^( X效果0 d* F7 B2 ?) a8 w
识别率是 97.333%! v5 o% n6 ^8 j% J
. d( }# J2 a- `' T' @) h; P
- Z3 t! L! B+ E8 J
|
|