ImaGIN_trainBaseUpdate.m
2.09 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
50
51
52
53
54
55
56
57
58
59
function ImaGIN_trainBaseUpdate(badDir, trainBaseFile, trainedFile)
% -=============================================================================
% This function is part of the ImaGIN software:
% https://f-tract.eu/
%
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE AUTHORS
% DO NOT ASSUME ANY LIABILITY OR RESPONSIBILITY FOR ITS USE IN ANY CONTEXT.
%
% Copyright (c) 2000-2018 Inserm U1216
% =============================================================================-
%
% Authors: Viateur Tuyisenge & Olivier David
% Parse inputs
if (nargin < 3) || isempty(trainedFile)
trainedFile = '/gin/data/database/02-raw/ImaGIN_trainedClassifier.mat';
end
if (nargin < 2) || isempty(trainBaseFile)
trainBaseFile = '/gin/data/database/02-raw/ImaGIN_trainBaseFeatures.mat';
end
% Read existing train base
if ~isempty(trainBaseFile) && file_exist(trainBaseFile)
Tbase = load(trainBaseFile);
else
Tbase.predictors = [];
Tbase.response = {};
end
% Go to bad channel directory with csv files (features)
cd(badDir);
% List csv files
csvTables = dir('*.csv');
% Read the csv files and stack them to form the train base
for i = 1:length(csvTables)
csvName = csvTables(i).name;
csvPath = strcat(badDir, '/', csvName);
crTable = readtable(csvPath);
crTable.Properties.VariableNames = {'rankIdx', 'ch_xcorr', 'ch_var', 'ch_dev', 'ch_ampl', 'ch_grad', 'ch_kurt', 'ch_hurs', 'Note'};
Tbase.predictors = [Tbase.predictors; crTable(:, {'ch_xcorr', 'ch_var', 'ch_dev', 'ch_ampl', 'ch_grad', 'ch_kurt', 'ch_hurs'})];
Tbase.response = [Tbase.response; crTable.Note];
end
% Write train base to hard drive
save(trainBaseFile, '-struct', 'Tbase');
% Train classifier
try
[trainedClassifier, validationAccuracy] = ImaGIN_trainClassifier(Tbase.predictors, Tbase.response);
save(trainedFile, 'trainedClassifier');
catch
disp(['ERROR: ' lasterr]);
end