-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNNmodel.m
More file actions
53 lines (47 loc) · 1.5 KB
/
NNmodel.m
File metadata and controls
53 lines (47 loc) · 1.5 KB
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
classdef NNmodel < handle
% Neural network object, contains whole network information
properties
LayerGraph
Connection
GradFcn
X % Predictor
Y % Response
YPred % Current predict result
grad_W % Current weight gradient of each layer
grad_b % Current bias gradient of each layer
end
methods
function self = NNmodel
end
% Evaluate network with predictor an d response
function y = eval(self, x, y)
if size(x,2)~= self.LayerGraph(1).neuronNum
error('Data size not match with input layer')
end
self.X = x';
self.Y = y;
initialGain = 1/sqrt(100);
input = self.X;
for i = 1:length(self.LayerGraph)
output = forward(self.LayerGraph(i),input);
% Batch normalization
%TODO
input = output;
end
y = output;
self.YPred = y(:);
end
% Back Propagation for Roy's GD
% Manual passing hidden state value between layer
function y = backward(self, x, layer)
X_temp = x;
if layer < length(self.LayerGraph)
for i = layer+1:length(self.LayerGraph)
output = forward(self.LayerGraph(i), X_temp, 'X_temp');
X_temp = output;
end
end
y = X_temp;
end
end
end