-
Notifications
You must be signed in to change notification settings - Fork 0
/
ee4414_regression.m
83 lines (62 loc) · 1.47 KB
/
ee4414_regression.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
clear
clc
numFeatures = 3;
numNeurons = [700 500];
%numNeurons = 30;
% prepare dataset
switch numFeatures
case 1
x = 0:2*pi/99:2*pi;
tempt = sin(x);
t = awgn(tempt,20);
case 2
x = 0:2*pi/99:2*pi;
x2 = 2*x;
tempt = sin(x) + cos(x2);
x = [x;x2];
t = awgn(tempt,20); % add noise with snr=20
case 3
x = 0:2*pi/99:2*pi;
x2 = 2*x;
x3 = 3*x;
tempt = sin(x) + cos(x2) + tan(x3);
x = [x;x2;x3];
t = awgn(tempt,20);
otherwise
x = 0:2*pi/99:2*pi;
tempt = sin(x);
end
%[x,t] = abalone_dataset;
% init the network
net = fitnet(numNeurons);
% modify the parameters (your code here)
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'radbas';
net.trainFcn='traincgb';
net.trainParam.lr = 0.001;
% train the network
net = train(net,x,t);
% retrive the prediction
y = net(x);
% plot the truth and prediction
if strcmp(net.name,'Function Fitting Neural Network')
plot(t)
hold on
plot(y)
% hold on
% plot(tempt)
% legend('truth','prediction','truth without noise');
legend('truth','prediction');
elseif strcmp(net.name,'Pattern Recognition Neural Network')
[T,tI] = max(t);
[Y,yI] = max(y);
[~,sI] = sort(tI);
sI=sI(1:10);
subplot(1,2,1)
plot(tI(sI),'go')
title('truth')
subplot(1,2,2)
plot(yI(sI),'ro')
title('prediction')
else
end