声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1044|回复: 1

[编程技巧] 关于BP三层神经网络的程序编制

[复制链接]
发表于 2007-10-22 15:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
这是我在网上找到的,说是可以改成BP三层神经网络的程序,但我实在是个门外汉,一直也没找到头绪,希望高手们帮我看看,或者推荐本相关的书也行,我手头现在有两本《神经网络理论与MATLAB7实现》和《面向MATLAB工具箱的神经网络理论与应用》,但是我都没找到相关的东西,所以还请大家帮忙,先谢谢了

% 读入训练数据和测试数据
Input = [];
Output = [];
str = {'Test','Check'};
Data = textread([str{1},'.txt']);
% 读训练数据
Input = Data(:,1:end-1);
% 取数据表的前五列(主从成分)
Output = Data(:,end);
% 取数据表的最后一列(输出值)
Data = textread([str{2},'.txt']);
% 读测试数据
CheckIn = Data(:,1:end-1);
% 取数据表的前五列(主从成分)
CheckOut = Data(:,end);
% 取数据表的最后一列(输出值)
Input = Input';
Output = Output';
CheckIn = CheckIn';
CheckOut = CheckOut';
% 矩阵赚置
[Input,minp,maxp,Output,mint,maxt] = premnmx(Input,Output);
% 标准化数据

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 神经网络参数设置
%====可以修正处
Para.Goal = 0.0001;
% 网络训练目标误差
Para.Epochs = 800;
% 网络训练代数
Para.LearnRate = 0.1;
% 网络学习速率
%====
Para.Show = 5;
% 网络训练显示间隔
Para.InRange = repmat([-1 1],size(Input,1),1);
% 网络的输入变量区间
Para.Neurons = [size(Input,1)*2+1 1];
% 网络后两层神经元配置
Para.TransferFcn= {'logsig' 'purelin'};
% 各层的阈值函数
Para.TrainFcn = 'trainlm';
% 网络训练函数赋值
% traingd : 梯度下降后向传播法
% traingda : 自适应学习速率的梯度下降法
% traingdm : 带动量的梯度下降法
% traingdx :
% 带动量,自适应学习速率的梯度下降法
Para.LearnFcn = 'learngdm';
% 网络学习函数
Para.PerformFcn = 'sse';
% 网络的误差函数
Para.InNum = size(Input,1);
% 输入量维数
Para.IWNum = Para.InNum*Para.Neurons(1);
% 输入权重个数
Para.LWNum = prod(Para.Neurons);
% 层权重个数
Para.BiasNum = sum(Para.Neurons);
% 偏置个数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Net = newff(Para.InRange,Para.Neurons,Para.TransferFcn,...
Para.TrainFcn,Para.LearnFcn,Para.PerformFcn);
% 建立网络
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Net.trainParam.show = Para.Show;
% 训练显示间隔赋值
Net.trainParam.goal = Para.Goal;
% 训练目标误差赋值
Net.trainParam.lr = Para.LearnRate;
% 网络学习速率赋值
Net.trainParam.epochs = Para.Epochs;
% 训练代数赋值
Net.trainParam.lr = Para.LearnRate;

Net.performFcn = Para.PerformFcn;
% 误差函数赋值
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 调试
Out1 =sim(Net,Input);
% 仿真刚建立的网络
Sse1 =sse(Output-Out1);
% 刚建立的网络误差

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[Net TR] = train(Net,Input,Output);
% 训练网络并返回
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Out3 =sim(Net,Input);
% 对学习训练后的网络仿真
回复
分享到:

使用道具 举报

发表于 2007-10-22 15:27 | 显示全部楼层
论坛上有这方面的程序

搜索下就知道了

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-25 09:50 , Processed in 0.072009 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表