|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
9 m% h" r" s- m: g' \文章目录5 \& r6 p6 q/ u" H5 F7 p2 S
- BP神经网络
+ l) }5 ?9 F: {/ k
- MATLAB代码
- 效果
+ f) ^1 x0 r! d: t) `5 F ! o4 ]: B$ p- `- \4 U
BP神经网络: l7 H6 _0 Y8 r# a* Y/ P+ e; u
BP(back propagation)神经网络是1986年由Rumelhart和McClelland为首的科学家提出的概念,是一种按照误差逆向传播算法训练的多层前馈神经网络,是目前应用最广泛的神经网络。4 B7 Q0 J3 W A$ B( j
0 m% h/ p; a+ S/ s) e9 ^5 ~6 I. |. I; y
BP神经网络的计算过程由正向计算过程和反向计算过程组成。正向传播过程,输入模式从输入层经隐单元层逐层处理,并转向输出层,每~层神经元的状态只影响下一层神经元的状态。如果在输出层不能得到期望的输出,则转入反向传播,将误差信号沿原来的连接通路返回,通过修改各神经元的权值,使得误差信号最小。
, @$ Y! }0 Z. s
, C- s+ M6 \5 C/ y! B: g3 ]MATLAB代码
3 g7 d) N( n; I3 s
7 Q }" N+ r+ m- 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 )
( B& d5 l. a( }# o. S" ^ 4 s5 k0 @7 h. |* u/ }* Q5 _
效果
$ S% J, w5 i: w0 r9 m8 T4 K识别率是 97.333%
+ L5 C- ^; `+ L- g! |" a
* B ?% ], N0 U4 n
; ?) ~7 w' r% M5 t b. a/ {" a. I |
|