Professional Documents
Culture Documents
Matlab code used to fit a Radial Basis function for the above values is given in the Annexure1. The value
of Y from the RBNN is given below for a spread of 0.5 with 3 centers and with a mean squared error goal
of 0.01:
A plot showing both the function Y with noise and the values of Y from the Radial Basis neural network
function is shown below:
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
NOTE THAT THE PLOT SHOULD SHOW ONLY THE DATA POINTS RATHER THAN CONNECT
THEM BY A LINE, SINCE THE LINE DOES NOT HAVE ANY MEANING.
ANAND PARTHASARATHY UFID: 6692-7926
(b) Calculate the error statistics of the fit using the equations developed in Chapters 3 and 4 of the
notes (including R2, the standard error, and the maximum prediction variance)
RMS error,
, 1
0.007488
,
6 3
, .
Since, we have 6 data points, choosing 3 centers from the six data points will lead to a 20 possible
combination of centers. Since, we already have values of Yhat from newrb function, we generated the
values of Y using the following weights formula:
Y = w 1 Ф1 + w 2 Ф2 + w 3 Ф3
and w1, w2, w3 – are the weights of the shape functions corresponding to the three centers.
ANAND PARTHASARATHY UFID: 6692-7926
The matlab code is given in the Appendix 2. When the shape functions were evaluated and the
corresponding weights, we obtained the three centers [0 0.8 1] which closely matched the values
generated by the matlab function newrb. So the three centers chosen for the calculation of the error
measures are [0 0.8 1].
The weights for the shape functions using the above mentioned centers is calculated using the formula,
Where, | | , X being the data points and C being the centers and σ is the spread which is 0.5.
Therefore, for each center we have six values of the shape function since there are six data points.
The shape functions matrix for the six points corresponding to centers X = 0, 0.8 and 1 are given below:
Therefore, maximum prediction variance occurs at the point X = 1 with the value
(c) Compare the error statistics with the actual errors at the data points and in a dense grid of 101
points in (0,1)
After having generated the RBNN surrogate with three centers, the data range of (0,1) is divided into a
dense grid of 101 points with an interval of 0.01. The values of the function at all these 101 points are
calculated using the surrogate toolbox. The actual error at all these 101 points is the difference between
the value of the true function at these points and the values predicted by the surrogate. The table in the
annexure gives the values and the corresponding actual errors at the 101 points and the six data points:
rms of the actual error at 101 points,
ANAND PARTHASARATHY UFID: 6692-7926
0.13573
101
0.0366
0.03553
, 0.0499
0.0814
(d) Kriging:
Fit with Kriging using a constant trend (ordinary Kriging) and compare accuracy at 101 points with
RBNN(remember that the exact function is y=x)
A Kriging surrogate is fitted using the surrogate toolbox (Matlab code attached in the Appendix 4) and
compared with the Radial Basis Neural Network function (RBNN) as shown in the graph below.
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
THIS IS RMS AT THE DATA POINTS, WHILE WHAT NEEDS TO BE COMPARED IS RMS ERROR AT
THE 101 POINTS.
(e) Fit with support vector regression using a polynomial of degree 1 as kernel and an epsilon-
insensitive loss function with epsilon of 0.1 (corresponding to the standard deviation of the noise)
and compare the accuracy at 101 points with the other two surrogates.
We have to fit a support vector regression with a linear polynomial. The epsilon value given in the
problem is 0.1. Also, the loss function is epsilon insensitive. The following parameters where used for the
support vector regression in the surrogate toolbox. The code used to generate the SVR is given in the
Annexure 5
The plot between the Support Vector Regression function, RBNN and the Kriging models are shown
below:
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
Function with SVR
0.1 Function fitted with Kriging
Function fitted with RBNN
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
X -->
As seen in the graph, the SVR does not map the true function exactly and hence has the highest rms
error.
ANAND PARTHASARATHY UFID: 6692-7926
(f) Check if you can get better fit with newrb using a different SPREAD:
With a spread of 1 as against a spread of 0.5, the following results are obtained for Radial Basis function
for the grid of 101 points:
Spread = 1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
As seen in the above plot, for a spread of 1 the surrogate improves appreciably and almost maps the true
function Y = X
Appendix 1:
a = axis;
axis([a(1) a(2) -1 1]);
Appendix 2: Matlab code to generate shape functions and compute prediction variance
X = [0;0.2;0.4;0.6;0.8;1];
Y = [ 0.119;0.16;0.433;0.617;0.781;0.928];
S = 0.5; % Spread
% Different possible centers combinations
c(1,:) = [ 0 0.2 0.4];
c(2,:) = [0 0.2 0.6];
c(3,:) = [0 0.2 0.8];
c(4,:) = [0 0.2 1];
c(5,:) = [0 0.4 0.6];
c(6,:) = [0 0.4 0.8];
c(7,:) = [0 0.4 1];
c(8,:) = [0 0.6 0.8];
c(9,:) = [0 0.6 1];
c(10,:) = [0 0.8 1];
c(11,:) = [0.2 0.4 0.6];
c(12,:) = [0.2 0.4 0.8];
c(13,:) = [0.2 0.4 1];
c(14,:) = [0.2 0.6 0.8];
c(15,:) = [0.2 0.6 1];
c(16,:) = [0.2 0.8 1];
c(17,:) = [0.4 0.6 0.8];
c(18,:) = [0.4 0.8 1];
c(19,:) = [0.6 0.8 1];
c(20,:) = [0.4 0.6 1];
for j = 1:20
for i =1:6
phi1(i) = exp(-(sum(X(i,:) - c(j,1)))^2/(2 * S^2));
phi2(i) = exp(-(sum(X(i,:) - c(j,2)))^2/(2 * S^2));
phi3(i) = exp(-(sum(X(i,:) - c(j,3)))^2/(2 * S^2));
end
phi = [phi1;phi2;phi3]';
% Compute the weights of the shape functions for each of the above
% mentioned 20 centers
w(:,j) = ((inv(phi'*phi))*phi')*Y;
end;
for j = 1:20
for i =1:6
phi1(i) = exp(-(sum(X(i,:) - c(j,1)))^2/(2 * S^2));
phi2(i) = exp(-(sum(X(i,:) - c(j,2)))^2/(2 * S^2));
phi3(i) = exp(-(sum(X(i,:) - c(j,3)))^2/(2 * S^2));
y(i,j) = w(1,j) * phi1(i) + w(2,j) * phi2(i) + w(3,j) * phi3(i);
end
end
for i =1:6
phi101(i) = exp(-(sum(X(i,:) - c(10,1)))^2/(2 * S^2));
phi102(i) = exp(-(sum(X(i,:) - c(10,2)))^2/(2 * S^2));
phi103(i) = exp(-(sum(X(i,:) - c(10,3)))^2/(2 * S^2));
Y10(i,1) = w(1,j) * phi1(i) + w(2,j) * phi2(i) + w(3,j) * phi3(i);
end
phi10 = [phi101;phi102;phi103]';
l = length(X);
for k=1:l
xm1(k) = exp(-(sum(X(k) - 0))^2/(2 * S^2));
xm2(k) = exp(-(sum(X(k) - 0.8))^2/(2 * S^2));
xm3(k) = exp(-(sum(X(k) - 1))^2/(2 * S^2));
end;
% Compute the prediction variance
for i = 1:6
pv(i) = [xm1(i) xm2(i) xm3(i)] * (inv(phi10'*phi10)) * [xm1(i) xm2(i)
xm3(i)]';
end
Appendix 3:
True
Surrogate values function
X at data points values Actual error
0 0.11006 0 0.11006
0.2 0.20843 0.2 0.00843
0.4 0.37955 0.4 ‐0.02045
0.6 0.61017 0.6 0.01017
0.8 0.82256 0.8 0.02256
1 0.90723 1 ‐0.09277
Surrogate True
values at 101 function Actual
X points values Error
0 0.11006 0 0.11006
0.01 0.11356 0.01 0.10356
0.02 0.11719 0.02 0.09719
0.03 0.12095 0.03 0.09095
0.04 0.12484 0.04 0.08484
0.05 0.12888 0.05 0.07888
0.06 0.13305 0.06 0.07305
ANAND PARTHASARATHY UFID: 6692-7926
X = [0:.01:1]';
Y = [0:.01:1]';
P = [0:.01:1];
T = [0:.01:1];
NbVariables = 1;
NbPointsTraining = length(X);
Theta0 = (NbPointsTraining^(-1/NbVariables))*ones(1,NbVariables);
LowerBound = 1e-3*ones(1,NbVariables);
UpperBound = 3*Theta0;
optionsKRG = srgtsOptionsSet(...
'P', X, ...
'T', Y, ...
'Surrogates', @srgtsKRG,...
'RegressionModel', @regpoly0, ...
'CorrelationModel', @corrgauss, ...
'Theta0', Theta0, ...
'LowerBound', LowerBound, ...
'UpperBound', UpperBound, ...
'Display','final');
PredictionMetrics = srgtsPredictionMetrics(X,Y,YhatKRG);
CorrelationCoefficient = PredictionMetrics.CorrelationCoefficient
RMSError = PredictionMetrics.RMSError
MaximumAbsoluteError = PredictionMetrics.MaximumAbsoluteError
ANAND PARTHASARATHY UFID: 6692-7926
P = [0:.01:1]';
T = [0:.01:1]';
Kernel = 'Linear';
KernelOptions = 1;
C = max( [ abs(mean(T) + 3*std(T)) , abs(mean(T) - 3*std(T)) ] );
% Insensitivity = std(T)/sqrt( NbPoints );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
[YhatSVR outputsSVR] = srgtsSimulate(P,surrogateSVR,optionsSVR);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% KRIGING
NbVariables = 1;
NbPointsTraining = length(P);
ANAND PARTHASARATHY UFID: 6692-7926
Theta0 = (NbPointsTraining^(-1/NbVariables))*ones(1,NbVariables);
LowerBound = 1e-3*ones(1,NbVariables);
UpperBound = 3*Theta0;
optionsKRG = srgtsOptionsSet(...
'P', P, ...
'T', T, ...
'Surrogates', @srgtsKRG,...
'RegressionModel', @regpoly0, ...
'CorrelationModel', @corrgauss, ...
'Theta0', Theta0, ...
'LowerBound', LowerBound, ...
'UpperBound', UpperBound, ...
'Display','final');
PredictionMetrics = srgtsPredictionMetrics(P,T,YhatKRG);
CorrelationCoefficient = PredictionMetrics.CorrelationCoefficient
RMSError = PredictionMetrics.RMSError
MaximumAbsoluteError = PredictionMetrics.MaximumAbsoluteError
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%RBNN
optionsRBNN = srgtsOptionsSet(...
'P', P, ...
'T', T, ...
'Surrogates', @srgtsRBNN,...
'Spread',0.5,...
'Goal',0.01,...
'MN',3,...
'DF',25,...
'Display','final');
% coeffRBNN = surrogateRBNN.PRSBeta;
[CVEMatrixRBNN, PRESSRMSRBNN, PRESSRBNN] =
srgtsComputeCrossValidation(optionsRBNN,surrogateRBNN);
PRESSRMSRBNN
PRESSRBNN
PredictionMetrics = srgtsPredictionMetrics(P,T,YhatRBNN);
ANAND PARTHASARATHY UFID: 6692-7926
CorrelationCoefficient = PredictionMetrics.CorrelationCoefficient
RMSError = PredictionMetrics.RMSError
MaximumAbsoluteError = PredictionMetrics.MaximumAbsoluteError
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h = plot(P, YhatSVR,...
P, YhatKRG,...
P, YhatRBNN);grid
set(h, 'LineWidth', 3);
set(h(1), 'LineStyle', '--', 'Color', [0 0 0]);
set(h(2), 'LineStyle', '-', 'Color', [0 0 1]);
set(h(3), 'LineStyle', '-.', 'Color', [1 0 0]);
axis tight;
legend('Function with SVR',...
'Function fitted with Kriging',...
'Function fitted with RBNN',...
'Location', 'SE');
xlabel('X -->');
a = axis;
axis([a(1) a(2) 0 1]);