俊博 发表于 2007-10-22 15:11

关于BP三层神经网络的程序编制

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

% 读入训练数据和测试数据
Input = [];
Output = [];
str = {'Test','Check'};
Data = textread();
% 读训练数据
Input = Data(:,1:end-1);
% 取数据表的前五列(主从成分)
Output = Data(:,end);
% 取数据表的最后一列(输出值)
Data = textread();
% 读测试数据
CheckIn = Data(:,1:end-1);
% 取数据表的前五列(主从成分)
CheckOut = Data(:,end);
% 取数据表的最后一列(输出值)
Input = Input';
Output = Output';
CheckIn = CheckIn';
CheckOut = CheckOut';
% 矩阵赚置
= 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 = ;
% 网络后两层神经元配置
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);
% 刚建立的网络误差

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
= train(Net,Input,Output);
% 训练网络并返回
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Out3 =sim(Net,Input);
% 对学习训练后的网络仿真

lxq 发表于 2007-10-22 15:27

论坛上有这方面的程序

搜索下就知道了
页: [1]
查看完整版本: 关于BP三层神经网络的程序编制