Abstract
This chapter introduces RBF neural network design method, gives RBF neural network approximation algorithm based on gradient descent, analyzes the effects of Gaussian function parameters on RBF approximation, and introduces RBF neural network modeling method based on off-line training. Several simulation examples are given.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Hartman EJ, Keeler JD, Kowalski JM (1990) Layered neural networks with Gaussian hidden units as universal approximations. Neural Comput 2(2):210–215
Park J, Sandberg LW (1991) Universal approximation using radial-basis-function networks. Neural Comput 3(2):246–257
Author information
Authors and Affiliations
Appendix
Appendix
2.1.1 Programs for Sect. 2.1.2.1
Simulink main program: chap2_1sim.mdl
RBF function: chap2_1rbf.m
function [sys,x0,str,ts] = spacemodel(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 7;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [];
function sys=mdlOutputs(t,x,u)
x=u(1); %Input Layer
%i=1
%j=1,2,3,4,5
%k=1
c=[-0.5 -0.25 0 0.25 0.5]; %cij
b=[0.2 0.2 0.2 0.2 0.2]'; %bj
W=ones(5,1); %Wj
h=zeros(5,1); %hj
for j=1:1:5
h(j)=exp(-norm(x-c(:,j))^2/(2*b(j)*b(j))); %Hidden Layer
end
y=W'*h; %Output Layer
sys(1)=y;
sys(2)=x;
sys(3)=h(1);
sys(4)=h(2);
sys(5)=h(3);
sys(6)=h(4);
sys(7)=h(5);
Plot program: chap2_1plot.m
close all;
% y=y(:,1);
% x=y(:,2);
% h1=y(:,3);
% h2=y(:,4);
% h3=y(:,5);
% h4=y(:,6);
% h5=y(:,7);
figure(1);
plot(t,y(:,1),'k','linewidth',2);
xlabel('time(s)');ylabel('y');
figure(2);
plot(y(:,2),y(:,3),'k','linewidth',2);
xlabel('x');ylabel('hj');
hold on;
plot(y(:,2),y(:,4),'k','linewidth',2);
hold on;
plot(y(:,2),y(:,5),'k','linewidth',2);
hold on;
plot(y(:,2),y(:,6),'k','linewidth',2);
hold on;
plot(y(:,2),y(:,7),'k','linewidth',2);
2.1.2 Programs for Sect. 2.1.2.2
Simulink main program: chap2_2sim.mdl
RBF function: chap2_2rbf.m
function [sys,x0,str,ts] = spacemodel(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {2,4,9}
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 8;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [];
function sys=mdlOutputs(t,x,u)
x1=u(1); %Input Layer
x2=u(2);
x=[x1 x2]';
%i=2
%j=1,2,3,4,5
%k=1
c=[-0.5 -0.25 0 0.25 0.5;
-0.5 -0.25 0 0.25 0.5]; %cij
b=[0.2 0.2 0.2 0.2 0.2]'; %bj
W=ones(5,1); %Wj
h=zeros(5,1); %hj
for j=1:1:5
h(j)=exp(-norm(x-c(:,j))^2/(2*b(j)*b(j))); %Hidden Layer
end
yout=W'*h; %Output Layer
sys(1)=yout;
sys(2)=x1;
sys(3)=x2;
sys(4)=h(1);
sys(5)=h(2);
sys(6)=h(3);
sys(7)=h(4);
sys(8)=h(5);
Plot program: chap2_2plot.m
close all;
% y=y(:,1);
% x1=y(:,2);
% x2=y(:,3);
% h1=y(:,4);
% h2=y(:,5);
% h3=y(:,6);
% h4=y(:,7);
% h5=y(:,8);
figure(1);
plot(t,y(:,1),'k','linewidth',2);
xlabel('time(s)');ylabel('y');
figure(2);
plot(y(:,2),y(:,4),'k','linewidth',2);
xlabel('x1');ylabel('hj');
hold on;
plot(y(:,2),y(:,5),'k','linewidth',2);
hold on;
plot(y(:,2),y(:,6),'k','linewidth',2);
hold on;
plot(y(:,2),y(:,7),'k','linewidth',2);
hold on;
plot(y(:,2),y(:,8),'k','linewidth',2);
figure(3);
plot(y(:,3),y(:,4),'k','linewidth',2);
xlabel('x2');ylabel('hj');
hold on;
plot(y(:,3),y(:,5),'k','linewidth',2);
hold on;
plot(y(:,3),y(:,6),'k','linewidth',2);
hold on;
plot(y(:,3),y(:,7),'k','linewidth',2);
hold on;
plot(y(:,3),y(:,8),'k','linewidth',2);
2.1.3 Programs for Sect. 2.2.2.1
Simulink main program: chap2_3sim.mdl
S function for plant: chap2_3rbf.m
function [sys,x0,str,ts]=s_function(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys=mdlOutputs(t,x,u);
case {2, 4, 9 }
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys=simsizes(sizes);
x0=[];
str=[];
ts=[];
function sys=mdlOutputs(t,x,u)
persistent w w_1 w_2 b ci
alfa=0.05;
xite=0.5;
if t==0
b=1.5;
ci=[-1 -0.5 0 0.5 1;
-10 -5 0 5 10];
w=rands(5,1);
w_1=w;w_2=w_1;
end
ut=u(1);
yout=u(2);
xi=[ut yout]';
for j=1:1:5
h(j)=exp(-norm(xi-ci(:,j))^2/(2*b^2));
end
ymout=w'*h';
d_w=0*w;
for j=1:1:5 %Only weight value update
d_w(j)=xite*(yout-ymout)*h(j);
end
w=w_1+d_w+alfa*(w_1-w_2);
w_2=w_1;w_1=w;
sys(1)=ymout;
S function for plant: chap2_3plant.m
function [sys,x0,str,ts]=s_function(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 1,
sys=mdlDerivatives(t,x,u);
case 3,
sys=mdlOutputs(t,x,u);
case {2, 4, 9 }
sys = [];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 0;
sys=simsizes(sizes);
x0=[0,0];
str=[];
ts=[];
function sys=mdlDerivatives(t,x,u)
sys(1)=x(2);
sys(2)=-25*x(2)+133*u;
function sys=mdlOutputs(t,x,u)
sys(1)=x(1);
Plot program: chap2_3plot.m
close all;
figure(1);
plot(t,y(:,1),'r',t,y(:,2),'k:','linewidth',2);
xlabel('time(s)');ylabel('y and ym');
legend('ideal signal','signal approximation');
2.1.4 Programs for Sect. 2.2.2.2
Matlab program: chap2_4.m
%RBF identification
clear all;
close all;
alfa=0.05;
xite=0.15;
x=[0,1]';
b=3*ones(5,1);
c=[-1 -0.5 0 0.5 1;
-1 -0.5 0 0.5 1];
w=rands(5,1);
w_1=w;w_2=w_1;
c_1=c;c_2=c_1;
b_1=b;b_2=b_1;
d_w=0*w;
d_b=0*b;
y_1=0;
ts=0.001;
for k=1:1:10000
time(k)=k*ts;
u(k)=sin(k*ts);
y(k)=u(k)^3+y_1/(1+y_1^2);
x(1)=u(k);
x(2)=y_1;
for j=1:1:5
h(j)=exp(-norm(x-c(:,j))^2/(2*b(j)*b(j)));
end
ym(k)=w'*h';
em(k)=y(k)-ym(k);
M=2;
if M==1 %Only weight value update
d_w(j)=xite*em(k)*h(j);
elseif M==2 %Update w,b,c
for j=1:1:5
d_w(j)=xite*em(k)*h(j);
d_b(j)=xite*em(k)*w(j)*h(j)*(b(j)^-3)*norm (x-c(:,j))^2;
for i=1:1:2
d_c(i,j)=xite*em(k)*w(j)*h(j)*(x(i)-c(i,j))*(b(j)^-2);
end
end
b=b_1+d_b+alfa*(b_1-b_2);
c=c_1+d_c+alfa*(c_1-c_2);
end
w=w_1+d_w+alfa*(w_1-w_2);
y_1=y(k);
w_2=w_1;
w_1=w;
c_2=c_1;
c_1=c;
b_2=b_1;
b_1=b;
end
figure(1);
subplot(211);
plot(time,y,'r',time,ym,'k:','linewidth',2);
xlabel('time(s)');ylabel('y and ym');
legend('ideal signal','signal approximation');
subplot(212);
plot(time,y-ym,'k','linewidth',2);
xlabel('time(s)');ylabel('error');
2.1.5 Programs for Sect. 2.3
Program of Gaussian membership function design: chap2_5.m
%RBF function
clear all;
close all;
c=[-3 -1.5 0 1.5 3];
M=1;
if M==1
b=0.50*ones(5,1);
elseif M==2
b=1.50*ones(5,1);
end
h=[0,0,0,0,0]';
ts=0.001;
for k=1:1:2000
time(k)=k*ts;
%RBF function
x(1)=3*sin(2*pi*k*ts);
for j=1:1:5
h(j)=exp(-norm(x-c(:,j))^2/(2*b(j)*b(j)));
end
x1(k)=x(1);
%First Redial Basis Function
h1(k)=h(1);
%Second Redial Basis Function
h2(k)=h(2);
%Third Redial Basis Function
h3(k)=h(3);
%Fourth Redial Basis Function
h4(k)=h(4);
%Fifth Redial Basis Function
h5(k)=h(5);
end
figure(1);
plot(x1,h1,'b');
figure(2);
plot(x1,h2,'g');
figure(3);
plot(x1,h3,'r');
figure(4);
plot(x1,h4,'c');
figure(5);
plot(x1,h5,'m');
figure(6);
plot(x1,h1,'b');
hold on;plot(x1,h2,'g');
hold on;plot(x1,h3,'r');
hold on;plot(x1,h4,'c');
hold on;plot(x1,h5,'m');
xlabel('Input value of Redial Basis Function');ylabel('Membership function degree');
Program of RBF approximation to test the effect of b and c: chap2_6.m
%RBF approximation test
clear all;
close all;
alfa=0.05;
xite=0.5;
x=[0,0]';
%The parameters design of Guassian Function
%The input of RBF (u(k),y(k)) must be in the effect range of Guassian function overlay
%The value of b represents the widenth of Guassian function overlay
Mb=1;
if Mb==1 %The width of Guassian function is moderate
b=1.5*ones(5,1);
elseif Mb==2 %The width of Guassian function is too narrow, most overlap of the function is near to zero
b=0.0005*ones(5,1);
end
%The value of c represents the center position of Guassian function overlay
%the NN structure is 2-5-1: i=2; j=1,2,3,4,5; k=1
Mc=1;
if Mc==1 %The center position of Guassian function is moderate
c=[-1.5 -0.5 0 0.5 1.5;
-1.5 -0.5 0 0.5 1.5]; %cij
elseif Mc==2 %The center position of Guassian function is improper
c=0.1*[-1.5 -0.5 0 0.5 1.5;
-1.5 -0.5 0 0.5 1.5]; %cij
end
w=rands(5,1);
w_1=w;w_2=w_1;
y_1=0;
ts=0.001;
for k=1:1:2000
time(k)=k*ts;
u(k)=0.50*sin(1*2*pi*k*ts);
y(k)=u(k)^3+y_1/(1+y_1^2);
x(1)=u(k);
x(2)=y(k);
for j=1:1:5
h(j)=exp(-norm(x-c(:,j))^2/(2*b(j)*b(j)));
end
ym(k)=w'*h';
em(k)=y(k)-ym(k);
d_w=xite*em(k)*h';
w=w_1+ d_w+alfa*(w_1-w_2);
y_1=y(k);
w_2=w_1;w_1=w;
end
figure(1);
plot(time,y,'r',time,ym,'b:','linewidth',2);
xlabel('time(s)');ylabel('y and ym');
legend('Ideal value','Approximation value');
2.1.6 Programs for Sect. 2.4
Program of RBF approximation to test the effect of hidden nets number: chap2_7.m
%RBF approximation test
clear all;
close all;
alfa=0.05;
xite=0.3;
x=[0,0]';
%The parameters design of Guassian Function
%The input of RBF (u(k),y(k)) must be in the effect range of Guassian function overlay
%The value of b represents the widenth of Guassian function overlay
bj=1.5; %The width of Guassian function
%The value of c represents the center position of Guassian function overlay
%the NN structure is 2-m-1: i=2; j=1,2,…,m; k=1
M=3; %Different hidden nets number
if M==1 %only one hidden net
m=1;
c=0;
elseif M==2
m=3;
c=1/3*[-1 0 1;
-1 0 1];
elseif M==3
m=7;
c=1/9*[-3 -2 -1 0 1 2 3;
-3 -2 -1 0 1 2 3];
end
w=zeros(m,1);
w_1=w;w_2=w_1;
y_1=0;
ts=0.001;
for k=1:1:5000
time(k)=k*ts;
u(k)=sin(k*ts);
y(k)=u(k)^3+y_1/(1+y_1^2);
x(1)=u(k);
x(2)=y(k);
for j=1:1:m
h(j)=exp(-norm(x-c(:,j))^2/(2*bj^2));
end
ym(k)=w'*h';
em(k)=y(k)-ym(k);
d_w=xite*em(k)*h';
w=w_1+ d_w+alfa*(w_1-w_2);
y_1=y(k);
w_2=w_1;w_1=w;
x1(k)=x(1);
for j=1:1:m
H(j,k)=h(j);
end
if k==5000
figure(1);
for j=1:1:m
plot(x1,H(j,:),'linewidth',2);
hold on;
end
xlabel('Input value of Redial Basis Function');ylabel('Membership function degree');
end
end
figure(2);
subplot(211);
plot(time,y,'r',time,ym,'b:','linewidth',2);
xlabel('time(s)');ylabel('y and ym');
legend('Ideal value','Approximation value');
subplot(212);
plot(time,y-ym,'r','linewidth',2);
xlabel('time(s)');ylabel('Approximation error');
2.1.7 Programs for Sect. 2.5.2.1
Program of RBF training: chap2_8a.m
%RBF Training for MIMO
clear all;
close all;
xite=0.10;
alfa=0.05;
W=rands(5,2);
W_1=W;
W_2=W_1;
h=[0,0,0,0,0]';
c=2*[-0.5 -0.25 0 0.25 0.5;
-0.5 -0.25 0 0.25 0.5;
-0.5 -0.25 0 0.25 0.5]; %cij
b=10; %bj
xs=[1,0,0];%Ideal Input
ys=[1,0]; %Ideal Output
OUT=2;
NS=1;
k=0;
E=1.0;
while E>=1e-020
%for k=1:1:1000
k=k+1;
times(k)=k;
for s=1:1:NS %MIMO Samples
x=xs(s,:);
for j=1:1:5
h(j)=exp(-norm(x'-c(:,j))^2/(2*b^2)); %Hidden Layer
end
yl=W'*h; %Output Layer
el=0;
y=ys(s,:);
for l=1:1:OUT
el=el+0.5*(y(l)-yl(l))^2; %Output error
end
es(s)=el;
E=0;
if s==NS
for s=1:1:NS
E=E+es(s);
end
end
error=y-yl';
dW=xite*h*error;
W=W_1+dW+alfa*(W_1-W_2);
W_2=W_1;W_1=W;
end %End of for
Ek(k)=E;
end %End of while
figure(1);
plot(times,Ek,'r','linewidth',2);
xlabel('k');ylabel('Error index change');
save wfile b c W;
Program of RBF test: chap2_8b.m
%Test RBF
clear all;
load wfile b c W;
%N Samples
x=[0.970,0.001,0.001;
1.000,0.000,0.000];
NS=2;
h=zeros(5,1); %hj
for i=1:1:NS
for j=1:1:5
h(j)=exp(-norm(x(i,:)'-c(:,j))^2/(2*b^2)); %Hidden Layer
end
yl(i,:)=W'*h; %Output Layer
end
yl
2.1.8 Programs for Sect. 2.5.2.2
Program of RBF training: chap2_9a.m
%RBF Training for a Plant
clear all;
close all;
ts=0.001;
xite=0.50;
alfa=0.05;
u_1=0;y_1=0;
fx_1=0;
W=0.1*ones(1,7);
W_1=W;
W_2=W_1;
h=zeros(7,1);
c1=[-3 -2 -1 0 1 2 3];
c2=[-3 -2 -1 0 1 2 3];
c=[c1;c2];
b=1.5; %bj
NS=3000;
for s=1:1:NS %Samples
u(s)=sin(s*ts);
fx(s)=0.5*y_1*(1-y_1)/(1+exp(-0.25*y_1));
y(s)=fx_1+u_1;
u_1=u(s);
y_1=y(s);
fx_1=fx(s);
end
k=0;
for k=1:1:500
k=k+1;
times(k)=k;
for s=1:1:NS %Samples
x=[u(s),y(s)];
for j=1:1:7
h(j)=exp(-norm(x'-c(:,j))^2/(2*b^2)); %Hidden Layer
end
yl(s)=W*h; %Output Layer
el=0.5*(y(s)-yl(s))^2; %Output error
es(s)=el;
E=0;
if s==NS
for s=1:1:NS
E=E+es(s);
end
end
error=y(s)-yl(s);
dW=xite*h'*error;
W=W_1+dW+alfa*(W_1-W_2);
W_2=W_1;W_1=W;
end %End of for
Ek(k)=E;
end %End of while
figure(1);
plot(times,Ek,'r','linewidth',2);
xlabel('k');ylabel('Error index change');
save wfile b c W NS;
Program of RBF test: chap2_9b.m
%Online RBF Etimation for Plant
clear all;
load wfile b c W NS;
ts=0.001;
u_1=0;y_1=0;
fx_1=0;
h=zeros(7,1);
for k=1:1:NS
times(k)=k;
u(k)=sin(k*ts);
fx(k)=0.5*y_1*(1-y_1)/(1+exp(-0.25*y_1));
y(k)=fx_1+u_1;
x=[u(k),y(k)];
for j=1:1:7
h(j)=exp(-norm(x'-c(:,j))^2/(2*b^2)); %Hidden Layer
end
yp(k)=W*h; %Output Layer
u_1=u(k);y_1=y(k);
fx_1=fx(k);
end
figure(1);
plot(times,y,'r',times,yp,'b-.','linewidth',2);
xlabel('times');ylabel('y and yp');
Rights and permissions
Copyright information
© 2013 Tsinghua University Press, Beijing and Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Liu, J. (2013). RBF Neural Network Design and Simulation. In: Radial Basis Function (RBF) Neural Network Control for Mechanical Systems. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-34816-7_2
Download citation
DOI: https://doi.org/10.1007/978-3-642-34816-7_2
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-34815-0
Online ISBN: 978-3-642-34816-7
eBook Packages: EngineeringEngineering (R0)