当前位置:网站首页>《MATLAB 神经网络43个案例分析》:第7章 RBF网络的回归--非线性函数回归的实现
《MATLAB 神经网络43个案例分析》:第7章 RBF网络的回归--非线性函数回归的实现
2022-06-12 08:41:00 【mozun2020】
《MATLAB 神经网络43个案例分析》:第7章 RBF网络的回归--非线性函数回归的实现
1. 前言
《MATLAB 神经网络43个案例分析》是MATLAB技术论坛(www.matlabsky.com)策划,由王小川老师主导,2013年北京航空航天大学出版社出版的关于MATLAB为工具的一本MATLAB实例教学书籍,是在《MATLAB神经网络30个案例分析》的基础上修改、补充而成的,秉承着“理论讲解—案例分析—应用扩展”这一特色,帮助读者更加直观、生动地学习神经网络。
《MATLAB神经网络43个案例分析》共有43章,内容涵盖常见的神经网络(BP、RBF、SOM、Hopfield、Elman、LVQ、Kohonen、GRNN、NARX等)以及相关智能算法(SVM、决策树、随机森林、极限学习机等)。同时,部分章节也涉及了常见的优化算法(遗传算法、蚁群算法等)与神经网络的结合问题。此外,《MATLAB神经网络43个案例分析》还介绍了MATLAB R2012b中神经网络工具箱的新增功能与特性,如神经网络并行计算、定制神经网络、神经网络高效编程等。
近年来随着人工智能研究的兴起,神经网络这个相关方向也迎来了又一阵研究热潮,由于其在信号处理领域中的不俗表现,神经网络方法也在不断深入应用到语音和图像方向的各种应用当中,本文结合书中案例,对其进行仿真实现,也算是进行一次重新学习,希望可以温故知新,加强并提升自己对神经网络这一方法在各领域中应用的理解与实践。自己正好在多抓鱼上入手了这本书,下面开始进行仿真示例,主要以介绍各章节中源码应用示例为主,本文主要基于MATLAB2015b(32位)平台仿真实现,这是本书第七章RBF网络的回归实例,话不多说,开始!
2. MATLAB 仿真示例一
打开MATLAB,点击“主页”,点击“打开”,找到示例文件
选中chapter7_1.m,点击“打开”
chapter7_1.m源码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%功能:RBF网络的回归--非线性函数回归的实现
%环境:Win7,Matlab2015b
%Modi: C.S
%时间:2022-06-09
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Matlab神经网络43个案例分析
% RBF网络的回归--非线性函数回归的实现
% by 王小川(@王小川_matlab)
% http://www.matlabsky.com
% Email:[email protected]163.com
% http://weibo.com/hgsz2003
%% 清空环境变量
clc
clear
%% 产生输入 输出数据
tic
% 设置步长
interval=0.01;
% 产生x1 x2
x1=-1.5:interval:1.5;
x2=-1.5:interval:1.5;
% 按照函数先求得相应的函数值,作为网络的输出。
F =20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2);
%% 网络建立和训练
% 网络建立 输入为[x1;x2],输出为F。Spread使用默认。
net=newrbe([x1;x2],F)
%% 网络的效果验证
% 我们将原数据回带,测试网络效果:
ty=sim(net,[x1;x2]);
% 我们使用图像来看网络对非线性函数的拟合效果
figure
plot3(x1,x2,F,'rd');
hold on;
plot3(x1,x2,ty,'b-.');
view(113,36)
title('可视化的方法观察准确RBF神经网络的拟合效果')
xlabel('x1')
ylabel('x2')
zlabel('F')
grid on
toc
添加完毕,点击“运行”,开始仿真,输出仿真结果如下:
net =
Neural Network
name: 'Radial Basis Network, Exact'
userdata: (your custom info)
dimensions:
numInputs: 1
numLayers: 2
numOutputs: 1
numInputDelays: 0
numLayerDelays: 0
numFeedbackDelays: 0
numWeightElements: 1205
sampleTime: 1
connections:
biasConnect: [1; 1]
inputConnect: [1; 0]
layerConnect: [0 0; 1 0]
outputConnect: [0 1]
subobjects:
input: Equivalent to inputs{
1}
output: Equivalent to outputs{
2}
inputs: {
1x1 cell array of 1 input}
layers: {
2x1 cell array of 2 layers}
outputs: {
1x2 cell array of 1 output}
biases: {
2x1 cell array of 2 biases}
inputWeights: {
2x1 cell array of 1 weight}
layerWeights: {
2x2 cell array of 1 weight}
functions:
adaptFcn: (none)
adaptParam: (none)
derivFcn: 'defaultderiv'
divideFcn: (none)
divideParam: (none)
divideMode: 'sample'
initFcn: 'initlay'
performFcn: 'mse'
performParam: .regularization, .normalization
plotFcns: {
}
plotParams: {
1x0 cell array of 0 params}
trainFcn: (none)
trainParam: (none)
weight and bias values:
IW: {
2x1 cell} containing 1 input weight matrix
LW: {
2x2 cell} containing 1 layer weight matrix
b: {
2x1 cell} containing 2 bias vectors
methods:
adapt: Learn while in continuous use
configure: Configure inputs & outputs
gensim: Generate Simulink model
init: Initialize weights & biases
perform: Calculate performance
sim: Evaluate network outputs given inputs
train: Train network with examples
view: View diagram
unconfigure: Unconfigure inputs & outputs
时间已过 0.766958 秒。

