[小学教育]在matlab6x中构建bp

上传人:tia****nde 文档编号:70523950 上传时间:2019-01-17 格式:PPT 页数:31 大小:371.81KB
返回 下载 相关 举报
[小学教育]在matlab6x中构建bp_第1页
第1页 / 共31页
[小学教育]在matlab6x中构建bp_第2页
第2页 / 共31页
[小学教育]在matlab6x中构建bp_第3页
第3页 / 共31页
[小学教育]在matlab6x中构建bp_第4页
第4页 / 共31页
[小学教育]在matlab6x中构建bp_第5页
第5页 / 共31页
点击查看更多>>
资源描述

《[小学教育]在matlab6x中构建bp》由会员分享,可在线阅读,更多相关《[小学教育]在matlab6x中构建bp(31页珍藏版)》请在金锄头文库上搜索。

1、在Matlab6.x中构建BP网络,BP网络建立 BP训练算法选取 训练数据的前期处理 提高BP网络泛化能力 检验BP网络的方法,一. BP网络建立,1.网络的输入输出数据结构 (m维输入n维输出) a. 只有一个样本时 Input = P1,P2,Pm m by 1列向量 Output = O1,O2,On n by 1列向量,b.有s个样本的时候 输入 Input 是 m by s矩阵 每个列向量为一个输入向量. 输出 Output 是 n by s矩阵每个列向量为一个输出.,2. 网络结构(一般3层网络够用) 输入层单元数: m 输出层单元数: n 隐层单元数h确定原则: 在满足训练精度

2、的情况下越少越好, 以防止过拟合情况.,3. 网络权值(weight)与阈值(bias)数据结构 输入层与隐层之间连接权矩阵W1是 m by h 矩阵其中W1第i行表示第i个输入单元与隐层单元间的连接权 隐层与输出层之间连接权矩阵W2是 n by h 矩阵其中第j行表示第j个输出单元与隐层单元间连接权.,4.各层传递函数选择: 输入层 隐层 输出层,a.输入层: 起着将输入传递到各隐层单元因此没有传递函数 b.隐层: 能够拟合非线性函数的关键, 应该 是个单调非减函数, Matlab中提供三种传递函数 longsig(0,1), tansig(-1,1)和purelin c. 输出层: 可以采

3、用logsig 与 tansig, 或者purelin. (最好purelin: 1.小样本 2.无需归一划),5. 最简便的构建方法 newff(三层为例) net = newff (PR,S1 S2 S3,TF2 TF3, BTF, BLF, PF) PR: m by 2 矩阵第i行表示第i维输入的取值范围. Si: 第i层单元个数 TFi: i层传递函数 default = tansig BTF: 网络训练函数default = trainlm BLF: 权值/阈值学习函数 default =learngdm,此时网络权值以及偏置项已经采用Nguyen-Widrow layer init

4、ialization method初始化完毕. PF: 性能函数 default = mse 均方误差和 为什么BTF与BLF不同: BTF: 得到dWi, dBi BLF: 更新 Wi, Bi,6.关于得到的网络 net 的问题 a.是个object, 所含内容 b. net.iw, net.lw, net.b是cell型数据 c. 训练算法及参数: net.trainParam.,二. 各种训练方法比较:,1. LM算法的一些注意事项: TRAINLM 由于速度很快所以是默认的算法, 但是很消耗内存. 原因:储存一个 s by m的Jacobi 矩阵, 当样本数目s很大的时候导致耗费内存过

5、多. 解决方案: Bogdan M. Wilamowski 的 An Algorithm for Fast Convergence in Training Neural Networks,Levenberg Marquadt算法主要解决非线性最小二乘问题. 使用trainlm时如果有 “out-of-memory” 错误提示的时候应采用如下步骤: (1) 通过设置 net.trainParam.mem_reduc 来减少对内存的需求.设置mem_reduc 为 2, 再重新训练一次. 如果仍然出现内存不足的情况增加 mem_reduc的值, 由于 a significant computati

6、onal overhead is associated with computing the Jacobian in sub-matrices但是运行时间也会随之增加. 参数意义如下: If mem_reduc is set to 1, then the full Jacobian is omputed, and no memory reduction is achieved. If mem_reduc is set to 2, then only half of the Jacobian will be computed at one time. This saves half of the

7、 memory used by the calculation of the full Jacobian.,(2) Use TRAINBFG, which is slower but more memory efficient than TRAINLM. (3) Use TRAINRP which is slower but more memory efficient than TRAINBFG.,Trainlm: Good: 对于函数拟合问题, 当网络只有几百个可调参数的时候, LM收敛最快. Bad: 当网络的权值增加的时候LM的优点逐渐消失(消耗内存急剧增加). 而且LM不适合与模式识别

