-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_models.m
More file actions
63 lines (46 loc) · 1.48 KB
/
run_models.m
File metadata and controls
63 lines (46 loc) · 1.48 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
60
61
62
63
function [signal,label]=run_models(data_record, digitalization_model, classification_model, verbose)
digitalization_model=digitalization_model.digitalization_model;
classes=classification_model.classes;
classification_model=classification_model.classification_model;
header=fileread(data_record);
% Digitalization model
image_file=get_image_file(header);
[folder,~,~]=fileparts(data_record);
features=get_features(folder,image_file,header);
num_samples = get_num_samples(header);
num_signals = get_num_signals(header);
rng(digitalization_model+mean2(features));
signal=2000*rand(num_samples,num_signals)-1000;
% Classification model
probabilities=mnrval(classification_model,features);
if sum(probabilities>0.3)>0
label=classes(probabilities>0.3);
if length(label)>1
label=strjoin(label,', ');
else
label=label{1};
end
else
[~,idx]=max(probabilities);
label=classes(idx);
label=label{1};
end
end
function image_file=get_image_file(header)
header=strsplit(header,'\n');
image_file=header(startsWith(header,'# Image'));
image_file=strsplit(image_file{1},':');
image_file=strtrim(image_file{2});
end
function num_samples = get_num_samples(header)
header=strsplit(header,'\n');
header_tmp=header{1};
header_tmp=strsplit(header_tmp,' ');
num_samples=str2double(header_tmp{4});
end
function num_signals = get_num_signals(header)
header=strsplit(header,'\n');
header_tmp=header{1};
header_tmp=strsplit(header_tmp,' ');
num_signals=str2double(header_tmp{2});
end