forked from jmarkow/nndetector-live
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nndetector_live_sim_network.m
57 lines (49 loc) · 1.38 KB
/
nndetector_live_sim_network.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
function [ACTIVATION,TRIGGER]=nndetector_live_sim_network(INPUT,NETWORK)
%
%
%
%
% first layer
% removed all anonymous functions, took a HUGE performance hit using them
if ~isempty(NETWORK.input_normalize)
switch NETWORK.input_normalize
case 'mapstd'
INPUT=mapstd.apply(INPUT,NETWORK.input_normalize_settings);
case 'mapminmax'
INPUT=mapminmax.apply(INPUT,NETWORK.input_normalize_settings);
end
end
tmp=NETWORK.layer_weights{1}*INPUT+NETWORK.layer_biases{1};
switch NETWORK.transfer_function{1}
case 'logsig'
ACTIVATION=logsig(tmp);
case 'tansig'
ACTIVATION=tansig(tmp);
case 'purelin'
ACTIVATION=purelin(tmp);
case 'satlin'
ACTIVATION=satlin(tmp);
end
% propagate through additional layers
for i=2:length(NETWORK.layer_weights)
tmp=NETWORK.layer_weights{i}*ACTIVATION+NETWORK.layer_biases{i};
switch NETWORK.transfer_function{1}
case 'logsig'
ACTIVATION=logsig(tmp);
case 'tansig'
ACTIVATION=tansig(tmp);
case 'purelin'
ACTIVATION=purelin(tmp);
case 'satlin'
ACTIVATION=satlin(tmp);
end
end
if ~isempty(NETWORK.output_normalize)
switch NETWORK.output_normalize
case 'mapstd'
ACTIVATION=mapstd.reverse(ACTIVATION,NETWORK.output_normalize_settings);
case 'mapminmax'
ACTIVATION=mapminmax.reverse(ACTIVATION,NETWORK.output_normalize_settings);
end
end
TRIGGER=ACTIVATION>=NETWORK.threshold;