8、网络训练.,Trainrp: Good: 用来训练模式识别问题的网络收敛最快, 而且消耗内迅也不多(训练中只借用下降梯度的方向). Bad: 函数拟合时效果不好. 当接近极小点的时候性能下降.,Trainscg(推荐算法): 在很多情况下效果都很好, 尤其是对规模较大的网络. 在函数拟合情况下几乎和LM算法一样快 (对于较大的网络甚至更快) ,.在模式识别训练中和 trainrp 一样快. Its performance does not degrade as quickly as trainrp performance does when the error is reduced. 共轭梯度

9、法( conjugate gradient algorithms) 对内存要求不是很高.,Trainbfg: 性能和 trainlm相近,但对内存要求较trainlm小. 但该算法计算量随着网络规模的增加呈几何增长, since the equivalent of a matrix inverse must be computed at each iteration.,Traingdx: 与其他算法比起来比较慢, 内存要求和 trainrp相近. 但是仍有其有用之处, 有些场合下需要收敛慢的算法. For example, when using early stopping you may h

10、ave inconsistent results if you use an algorithm that converges too quickly. You may overshoot the point at which the error on the validation set is minimized.,三.训练数据前期处理,1.将输入和输出归一划到一定范围内 a.算术处理 premnmx: 得到-1,1的新数据 tramnmx: 归一划新的输入 b.统计处理 prestd: 得到平均值为0, 标准差为1的新数据 poststd: 将数据变换回去,将 输入归一划到一定范围内的原因

11、: Sigmoid functions are characterized by the fact that their slope must approach zero as the input gets large. This causes a problem when using steepest descent to train a multilayer network with sigmoid functions, since the gradient can have a very small magnitude; and therefore, cause small change

12、s in the weights and biases, even though the weights and biases are far from their optimal values.,2.主成分分析(PCA) 当输入维数比较高, 而且每一个输入向量的各分量之间相关性比较大的时候. 使用主成分分析(principal component analysis)效果更好. pn,meanp,stdp = prestd(p); ptrans,transMat = prepca(pn,0.02); 注意: 当有新输入的时候, 要先用trastd之然后再用得到的transMat将其PC提取出来

13、 pnewn = trastd(pnew,meanp,stdp); pnewtrans = trapca(pnewn,transMat); a = sim(net,pnewtrans);,四.提高网络泛化能力,1.过拟合与网络结构 即网络的训练误差很小(已经收敛), 但是预测未学习过的样本时误差很大. 网络记住了学习的样本, 但是没有扩展能力(generalization). 一个例子: 学习识别什么是树的时候两种极端情况. 如果网络的可调参数比训练样本数少的多的话, 过拟合的可能性就小的多了.,2.解决方法: a. 控制网络规模: trainbr 一般来说网络隐层节点数越多越容易收敛, 但是

14、也越容易过拟 合, 所以应该使用规模合适的网络, trainbr可以自动做到这一点. trainbr 算法在输入和输出落在 -1,1范围内时效果最好. trainbr是在LM算法基础上改编的. b.Automated regularization(正则化): net.performFcn = msereg; net.performParam.ratio = 0.5(难以确定); 修改网络的性能函数使得在减小MSE的同时也减小权值的绝对值大小, 这会使得网络产生的曲线更加光滑因而过拟合可能性变小.,c. Early stopping: 将训练数据分为两部分: training set (训练集)

15、 validation set(验证集), 每次迭代用training set 更新网络, 然后用网络来预测validation set并与更新前的网络预测误差比较, 当发现预测validation set的误差开始上升的时候停止训练.(效果不如trainbr),推荐方法: trainbr 在函数拟合的时候trainbr效果比early stopping更好,尤其是当训练数据比较少得时候. This is because Bayesian regularization does not require that a validation data set be separated out of

16、 the training data set. It uses all of the data.,注意事项: a. 在多种初始化条件下训练网络. It is possible for either method to fail in certain circumstances. By testing several different initial conditions, you can verify robust network performance. b. trainbr在用于模式识别的网络训练时效果不佳. c. trainbr 更耗费时间,五.检验模型性能,1.postreg的使用 对于训练样本集(x, t)来说, 假设训练得到的网络输出为a, m,b,r = postreg(a,t), 这样得到线性回归模型 a = m *t + b, r为得到的这个线性回归模型的相关系数. m, r

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号