3. MATLAB 仿真示例二
双击当前文件夹视图中的chapter7_2.m,打开chapter7_2.m源码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%功能:RBF网络的回归--非线性函数回归的实现
%环境:Win7,Matlab2015b
%Modi: C.S
%时间:2022-06-09
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Matlab神经网络43个案例分析
% RBF网络的回归--非线性函数回归的实现
% by 王小川(@王小川_matlab)
% http://www.matlabsky.com
% Email:[email protected]163.com
% http://weibo.com/hgsz2003
%% 清空环境变量
clc
clear
%% 产生训练样本(训练输入,训练输出)
tic
% ld为样本例数
ld=400;
% 产生2*ld的矩阵
x=rand(2,ld);
% 将x转换到[-1.5 1.5]之间
x=(x-0.5)*1.5*2;
% x的第一行为x1,第二行为x2.
x1=x(1,:);
x2=x(2,:);
% 计算网络输出F值
F=20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2);
%% 建立RBF神经网络
% 采用approximate RBF神经网络。spread为默认值
net=newrb(x,F);
%% 建立测试样本
% generate the testing data
interval=0.1;
[i, j]=meshgrid(-1.5:interval:1.5);
row=size(i);
tx1=i(:);
tx1=tx1';
tx2=j(:);
tx2=tx2';
tx=[tx1;tx2];
%% 使用建立的RBF网络进行模拟,得出网络输出
ty=sim(net,tx);
%% 使用图像,画出3维图
% 真正的函数图像
interval=0.1;
[x1, x2]=meshgrid(-1.5:interval:1.5);
F = 20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2);
subplot(1,3,1)
mesh(x1,x2,F);
zlim([0,60])
title('真正的函数图像')
% 网络得出的函数图像
v=reshape(ty,row);
subplot(1,3,2)
mesh(i,j,v);
zlim([0,60])
title('RBF神经网络结果')
% 误差图像
subplot(1,3,3)
mesh(x1,x2,F-v);
zlim([0,60])
title('误差图像')
set(gcf,'position',[300 ,250,900,400])
toc
点击“运行”,开始仿真,输出仿真结果如下:
NEWRB, neurons = 0, MSE = 111.628
NEWRB, neurons = 50, MSE = 4.70402
NEWRB, neurons = 100, MSE = 0.00159245
NEWRB, neurons = 150, MSE = 1.23329e-05
NEWRB, neurons = 200, MSE = 5.13919e-07
NEWRB, neurons = 250, MSE = 1.7818e-07
NEWRB, neurons = 300, MSE = 5.68933e-08
NEWRB, neurons = 350, MSE = 3.98896e-08
NEWRB, neurons = 400, MSE = 3.84391e-08
时间已过 8.069210 秒。

4. 小结
RBF(Radial Basis Function, 径向基函数)网络一般来说,是一种单隐层前馈神经网络,它使用径向基函数作为隐含层神经元激活函数,而输出层则是对隐含层神经元输出的线性组合。在我的专栏《视觉机器学习20讲-MATLAB源码示例》中也有进行介绍,RBF在SVM中也作为核函数进行过集成,想参考RBF网络在视觉机器学习中应用的,具体实例可参考文末链接。对本章内容感兴趣或者想充分学习了解的,建议去研习书中第七章节的内容。后期会对其中一些知识点在自己理解的基础上进行补充,欢迎大家一起学习交流。
边栏推荐
- 【指針進階三】實現C語言快排函數qsort&回調函數
- R loop assignment variable name
- FDA reviewers say Moderna covid vaccine is safe and effective for children under 5 years of age
- 正则校验用户名
- 安科瑞电动机保护器具有过载反时限、过载定时限、接地、起动超时、漏电、欠载、断相、堵转等功能
- At present, MES is widely used. Why are there few APS scheduling systems? Why?
- Project sorting of niuke.com
- (p17-p18) define the basic type and function pointer alias by using, and define the alias for the template by using and typedef
- Hands on learning and deep learning -- simple implementation of linear regression
- 进制GB和GiB的区别
猜你喜欢

【新规划】

Hands on deep learning -- implementation of multi-layer perceptron from scratch and its concise implementation

处理异常数据

Figure neural network makes Google maps more intelligent

Hands on deep learning -- concise implementation code of weight decay

Hands on learning and deep learning -- Realization of linear regression from scratch

Background location case 1

Hands on deep learning -- Introduction to linear regression model

Hands on deep learning 18 -- model selection + over fitting and under fitting and code implementation

【 pointeur avancé Ⅲ】 mise en œuvre de la fonction de tri rapide qsort& fonction de rappel en langage C
随机推荐
When converting tensor to ndarray in tensorflow, the run or Eval function is constantly called in the loop, and the code runs more and more slowly!
(p17-p18) define the basic type and function pointer alias by using, and define the alias for the template by using and typedef
2022.6.9-----leetcode.497
In the era of intelligent manufacturing, how do enterprises carry out digital transformation
This article is required for the popularization of super complete MES system knowledge
Random acquisition of 4-digit non repeated verification code
Never use MES as a tool, or you will miss the most important thing
Convert spaces to < br / > newline labels
Hands on learning and deep learning -- Realization of linear regression from scratch
What is the MES system? What is the operation process of MES system?
深拷贝与浅拷贝的区别
MPLS的原理与配置
Configuration and principle of MSTP
Callback webrtc underlying logs to the application layer
Project sorting of niuke.com
What is the quality traceability function of MES system pursuing?
Background position - exact units
判断对象是否为空
What scheduling rules does the APS software have? What is the exception handling scheme?
JS to refresh the page after loading