当前位置:网站首页>《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网络在视觉机器学习中应用的,具体实例可参考文末链接。对本章内容感兴趣或者想充分学习了解的,建议去研习书中第七章节的内容。后期会对其中一些知识点在自己理解的基础上进行补充,欢迎大家一起学习交流。
边栏推荐
- 2022.6.9-----leetcode. four hundred and ninety-seven
- ctfshow web3
- Build personal blog and web.
- [advanced pointer III] implement C language quick sorting function qsort & callback function
- FDA reviewers say Moderna covid vaccine is safe and effective for children under 5 years of age
- 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!
- [data storage] storage of floating point data in memory
- Background position - exact units
- At present, MES is widely used. Why are there few APS scheduling systems? Why?
- Vscade debug TS
猜你喜欢

ctfshow web4

报错:文件夹在另一个程序中打开无法删除怎么办

【数据存储】浮点型数据在内存中的存储

Hands on deep learning -- discarding method and its code implementation

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

This article is required for the popularization of super complete MES system knowledge

Hypergeometric cumulative distribution test overlap

Webrtc series - mobile terminal hardware coding supports simulcast
![[GUI development] browsing function implementation model of image processing software](/img/37/2162a6047682b9cfc9b8b7c2488068.jpg)
[GUI development] browsing function implementation model of image processing software

Engineers learn music theory (II) scale and tendency
随机推荐
Query in MySQL
Lock mechanism in MySQL
Error: clear the history in the search box in the website?
Where does the driving force of MES system come from? What problems should be paid attention to in model selection?
Difference between binary GB and gib
Detailed explanation of private, public and interface attributes in cmake
Background location case II
Display the remaining valid days according to the valid period
Audio and video related links
Call method and apply method
JVM学习笔记:三 本地方法接口、执行引擎
【新规划】
Encapsulate the amount input box component.
The newline character with in the string is converted to an array
What is the MES system? What is the operation process of MES system?
Webrtc adding third-party libraries
Code generation tool Autocode for XML Publishing
Judge whether the object is empty
Is it really expensive for enterprises to launch MES software?
Random acquisition of 4-digit non repeated verification code