RBF网络

来源:互联网 发布:软件工程设计招聘 编辑:程序博客网 时间:2024/05/23 19:11

在matlab中文论坛看到了rbf的视频,整理了一下,也方便以后自己记不起来时看一下,老师给了rbf的程序,自己加了点注释。




rbf分为两类,exact和approximate.

rbf与非线性回归的区别在于:rbf是不知道数学模型的,而非线性回归则是知道数学模型的,比如知道数据服从某种函数分布,只是系数不知道而已。

clc;

clear;
close all;

%rbf_approximate
% generate the learning data
ld=400; %训练数据的个数
x=rand(2,ld); %0-1
x=(x-0.5)*1.5*2; %-1.5, 1.5
x1=x(1,:);
x2=x(2,:);
F=20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2);


%创建并训练网络
net=newrb(x,F);


%generate the testing data
interval=0.1;
[i, j]=meshgrid(-1.5:interval:1.5);
row=size(i);%961
tx1=i(:);
tx1=tx1';
tx2=j(:);
tx2=tx2';
tx=[tx1;tx2];


%testing
ty=sim(net,tx);%执行simulink模型用的命令


v=reshape(ty,row);
figure
subplot(1,3,2)
mesh(i,j,v);
zlim([0,60])%zlim的是限定z坐标轴的区间范围


%plot the original function
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])


net.IW%查看权重,详细参考help

net,LW

net.b 可以查看bias


%rbf_

%Generate some training data

clc;
clear;
interval=0.01;
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);
net=newrbe([x1;x2],F)

ty=sim(net,[x1;x2]);
figure
plot3(x1,x2,F,'g');
figure
plot3(x1,x2,ty,'b');





0 0
原创粉丝点击