-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSinX_RBF.m
51 lines (42 loc) · 1.16 KB
/
SinX_RBF.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
close all;clear;clc;
%% Set inputs range
xmin = 0;
xmax = 2*pi;
%% without noise
x = linspace(xmin,xmax,20);
y = sin(x);
%% with noise
% x1 = linspace(xmin,xmax,50);
% y1 = sin(x1); % model;
%
% x = [x1,x1,x1,x1,x1,x1];
% % x = x1;
% x = x + randn(size(x))*.1;
% y = sin(x) + randn(size(x))*.1;
% plot(x1,y1,'r','linewidth',3),hold on,plot(x,y,'.')
% legend('Model','Noisy data')
%% Input & Target
inputs = x;
targets = y;
%% Create a RBF Network
goal = 0.000; % Mean squared error goal (default = 0.0)
spread = 3; % Spread of radial basis functions (default = 1.0)
MN = 30; % Maximum number of neurons
DF = 10; % Number of neurons to add between displays (default = 25)
net = newrb(inputs,targets,goal,spread,MN,DF);
view(net)
%% Test RBF Network
xtest = linspace(xmin,xmax,17);
ytest = sin(xtest);
output = net(xtest);
%% Compute error
mse_err = mse(ytest,output);
fprintf('Mean Squared Error of test data is %.4f \n',mse_err)
sse_err = sse(ytest,output);
fprintf('Sum of Squared Error of test data is %.4f \n',sse_err)
%% Plot result
figure
plot(xtest,ytest,'-*r');hold on;
plot(xtest,output,'--+');
xlim([xmin,xmax])
legend('Target','Output')