[matlab]bp神经网络工具箱学习笔记
基本就三个函数:
newff():创建一个bp神经网络
train():训练函数
sim():仿真函数
同时具有可视化界面,但目前不知道可视化界面如何进行仿真,且设置不太全
工具箱:Neural net fitting
textread使用方法:http://blog.sina.com.cn/s/blog_9e67285801010bju.html
ex1.
clear;
clc;
%注意P矩阵,matlab默认将一列作为一个输入
P=[0.5152 0.8173 1.0000 ;
0.8173 1.0000 0.7308;
1.0000 0.7308 0.1390;
0.7308 0.1390 0.1087;
0.1390 0.1087 0.3520;
0.1087 0.3520 0.0000;]';
%以第四个月的销售量归一化处理后作为目标向量
T=[0.7308 0.1390 0.1087 0.3520 0.0000 0.3761];
%创建一个BP神经网络,每一个输入向量的取值范围为[0 ,1],隐含层有5个神经元,输出层有一个神经元,隐含层的激活函数为tansig,输出层的激活函数为%logsig,训练函数为梯度下降函数,即标准学习算法
net=newff([0 1;0 1;0 1],[5,1],{'tansig','logsig'},'traingd');%minmax(P)
net.trainParam.epochs=1500;%最大迭代次数.
net.trainParam.goal=0.01; %训练的误差精度
%设置学习速率为0.1
LP.lr=0.1;
net=train(net,P,T);
a=[0.1;0.2;0.3];
a=premnmx(a);
b=sim(net,a);
b=postmnmx(b,0,1);
b
ex2.
P=[3.2 3.2 3 3.2 3.2 3.4 3.2 3 3.2 3.2 3.2 3.9 3.1 3.2;
9.6 10.3 9 10.3 10.1 10 9.6 9 9.6 9.2 9.5 9 9.5 9.7;
3.45 3.75 3.5 3.65 3.5 3.4 3.55 3.5 3.55 3.5 3.4 3.1 3.6 3.45;
2.15 2.2 2.2 2.2 2 2.15 2.14 2.1 2.1 2.1 2.15 2 2.1 2.15;
140 120 140 150 80 130 130 100 130 140 115 80 90 130;
2.8 3.4 3.5 2.8 1.5 3.2 3.5 1.8 3.5 2.5 2.8 2.2 2.7 4.6;
11 10.9 11.4 10.8 11.3 11.5 11.8 11.3 11.8 11 11.9 13 11.1 10.85;
50 70 50 80 50 60 65 40 65 50 50 50 70 70];
T=[2.24 2.33 2.24 2.32 2.2 2.27 2.2 2.26 2.2 2.24 2.24 2.2 2.2 2.35];
[p1,minp,maxp,t1,mint,maxt]=premnmx(P,T); %创建网络
net=newff(minmax(P),[8,6,1],{'tansig','tansig','purelin'},'trainlm');%此时的minmax函数是正确的,minmax是在每一行取最大最小值,而这也是有意义的
%设置训练次数
net.trainParam.epochs = 5000;
%设置收敛误差
net.trainParam.goal=0.0000001;
%训练网络
[net,tr]=train(net,p1,t1);
%TRAINLM, Epoch 0/5000, MSE 0.533351/1e-007, Gradient 18.9079/1e-010
%TRAINLM, Epoch 24/5000, MSE 8.81926e-008/1e-007, Gradient 0.0022922/1e-010
%TRAINLM, Performance goal met. %输入数据
a=[3.0;9.3;3.3;2.05;100;2.8;11.2;50];
%将输入数据归一化
a=premnmx(a);
%放入到网络输出数据
b=sim(net,a);
%将得到的数据反归一化得到预测数据
c=postmnmx(b,mint,maxt);
c
ex3.
close all;
clear;
clc;
%读取训练数据
[f1,f2,f3,f4,class] = textread('Train.txt','%f%f%f%f%d',75,'delimiter',',');
%特征值归一化
[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
%output=class';
%创建神经网络
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('Test.txt','%f%f%f%f%d',75,'delimiter',',');
%测试数据归一化
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)
拟合曲线:


