MATLAB BP神经网络用法的总结(试用于初学者)

来源:互联网 发布:youxi域名 编辑:程序博客网 时间:2024/06/05 12:41

BP(back propagation,反向传播)神经网络功能及其MATLAB实现。

反向传播指误差函数会由输出端向前反向传播,隐含层借此调整权值来缩小误差。

结构图:


W为权值,b为阈值。

1.      数据输入:数据输入时需先使用传递函数进行变化,变换方法包括阈值(阶跃)函数、分段线性变换、归一化函数(mapminmax)、对数S形变换(logsig)、正切S形变换(tansig)。

2.      神经网络创建:

创建函数newcf,该函数创建级联前向BP神经网络。

  Description

 

    newcf(P,T,[S1 S2...S(N-1)],{TF1 TF2...TFN},BTF,BLF,PF,IPF,OPF,DDF)takes,

      P  - RxQ1 matrix of Q1representative R-element input vectors.

      T  - SNxQ2 matrix of Q2representative SN-element target vectors.

      Si  - Sizes of N-1 hidden layers,S1 to S(N-1), default = [].

            (Output layer size SN is determined from T.)

      TFi - Transfer function of ith layer. Default is 'tansig' for

            hidden layers, and 'purelin' for output layer.

      BTF - Backprop network training function, default = 'trainlm'.

      BLF - Backprop weight/bias learning function, default = 'learngdm'.

      PF  - Performance function,default = 'mse'.

      IPF - Row cell array of input processing functions.

            Default is {'fixunknowns','remconstantrows','mapminmax'}.

      OPF - Row cell array of output processing functions.

            Default is {'remconstantrows','mapminmax'}.

      DDF - Data division function, default = 'dividerand';

    and returns an N layer cascade-forward backprop network.

net = newcf(P,T,[S1 S2...S(N-1)],{TF1TF2...TFN},BTF,BLF,PF,IPF,OPF,DDF)

PR:每组输入(共有R组输入)元素的最大值和最小值组成的R*2维矩阵;

Si:第i层的长度,共计N层;

TFi:第i层的传递函数,默认隐含层为tansig,输出层为purelin,输入为两个字符串构成的矩阵,取值范围:


BTF:BP网络的训练函数,默认为trainlm,即Lecenberg-Marquardt函数,可设置为traingd,梯度下降BP算法训练函数,traindm,动量反传的梯度下降BP算法训练函数,trainda,动态自适应学习速率的梯度下降BP算法训练函数,traindx,动量反传和动态自适应学习速率的梯度下降BP算法训练函数。

BLF:权值和阈值的BP学习算法,默认为learngdm,带动量项,可设置为learngd,不带动量项。

PF:网络的性能函数,即训练误差的计算方法,默认为mse,即均方差,可设置为mae,均值绝对误差。

IPF:输入处理函数。

OPF:输出处理函数。

DDF:验证数据划分函数。

后面三个参数一般不设置,取系统默认即可。

创建函数newff,该函数创建前向神经网络。

  Description

 

    newff(P,T,S) takes,

      P  - RxQ1 matrix of Q1representative R-element input vectors.

      T  - SNxQ2 matrix of Q2representative SN-element target vectors.

      Si  - Sizes of N-1 hidden layers,S1 to S(N-1), default = [].

            (Output layer size SN is determined from T.)

    and returns an N layer feed-forward backprop network.

 

    newff(P,T,S,TF,BTF,BLF,PF,IPF,OPF,DDF) takes optional inputs,

      TFi - Transfer function of ith layer. Default is 'tansig' for

            hidden layers, and 'purelin' for output layer.

      BTF - Backprop network training function, default = 'trainlm'.

      BLF - Backprop weight/bias learning function, default = 'learngdm'.

      PF  - Performance function,default = 'mse'.

      IPF - Row cell array of input processing functions.

            Default is {'fixunknowns','remconstantrows','mapminmax'}.

      OPF - Row cell array of output processing functions.

            Default is {'remconstantrows','mapminmax'}.

      DDF - Data division function, default = 'dividerand';

    and returns an N layer feed-forward backprop network.

P:输入数据矩阵;

T:目标数据矩阵;

S:隐含层节点数;

其他参数同newcf。

传递函数

Logsig

Tansig

学习函数

Learngd函数

[dW,LS] =learngd(W,P,Z,N,A,T,E,gW,gA,D,LP,LS)

W:权值矩阵;

P:层输入向量;

Z:层输入经过加权函数变换后的加权输入矢量;

N:加权输入经过输入函数计算后得到的神经元传递函数的输入矢量;

A:该层神经元输出矢量;

T:目标矢量;

E:误差矢量;

gW:网络性能对于权值的梯度矢量;

gA:网络性能对于该层输出梯度矢量;

D:神经元的距离矩阵;

LP:学习参数,learngd函数的学习参数是由学习速率LP.lr构成的,默认值为0.01;

LS:学习状态,初始值为[],函数返回阈值调整量dW和当前学习状态LS。

Learndm函数

参数同上。

训练函数

Trainbfg准牛顿BP算法函数

[net,TR =trainbfg(Net,Tr,trainV,valV,testV)

Net:待训练的神经网咯;

Tr:有延迟的输入网络;

trainV:训练向量;

valV:验证向量;

testV测试向量;

net:训练后的神经网络;

TR:每步训练的有关信息,包括:

         TR.epoch:时刻点;

         TR.perf:训练性能;

         TR.vperf:确认性能;

         TR.tperf:检验性能。

info=trainfg(‘info‘);返回函数的有用信息。

常规参数:

net.trainParam.epochs:训练次数,默认值为100.

net.trainParam.goal:网络性能目标,默认值为0。

net.trainParam.max_fail:最大验证失败次数,默认值为5.

net.trainParam.min_grad:性能函数的最小梯度,默认值为1e-6.

net.trainParam.show:两次显示之间的训练次数,默认值为25。

net.trainParam.time:最大训练时间(秒),默认值为INF。

0 0