forked from shababo/iit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogic_gates.m
81 lines (54 loc) · 1.7 KB
/
logic_gates.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
function output = logic_gates(input,logic_type,in_noise)
% LOGIC_GATES the probability an element will turn on given the inputs
%
% OUTPUT = logic_gates(INPUT, LOGIC_TYPE)
%
% Given a binary input vector, input, and the logic type, logic_type, of
% the element of interest, this function will return the probability that
% the element of interest will be on
% 0 to .5
global noise;
if nargin == 3
noise = in_noise;
end
% broken mechanism outputting 0 always
if logic_type == 0
output = 0;
% AND
elseif logic_type == 1
output = all(input);
% OR
elseif logic_type == 2
output = any(input);
% XOR
elseif logic_type == 3
output = sum(input) == 1;
% COPY
elseif logic_type == 4
output = input(1);
% NOT - TODO: check that element only has one input
elseif logic_type == 5
output = ~input(1);
% NULL
elseif logic_type == 6
output = .5;
return;
% MAJORITY
elseif logic_type == 7 %Larissa: Majority should be more than half? 2 out of 4 is not majority, but is minority??
N = length(input);
output = (sum(input)/N > .5);
% MINORITY
elseif logic_type == 8
N = length(input);
output = (sum(input)/N < .5);
%PARITY
elseif logic_type == 9
output = mod(sum(input),2) == 1;
%Linear Threshold unit, threshold is logic_type -10. I.e. '12' means threshold '2'
elseif logic_type >= 10 && logic_type < 20
output = sum(input) >= logic_type-10;
%below Threshold unit, threshold is logic_type -20. I.e. '22' means under threshold '2'
elseif logic_type >= 20
output = sum(input) < logic_type-20;
end
output = abs(output - noise);