Solution 1:
mf_n=2;
epoch_n=200;
%training data developing
point_n = 6;
x = linspace(1, 6, point_n);
y = linspace(1, 6, point_n);
z = linspace(1, 6, point_n);
trn_data = zeros(length(x)*length(y)*length(z), 4);
count = 1;
for i = x,
for j = y;
for k = z;
out = (1+i^0.5+j^(-1)+k^(-1.5))^2;
trn_data(count, :) = [i j k out];
count = count + 1;
end
end
end
% Checking data
point_n = 5;
y = linspace(1.5, 5.5, point_n);
z = linspace(1.5, 5.5, point_n);
chk_data = zeros(length(x)*length(y)*length(z), 4);
count = 1;
for i = x,
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
for j = y;
for k = z;
out = (1+i^0.5+j^(-1)+k^(-1.5))^2;
chk_data(count, :) = [i j k out];
count = count + 1;
end
end
end
% ====== training options
ss = 0.1;
ss_dec_rate = 0.9;
ss_inc_rate = 1.1;
mf_type = 'gbellmf';
in_fismat = genfis1(trn_data, mf_n, mf_type);
% Initiating training
[trn_out_fismat trn_error step_size chk_out_fismat chk_error] = ...
anfis(trn_data, in_fismat, ...
[epoch_n nan ss ss_dec_rate ss_inc_rate], [1,1,1,1], chk_data);
% calculating the result
% plot MFs
% figH = genfig('MFs for the function training');
% plot initial MFs on x and y
subplot(221); plotmf(in_fismat, 'input', 1);
subplot(222); plotmf(trn_out_fismat, 'input', 1);
subplot(223); plotmf(trn_out_fismat, 'input', 2);
subplot(224); plotmf(trn_out_fismat, 'input', 3);
%delete(findobj(figH, 'type', 'text'));
subplot(221); title('Initial MFs on X, Y and Z');
subplot(222); title('Initial MFs on Y');
subplot(223); title('Final MFs on X');
subplot(224); title('Final MFs on Y');
figure
% ====== plot error curve and step size
% figH = genfig('Error curves and step sizes curve');
% blackbg;
subplot(121)
plot(1:epoch_n, [trn_error chk_error]);
legend('Error by Training', 'Error by Checking');
xlabel('Epoch #'); ylabel('Root Mean Squared Error');
title('Error Curves');
subplot(122)
plot(1:epoch_n, step_size);
xlabel('Epoch #'); ylabel('Step Size H');
title('Step Size Curve');
Command Window
ANFIS info:
Number of nodes: 34
1 0.605402 0.840439
2 0.580785 0.81979
3 0.555675 0.799724
4 0.530004 0.780112
5 0.503775 0.760763
6 0.477056 0.741444
7 0.44725 0.71992
8 0.417216 0.697789
9 0.38718 0.674759
10 0.357346 0.650629
11 0.324949 0.622684
12 0.293103 0.593291
13 0.261865 0.562559
14 0.231291 0.530666
15 0.198584 0.494464
16 0.167132 0.457549
17 0.137372 0.420513
18 0.109909 0.384289
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
19 0.0836592 0.346993
20 0.0648102 0.316079
21 0.0590948 0.293222
22 0.0580539 0.285828
23 0.0615965 0.309294
24 0.0573598 0.266621
25 0.0590593 0.316403
26 0.0552965 0.267676
27 0.0567471 0.316117
28 0.0513525 0.271271
29 0.0542111 0.313344
30 0.0495062 0.268819
31 0.0518612 0.311106
32 0.0462024 0.270935
33 0.0492266 0.307546
34 0.0444983 0.267866
35 0.0469129 0.305074
36 0.0416288 0.269383
37 0.0443303 0.301545
38 0.0400546 0.266276
39 0.042152 0.299223
40 0.0375143 0.267508
41 0.0397501 0.296002
42 0.0360715 0.264616
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
43 0.0377676 0.293921
44 0.0338096 0.265691
45 0.0356087 0.291076
46 0.0325023 0.263097
47 0.0338417 0.28923
48 0.0304928 0.26406
49 0.0319372 0.286737
50 0.0293224 0.261759
51 0.0303818 0.285097
52 0.0275479 0.262621
53 0.0287195 0.282906
54 0.0265127 0.260577
55 0.0273628 0.281438
56 0.024958 0.261344
57 0.0259235 0.2795
58 0.0240541 0.259518
59 0.0247511 0.278175
60 0.0227057 0.260191
61 0.0235173 0.27645
62 0.0219293 0.25855
63 0.0225175 0.275246
64 0.0207764 0.259132
65 0.0214762 0.273701
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
66 0.0201257 0.257648
67 0.0206416 0.272601
68 0.0191608 0.258145
69 0.0197851 0.271212
70 0.0186353 0.256799
71 0.0191109 0.270202
72 0.0178522 0.257218
73 0.0184313 0.268949
74 0.0174486 0.25599
75 0.0179083 0.268013
76 0.0168353 0.256336
77 0.0173879 0.26687
78 0.0165395 0.25521
79 0.0169928 0.265988
80 0.0160704 0.255484
81 0.0165954 0.26492
82 0.0158541 0.254431
83 0.016289 0.264067
84 0.0154914 0.254623
85 0.0159668 0.263033
86 0.0153214 0.253607
87 0.0157088 0.262186
88 0.0150273 0.253706
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
89 0.0154239 0.261157
90 0.0148789 0.252697
91 0.01519 0.260311
92 0.0146266 0.252704
93 0.0149267 0.25929
94 0.0144875 0.251703
95 0.0147091 0.258456
96 0.0142615 0.251638
97 0.014466 0.257466
98 0.0141267 0.250668
99 0.0142642 0.256661
Designated epoch number reached --> ANFIS training completed at epoch 200.
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
Second Solution
point_n = 6;
x = linspace(1, 6, point_n);
y = linspace(1, 6, point_n);
z = linspace(1, 6, point_n);
data = zeros(length(x)*length(y)*length(z), 4);
count = 1;
for i = x,
for j = y;
for k = z;
out = (1+i^0.5+j^(-1)+k^(-1.5))^2;
data(count, :) = [i j k out];
count = count + 1;
end
end
end
P=[data(:,[1,2,3])]';
T=[data(:,4)]';
%inputs x ,y ,z ranges from [1 to 6]
%network training function is to be used.
%network is simulated and its output plotted against the targets.
net = newff([1 6;1 6;1 6],[10 1],{'tansig' 'purelin'});
Y = sim(net,P);
%Here the network is trained for 200 epochs
net.trainParam.goal= 0.0;
net.trainParam.epochs = 200;
% Train data
net = train(net,P,T);
% checking data
point_n = 5;
x = linspace(1.5, 5.5, point_n);
y = linspace(1.5, 5.5, point_n);
z = linspace(1.5, 5.5, point_n);
chk_data = zeros(length(x)*length(y)*length(z), 4);
count = 1;
for i = x,
for j = y;
for k = z;
out = (1+i^0.5+j^(-1)+k^(-1.5))^2;
chk_data(count, :) = [i j k out];
count = count + 1;
end
end
end
Pck=[chk_data(:,[1,2,3])]';
Tck=[chk_data(:,4)]';
%Output for Checking and Training data.
Yck = sim(net,Pck);
Y = sim(net,P);
%Plotting data.
figure;
plot(Yck(1,:)-Tck,'g');
title('The Error for Checking Data');xlabel('Time');
figure;
plot(Y(1,:)-T);
title('The Error for Training Data');xlabel('Time');
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
sum=0;
for i= 1 :size(T,2)
sum=(abs(T(i)-Y(i))/abs(T(i)))+sum;
end
APE=sum/size(T,2);
sum=0;
for i= 1 :size(Tck,2)
sum=(abs(Tck(i)-Yck(i))/abs(Tck(i)))+sum;
end
APEck=sum/size(T,2);
Results
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
Project 7 ECE 7690 , Tejas Deshpande (gn0014)
Conclusion:
Table 12.2
The ANFIS model has less error training error and checking error because the number of training data
sets is larger than the GMDH model.
In this project the training error obtained is 0.0076 % and checking error is 0.2256 % , both these errors
are less because the number of checking data size is more which is 150.