当前位置:网站首页>《MATLAB 神經網絡43個案例分析》:第7章 RBF網絡的回歸--非線性函數回歸的實現
《MATLAB 神經網絡43個案例分析》:第7章 RBF網絡的回歸--非線性函數回歸的實現
2022-06-12 08:42: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網絡在視覺機器學習中應用的,具體實例可參考文末鏈接。對本章內容感興趣或者想充分學習了解的,建議去研習書中第七章節的內容。後期會對其中一些知識點在自己理解的基礎上進行補充,歡迎大家一起學習交流。
边栏推荐
- Configuration and principle of MSTP
- 2022.6.11-----leetcode. nine hundred and twenty-six
- 在Tensorflow中把Tensor转换为ndarray时,循环中不断调用run或者eval函数,代码运行越来越慢!
- FDA reviewers say Moderna covid vaccine is safe and effective for children under 5 years of age
- Loading font component loading effect
- In depth interpretation of 5g key technologies
- The electrical fire detector monitors each power circuit in real time
- Error: what if the folder cannot be deleted when it is opened in another program
- Py & go programming skills: logic control to avoid if else
- Handling abnormal data
猜你喜欢

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

The era of post MES system has come gradually

报错:清除网站内搜索框中的历史记录?

ctfshow web 1-2

Hands on learning and deep learning -- a brief introduction to softmax regression

Background attribute compound writing

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

X64dbg debugging exception_ ACCESS_ VIOLATION C0000005

What is the MES system? What is the operation process of MES system?

安科瑞电动机保护器具有过载反时限、过载定时限、接地、起动超时、漏电、欠载、断相、堵转等功能
随机推荐
Engineers learn music theory (I) try to understand music
Display the remaining valid days according to the valid period
Where does the driving force of MES system come from? What problems should be paid attention to in model selection?
MPLS的原理与配置
Regular verification user name
Webrtc adding third-party libraries
Production scheduling status of manufacturing enterprises and solutions of APS system
Hands on learning and deep learning -- simple implementation of linear regression
(p19-p20) delegate constructor (proxy constructor) and inheritance constructor (using)
Installation of Shengxin R package
[essence] explain in detail the memory management mechanism in QT
Loading font component loading effect
In the era of intelligent manufacturing, how do enterprises carry out digital transformation
Scope of bean
Background position - mixed units
[compilation principle] understand BNF
处理异常数据
Vscode download slow solution
Convert spaces to < br / > newline labels
The difference between deep copy and shallow copy