Skip to content

Commit 2e1a271

Browse files
committed
More efficient Matlab wrapping
1 parent 1e85536 commit 2e1a271

File tree

8 files changed

+62
-94
lines changed

8 files changed

+62
-94
lines changed

featureList.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
DN_HistogramMode_5
22
DN_HistogramMode_10
3-
DN_Mean
4-
DN_Spread_Std
53
CO_f1ecac
64
CO_FirstMin_ac
75
CO_HistogramAMI_even_2_5
@@ -21,4 +19,6 @@ SB_MotifThree_quantile_hh
2119
SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1
2220
SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1
2321
SP_Summaries_welch_rect_centroid
24-
FC_LocalSimple_mean3_stderr
22+
FC_LocalSimple_mean3_stderr
23+
DN_Mean
24+
DN_Spread_Std

wrap_Matlab/GetAllFeatureNames.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function featureNames = GetAllFeatureNames(doCatch24)
2+
% Retrieve all feature names from featureList.txt
3+
4+
if nargin < 1 || isempty(doCatch24)
5+
doCatch24 = true;
6+
end
7+
%-------------------------------------------------------------------------------
8+
9+
fid = fopen('../featureList.txt','r');
10+
i = 1;
11+
tline = fgetl(fid);
12+
featureNames{i} = tline;
13+
while ischar(tline)
14+
i = i + 1;
15+
tline = fgetl(fid);
16+
if ischar(tline)
17+
featureNames{i} = tline;
18+
end
19+
end
20+
fclose(fid);
21+
22+
%-------------------------------------------------------------------------------
23+
% Filter out the two extra features: 'DN_Mean' and 'DN_Spread_Std'
24+
isMeanStd = strcmp(featureNames,'DN_Mean') | strcmp(featureNames,'DN_Spread_Std');
25+
assert(sum(isMeanStd) == 2)
26+
if ~doCatch24
27+
featureNames = featureNames(~isMeanStd);
28+
fprintf(1,'Using catch22\n');
29+
else
30+
fprintf(1,'Using catch24\n');
31+
end
32+
33+
end

wrap_Matlab/catch22_all.m

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,16 @@
1212
%% Check inputs and set defaults
1313
%-------------------------------------------------------------------------------
1414
if nargin < 2
15-
doCatch24 = false;
15+
doCatch24 = true;
1616
end
1717

1818
%-------------------------------------------------------------------------------
1919
% Define the features:
2020
%-------------------------------------------------------------------------------
21-
22-
% catch22:
23-
featureNames = ...
24-
{ ...
25-
'DN_HistogramMode_5', ...
26-
'DN_HistogramMode_10', ...
27-
'CO_f1ecac', ...
28-
'CO_FirstMin_ac', ...
29-
'CO_HistogramAMI_even_2_5', ...
30-
'CO_trev_1_num', ...
31-
'MD_hrv_classic_pnn40', ...
32-
'SB_BinaryStats_mean_longstretch1', ...
33-
'SB_TransitionMatrix_3ac_sumdiagcov', ...
34-
'PD_PeriodicityWang_th0_01', ...
35-
'CO_Embed2_Dist_tau_d_expfit_meandiff', ...
36-
'IN_AutoMutualInfoStats_40_gaussian_fmmi', ...
37-
'FC_LocalSimple_mean1_tauresrat', ...
38-
'DN_OutlierInclude_p_001_mdrmd', ...
39-
'DN_OutlierInclude_n_001_mdrmd', ...
40-
'SP_Summaries_welch_rect_area_5_1', ...
41-
'SB_BinaryStats_diff_longstretch0', ...
42-
'SB_MotifThree_quantile_hh', ...
43-
'SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1', ...
44-
'SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1', ...
45-
'SP_Summaries_welch_rect_centroid', ...
46-
'FC_LocalSimple_mean3_stderr'
47-
};
48-
49-
% Add basic properties of the distribution (mean and standard deviation) as catch24 if desired:
50-
if doCatch24
51-
additionals = {'DN_Mean', 'DN_Spread_Std'};
52-
featureNames = [featureNames, additionals];
53-
end
21+
featureNames = GetAllFeatureNames(doCatch24);
5422

5523
%-------------------------------------------------------------------------------
56-
% Compute all features from their local catch22 (compiled) implementations
24+
% Compute all features from their local compiled implementations
5725
%-------------------------------------------------------------------------------
5826
numFeatures = length(featureNames);
5927
featureValues = zeros(numFeatures,1);

wrap_Matlab/mexAll.m

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,7 @@
1313
includeFiles = cellfun(@(x) fullfile(basePath, x), CFileNames, 'UniformOutput', false);
1414

1515
% Get function names
16-
fid = fopen('../featureList.txt','r');
17-
i = 1;
18-
tline = fgetl(fid);
19-
featureNames{i} = tline;
20-
while ischar(tline)
21-
i = i + 1;
22-
tline = fgetl(fid);
23-
if ischar(tline)
24-
featureNames{i} = tline;
25-
end
26-
end
27-
fclose(fid);
16+
featureNames = GetAllFeatureNames(true);
2817

2918
% mex all feature functions separately
3019
numFeatures = length(featureNames);

wrap_Matlab/testing.m

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
% get function names
2-
fid = fopen('../featureList.txt','r');
3-
i = 1;
4-
tline = fgetl(fid);
5-
featureNames{i} = tline;
6-
while ischar(tline)
7-
i = i+1;
8-
tline = fgetl(fid);
9-
featureNames{i} = tline;
10-
end
11-
fclose(fid);
1+
%-------------------------------------------------------------------------------
2+
% Get the function names
3+
featureNames = GetAllFeatureNames();
4+
numFeatures = length(featureNames);
125

13-
% get the data
6+
%-------------------------------------------------------------------------------
7+
% Get the data
148
dataFileNames = {'../testData/test.txt', '../testData/test2.txt'};
15-
for j = 1:2
16-
9+
numTestFiles = length(dataFileNames);
10+
11+
fprintf(1,'Testing %u compiled features on %u data files\n',numFeatures,numTestFiles);
12+
13+
%-------------------------------------------------------------------------------
14+
% Test all functions on all the data files
15+
for j = 1:numTestFiles
16+
1717
dataFileName = dataFileNames{j};
18-
fprintf('\n%s\n', dataFileName)
19-
18+
fprintf('\n%s\n\n', dataFileName)
19+
2020
fileID = fopen(dataFileName,'r');
21-
2221
data = fscanf(fileID,'%f');
23-
24-
for featureInd = 1:length(featureNames)-1
25-
26-
featureName = featureNames{featureInd};
2722

28-
fh = str2func(['catch22_', featureName]);
23+
for featureInd = 1:numFeatures
2924

25+
featureName = featureNames{featureInd};
26+
fh = str2func(['catch22_', featureName]);
3027
out = fh(data');
31-
28+
3229
fprintf("%s: %1.6f\n", featureName, out);
3330
end
34-
31+
3532
fclose(fileID);
36-
33+
3734
end

wrap_Matlab/testing_all.m

Lines changed: 0 additions & 19 deletions
This file was deleted.

wrap_Python/.DS_Store

-6 KB
Binary file not shown.

wrap_Python/catch22/.DS_Store

-6 KB
Binary file not shown.

0 commit comments

Comments
 (0)