forked from Alexflex/HNNC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlpMatlabTest.m
133 lines (117 loc) · 3.97 KB
/
mlpMatlabTest.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function mlpMatlabTest(ds, path, varargin)
% Ôóíêöèÿ ñîçäàåò ÌÑÏ âñòðîåííûìè ñðåäñòâàìè Matlab è îñóùåñòâëÿåò
% òåñòèðîâàíèå íà èìåþùåìñÿ íàáîðå äàííûõ
%
% mlpMatlabTest(ds, varargin)
%
% Arguments
% ds - ìíîæåñòâî ïðèìåðîâ
% path - ïóòü äëÿ ñîõðàíåíèÿ ëîãà îáó÷åíèÿ
% varargin - ïàðàìåòðû ðàçìåðíîñòåé ñåòè
%
% Example
% mlpMatlabTest(ds, ds.numInputs, 8, 10);
%
% See also
%
% Revisions
% Author: Vulfin Alex, Date: 25/11/2010
% Supervisor: Vulfin Alex, Date: 25/11/2010
% Author: (Next revision author), Date: (Next revision date)
% ãëîáàëüíûé ïîòîê âûâîäà, ñâÿçàííûé ëèáî ñ ýêðàíîì, ëèáî ñ ôàéëîì
% global flogid;
% ñîçäàíèå îáó÷àþùåãî ìíîæåñòâà äëÿ netff èç èñõîäíîãî
p = ds.training.inputs;
t = ds.training.outputs;
trainInd = 1:ds.training.count;
if(ds.hasTest)
p = [p; ds.test.inputs];
t = [t; ds.test.outputs];
testInd = ds.training.count + 1:ds.training.count + ds.test.count;
end
if(ds.hasValidation)
p = [p; ds.validation.inputs];
t = [t; ds.validation.outputs];
valInd = ds.training.count + ds.test.count + 1:...
ds.training.count + ds.test.count + ds.validation.count;
end
% ñîçäàíèå ÌÑÏ çàäàííîé àðõèòåêòóðû
% netm = newff(p', t', [varargin{:}], {}, 'traingdm');
netm = newff(p', t', [varargin{:}], {}, 'trainrp');
% çàäàíèå ïàðàìåòðîâ îáó÷åíèÿ - ïîêàçûâàòü ëîã îáó÷åíèÿ êàæäûå N ýïîõ
netm.trainParam.show = 25;
netm.trainParam.showCommandLine = false;
netm.trainParam.goal = 1e-5;
netm.trainParam.epochs = 1000;
netm.trainParam.max_fail = 10;
% íå ïîêàçûâàòü âèçóàëüíûé ìàñòåð
netm.trainParam.showWindow = 0;
% ðàçäåëåíèå ïðèìåðîâ íà îáó÷àþùåå, ïðîâåðî÷íîå è òåñòîâîå ìíîæåñòâà
netm.divideFcn = 'divideind';
netm.divideParam.trainInd = trainInd;
if(ds.hasValidation)
netm.divideParam.valInd = valInd;
end
if(ds.hasTest)
netm.divideParam.testInd = testInd;
end
% îáó÷åíèå ñåòè
[netm, tr] = train(netm, p', t');
% ïîñòðîåíèå ãðàôèêà îáó÷åíèÿ
plotperform(tr);
h = gcf;
p = [ds.training.inputs];
t = [ds.training.outputs];
ytst = sim(netm, p');
etst = t' - ytst;
MSEtst = mse(etst);
mclasses = classesFromOutputs(ytst');
classErrorSet = sum(mclasses ~= ds.training.classes);
classError = classErrorSet/ds.training.count;
correct = 100*(1 - classError);
numErrors = classError*ds.training.count;
printMessage('\n\tÐåçóëüòàòû òåñòèðîâàíèÿ MATLAB ÌÑÏ íà îáó÷àþùåì ìíîæåñòâå');
printMessage('\n\t\tregressError = %g', MSEtst);
printMessage('\n\t\tclassError = %g', classError);
printMessage('\n\t\tnumErrors = %d', numErrors);
printMessage('\n\t\tcorrect = %5.2f%', correct);
% Obtaining the test MSE
if(ds.hasTest)
p = [ds.test.inputs];
t = [ds.test.outputs];
ytst = sim(netm, p');
etst = t' - ytst;
MSEtst = mse(etst);
mclasses = classesFromOutputs(ytst');
classErrorSet = sum(mclasses ~= ds.test.classes);
classError = classErrorSet/ds.test.count;
correct = 100*(1 - classError);
numErrors = classError*ds.test.count;
printMessage('\n\tÐåçóëüòàòû òåñòèðîâàíèÿ MATLAB ÌÑÏ íà òåñòîâîì ìíîæåñòâå');
printMessage('\n\t\tregressError = %g', MSEtst);
printMessage('\n\t\tclassError = %g', classError);
printMessage('\n\t\tnumErrors = %d', numErrors);
printMessage('\n\t\tcorrect = %5.2f%', correct);
end
% Obtaining the validation MSE
if(ds.hasValidation)
p = [ds.validation.inputs];
t = [ds.validation.outputs];
ytst = sim(netm, p');
etst = t' - ytst;
MSEtst = mse(etst);
mclasses = classesFromOutputs(ytst');
classErrorSet = sum(mclasses ~= ds.validation.classes);
classError = classErrorSet/ds.validation.count;
correct = 100*(1 - classError);
numErrors = classError*ds.validation.count;
printMessage('\n\tÐåçóëüòàòû òåñòèðîâàíèÿ MATLAB ÌÑÏ íà ïðîâåðî÷íîì ìíîæåñòâå');
printMessage('\n\t\tregressError = %g', MSEtst);
printMessage('\n\t\tclassError = %g', classError);
printMessage('\n\t\tnumErrors = %d', numErrors);
printMessage('\n\t\tcorrect = %5.2f%', correct);
end
saveas(h, char(path), 'png');
pause(1);
close(h);
end %of function