-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_noise_input.m~
58 lines (54 loc) · 1.62 KB
/
add_noise_input.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
function[error_percentage] = add_noise_input()
p = [0,1,1,1,0,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,0,1,1,1,0; %0
0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0; %1
1,1,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,1,1,1,1]; %2
t = [1,0,0; %0
0,1,0; %1
0,0,1]; %2
%variables to count the wrong outputs
input_size = size(p,1);
[W,b] = backprop(p, t, 1, 20, 0.1, 350);
a = zeros(length(W),1);
for h = 1:length(t)
for i = 0:4:8
for j = 1:10
for k = 1:length(W)
if (k == 1)
a(:,k) = W{k}*addNoise(p(h,:)',i)+b{k};
else
a(:,k) = W{k}*addNoise(a(:,k-1),i)+b{k};
end
end
if (a(:,-
end
end
end
outputs = cell(input_size, 1);
match_counter = 0;
tries = 0;
%for loop to go through all the layers of neurons
for trial = 1:10
%add the pixel to the desired input and change it with the pixel
for inp = 1:input_size
new_noisy = addNoise(p(inp,:), pix);
%calculate the output from using the changed input
for j = 1:total_layers
if (j == 1)
a{j} = (W{1} * new_noisy.' + b{1});
elseif (j == total_layers)
a{j} = (W{2} * a{j-1} + b{2});
else
a{j} = (W{1} * a{j-1} + b{1});
end
end
outputs{inp} = a{total_layers};
if (outputs{inp} == t(inp,:).')
match_counter = match_counter + 1;
end
tries = tries + 1;
end
end
disp(tries)
disp(match_counter)
error_percentage = ((tries - match_counter) / tries) / 100;
end