-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompute_network.m
More file actions
executable file
·43 lines (31 loc) · 1.01 KB
/
compute_network.m
File metadata and controls
executable file
·43 lines (31 loc) · 1.01 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
%ritorna la rete di riconoscimento migliore
function best_net = compute_network(trX, trT, tstX, tstT)
trainFcn = 'trainscg';
%Scaled conjugate gradient backpropagation
%trainscg is a network training function that updates weight and bias
%values according to the scaled conjugate gradient method.
hiddenLayerSize = 25;
net = patternnet(hiddenLayerSize);
perc_error = 1;
%alleno e testo 10 volte
%train 85%
%validazione 15%
for i=1:10
net.divideParam.trainRatio = 85/100;
net.divideparam.valRatio = 15/100;
net.divideParam.testRatio = 0/100;
[net, tr] = train(net, trX', trT');
y = net(tstX');
tind = vec2ind(tstT');
yind = vec2ind(y);
percentError = sum(tind ~=yind)/numel(tind);
if(percentError <perc_error)
best_net = net;
perc_error = percentError;
end
end
y = best_net(tstX');
%plotconfusion(targets,outputs) returns a confusion matrix plot
%for the target and output data in targets and outputs, respectively.
plotconfusion(tstT', y)
end