RBF neural network function regression case (MATLAB)

I am also a neural network novice. Recently I have been learning neural network algorithms and have done many cases, so I will start with the simplest RBF neural network. This time I will show how I use RBF neural network to perform regression analysis on functions.

// learning data
// generate the learning data
clc;
clear;
close all;
Id=400;
x=rand(2,Id);
x=(x-0.5)*2*1.5;
x1=x(1,:);
x2=x(2,:);
F=20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2);

2. RBF neural network training

// RBF神经网络训练
// RBF神经网络训练
net=newrb(x,F);//直接调用现成函数

3. Generate test 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];;

4. Substituting into the predictive model
Here are some 内联代码片.

// 代入预测模型
//代入预测模型
ty=sim(net,tx);
v=reshape(ty,row);
figure
subplot(1,3,2)
mesh(i,j,v)
zlim([0,60]);

5. Draw the original function model and calculate the error

//画出原始函数模型
// 画出原始函数模型
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])
%%plot the error
subplot(1,3,3)
mesh(x1,x2,F-v);
zlim([0,60]);

6. Result analysis
forecast result
To sum up, it can be seen that the overall results obtained from the 400 training data are still very good, except for the errors in the corners and the remaining errors are small.

Guess you like

Origin blog.csdn.net/qq_42955211/article/details/106346390