[matlab]bp神经网络工具箱学习笔记的更多相关文章
- Matlab的BP神经网络工具箱及其在函数逼近中的应用
1.神经网络工具箱概述 Matlab神经网络工具箱几乎包含了现有神经网络的最新成果,神经网络工具箱模型包括感知器.线性网络.BP网络.径向基函数网络.竞争型神经网络.自组织网络和学习向量量化网络.反馈 ...
- Matlab神经网络工具箱学习之一
1.神经网络设计的流程 2.神经网络设计四个层次 3.神经网络模型 4.神经网络结构 5.创建神经网络对象 6.配置神经网络的输入输出 7.理解神经网络工具箱的数据结构 8.神经网络训练 1.神经网络 ...
- 卷积神经网络(CNN)学习笔记1:基础入门
卷积神经网络(CNN)学习笔记1:基础入门 Posted on 2016-03-01 | In Machine Learning | 9 Comments | 14935 Vie ...
- paper 75:使用MATLAB的神经网络工具箱创建神经网络
% 生成训练样本集 clear all; clc; P=[110 0.807 240 0.2 15 1 18 2 1.5; 110 2.865 240 0.1 15 2 12 1 2; 110 2.5 ...
- BP神经网络算法学习
BP(Back Propagation)网络是1986年由Rumelhart和McCelland为首的科学家小组提出,是一种按误差逆传播算法训练的多层前馈网络,是眼下应用最广泛的神经网络模型之中的一个 ...
- MATLAB的神经网络工具箱介绍
一.使用matlab2010b以后的版本会有完整的神经网络工具箱,使用nnstart可以调出toolbox,然后选择需要的功能,导入数据,选择训练参数和每层神经元个数,最后训练会输出网络与结果. 二. ...
- MATLAB——BP神经网络
1.使用误差反向传播(error back propagation )的网络就叫BP神经网络 2.BP网络的特点: 1)网络由多层构成,层与层之间全连接,同一层之间的神经元无连接 . 2)BP网络的传 ...
- [matlab]机器学习及SVM工具箱学习笔记
机器学习与神经网络的关系: 机器学习是目的,神经网络是算法.神经网络是实现机器学习的一种方法,平行于SVM. 常用的两种工具:svm tool.libsvm SVM分为SVC和SVR,svc是专门用来 ...
- Matlab神经网络工具箱学习之二
螃蟹的分类 这个例子的目的是根据螃蟹的品种.背壳的长宽等等属性来判断螃蟹的性别,雄性还是雌性. 训练数据一共有六个属性: species, frontallip, rearwidth, length, ...
随机推荐
- JQuery 双击动态编辑
$(this).append(input); $("input#temp").focus(); $("inp ...
- pygame躲敌人的游戏
#first.py# coding=utf- import pygame from pygame.locals import * from sys import exit from util impo ...
- java获取调用此方法的上面的方法名、类
StackTraceElement[] stacks = (new Throwable()).getStackTrace(); for (StackTraceElement stack : stack ...
- In a Web Application and Mobile (hybrid), how to know which this platform running?
needed depending on the platform to change the CSS to suit the size of the font. for example the DbG ...
- Spark-Spark setMaster & WordCount Demo
Spark setMaster源码 /** * The master URL to connect to, such as "local" to run locally with ...
- 仿联想商城laravel实战---4、验证(lavarel的表单验证如何使用)
仿联想商城laravel实战---4.验证(lavarel的表单验证如何使用) 一.总结 一句话总结: 验证规则和验证信息的数组:在控制器的方法中 1.注册页面中的用户名正确(比如是否重名,字段长度是 ...
- 宽度显示banner
今天解决了一个以前解决不了的问题,所以就想找博客园记录一些笔记. ……以前也遇到过这种满屏banner不知道怎么做的问题,问老师老师也说不出个所以然,百度搜了好几条 也不太满意... 所以就开始尝试摸 ...
- 修改Hosts文件,禁止访问指定网页
不知道Hosts文件什么鬼的朋友可以在网上搜索一下(大牛勿喷- -) 访问网址时,先查询本地的Hosts文件,那么如果我们将Hosts文件中的网址与IP的映射修改之后,将访问错误的IP. 如在文件尾追 ...
- STL memory.cpp
memory.cpp # // Filename: memory # # // Comment By: 凝霜 # // E-mail: mdl2009@vip.qq.com # // Blog: ht ...
- 【leetcode刷题笔记】Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...