-
Notifications
You must be signed in to change notification settings - Fork 2
/
CNN.m
51 lines (48 loc) · 1.4 KB
/
CNN.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
classdef CNN < handle
properties
layers = [];
end
methods
function addLayer(CNN, type, numberOfFilters, filterDimension, activationFunction, prevDimension, fanIn, fanOut)
CNN.layers = [CNN.layers; [type, numberOfFilters, filterDimension, activationFunction, prevDimension, fanIn, fanOut] ];
end
function constructLayers(CNN)
% CNN.layers = Layers(CNN.layers)
CNN.layers = Layer(CNN.layers);
end
function output = forwardPropagation(CNN, input)
prev_output = input;
size_cnn_layers = size(CNN.layers) - 1;
for i = 1:size_cnn_layers(2)
prev_output = CNN.layers(i).layerFunction(prev_output);
size(prev_output);
end
output = prev_output;
% disp(output)
end
function backwardPropagation(CNN, actualY, input)
for i = flip(1:size(CNN.layers, 2)-1)
k = i+1;
if(i==size(CNN.layers, 2)-1)
k = i;
end
%Check prev output
if(i==1)
prevOutput = input;
else
prevOutput = CNN.layers(i-1).layerOutput;
end
CNN.layers(i).calculateError(CNN.layers(k), actualY, prevOutput);
end
end
function print(CNN)
disp("CNN")
for i = 1:size(CNN.layers)
disp("Layer filters: ")
disp(CNN.layers(i).filters)
disp("Layer Output: ")
disp(CNN.layers(i).layerOutput)
end
end
end
end