-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict_NN_RNN.m
90 lines (76 loc) · 2.11 KB
/
predict_NN_RNN.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
84
85
86
87
88
89
90
function [p] = predict_NN_RNN(theta1, theta2,theta3, X,X_TM1,config)
%
% Copyright (C) Hamid 2015
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation;
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m = size(X, 1);
num_labels = size(theta3, 1);
% initial the predictions
p = zeros(size(X, 1), 1);
% % first layer
% Add bias term
d1 =X;
d2=theta1*[ones(m, 1) d1]';
d2=sigmoid(d2);
d1_tm1 = X_TM1;
d2_tm1 = theta1 * [ones(m, 1) d1_tm1]';
d2_tm1 = sigmoid(d2_tm1);
% d1_tm2 = X_TM2;
% d2_tm2 = theta1 * [ones(m, 1) d1_tm2]';
% d2_tm2 = sigmoid(d2_tm2);
%
% d1_tm3 = X_TM3;
% d2_tm3 = theta1 * [ones(m, 1) d1_tm3]';
% d2_tm3 = sigmoid(d2_tm3);
% % % % % % % % % % % % % % % % % % % % %
d3_tm1 = theta2 * [ones(m, 1), d2_tm1']';
d3_tm1 = sigmoid(d3_tm1);
% d3_tm2 = theta2 * [ones(m, 1), d2_tm2']';
% d3_tm2 = sigmoid(d3_tm2);
%
% d3_tm3 = theta2 * [ones(m, 1), d2_tm3']';
% d3_tm3 = sigmoid(d3_tm3);
% % % % % % % % % % % % % % % % % % % % % %
% d4_tm2 = theta3 * [ones(m, 1), d3_tm2']';
% d4_tm2 = sigmoid(d4_tm2);
% d4_tm3 = theta3 * [ones(m, 1), d3_tm3']';
% d4_tm3 = sigmoid(d4_tm3);
% % % % % % % % % % % % % % % % % % % % % % %
% d5_tm3 = theta4 * [ones(m, 1), d4_tm3']';
% d5_tm3 = sigmoid(d5_tm3);
% Output layer
% Add bias term
d6=theta3*[ones(1,m) ;d2+d3_tm1];
d6=sigmoid(d6);
if strcmp(config.l,'class')
% pick the maximum
[~,ix]=max(d6);
p = ix;
elseif strcmp(config.l,'pred')
p=d6;
end
% loop version. commented
% for i=1:size(X,1)
% data = X(i,:);
%
% % Add bias term
% d1=theta1*[1 data]';
% d2=sigmoid(d1);
%
% % Add bias term
% d3=Theta2*[1 ;d2];
% d4=sigmoid(d3);
%
% % pick the maximum
% [~,ix]=max(d4);
% p(i) = ix;
% end
end