-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplyNeuralNetwork.m
More file actions
49 lines (49 loc) · 2.14 KB
/
ApplyNeuralNetwork.m
File metadata and controls
49 lines (49 loc) · 2.14 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
function NetworkOutput = ApplyNeuralNetwork(Network,X,e)
K = length(X(:,1));
Weights = Network.weights;
Topology = Network.Topology;
bias = Network.bias;
N_Layers = Network.N_Layers;
Nodes = zeros(K,sum(Topology(2:end)));
Connections = zeros(K,length(Nodes));
Prediction = zeros(K,Topology(end));
k=1;
c_counter = 0;
Nodes(1,1:Topology(1)) = X(1:Topology(1));
for i=2:N_Layers
if i==2
n_counter = sum(Topology(1:i-1));
for j=1:Topology(2)
Temp = 0;
for ell=1:Topology(1)
c_counter = c_counter + 1;
temp = X(k,ell)*Weights(c_counter);
Temp = Temp + temp;
end
Temp = Temp+bias(c_counter)*1;
n_counter = n_counter + 1;
Connections(n_counter) = Temp;
Nodes(k,n_counter) = 1 / ( 1 + exp(-Temp) );
end
n0 = 0;
else
n_counter = sum(Topology(1:i-1));
for j=1:Topology(i)
Temp = 0;
for ell=1:Topology(i-1)
c_counter = c_counter + 1;
temp = Nodes(k,n0+ell)*Weights(c_counter);
Temp = Temp + temp;
end
n_counter = n_counter+1;
Temp = Temp +bias(c_counter)*1;
Connections(n_counter) = Temp;
Nodes(k,n_counter) = 1 / ( 1 + exp(-Temp) );
end
n0 = n0 + Topology(i-1);
end
end
Prediction(k,:) = Nodes(k,end);
NetworkOutput.Connections = Connections;
NetworkOutput.Nodes = Nodes;
NetworkOutput.Prediction = Prediction;