Skip to content

Commit

Permalink
More efficient Matlab wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
benfulcher committed Jun 21, 2022
1 parent 1e85536 commit 2e1a271
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 94 deletions.
6 changes: 3 additions & 3 deletions featureList.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
DN_HistogramMode_5
DN_HistogramMode_10
DN_Mean
DN_Spread_Std
CO_f1ecac
CO_FirstMin_ac
CO_HistogramAMI_even_2_5
Expand All @@ -21,4 +19,6 @@ SB_MotifThree_quantile_hh
SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1
SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1
SP_Summaries_welch_rect_centroid
FC_LocalSimple_mean3_stderr
FC_LocalSimple_mean3_stderr
DN_Mean
DN_Spread_Std
33 changes: 33 additions & 0 deletions wrap_Matlab/GetAllFeatureNames.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function featureNames = GetAllFeatureNames(doCatch24)
% Retrieve all feature names from featureList.txt

if nargin < 1 || isempty(doCatch24)
doCatch24 = true;
end
%-------------------------------------------------------------------------------

fid = fopen('../featureList.txt','r');
i = 1;
tline = fgetl(fid);
featureNames{i} = tline;
while ischar(tline)
i = i + 1;
tline = fgetl(fid);
if ischar(tline)
featureNames{i} = tline;
end
end
fclose(fid);

%-------------------------------------------------------------------------------
% Filter out the two extra features: 'DN_Mean' and 'DN_Spread_Std'
isMeanStd = strcmp(featureNames,'DN_Mean') | strcmp(featureNames,'DN_Spread_Std');
assert(sum(isMeanStd) == 2)
if ~doCatch24
featureNames = featureNames(~isMeanStd);
fprintf(1,'Using catch22\n');
else
fprintf(1,'Using catch24\n');
end

end
38 changes: 3 additions & 35 deletions wrap_Matlab/catch22_all.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,16 @@
%% Check inputs and set defaults
%-------------------------------------------------------------------------------
if nargin < 2
doCatch24 = false;
doCatch24 = true;
end

%-------------------------------------------------------------------------------
% Define the features:
%-------------------------------------------------------------------------------

% catch22:
featureNames = ...
{ ...
'DN_HistogramMode_5', ...
'DN_HistogramMode_10', ...
'CO_f1ecac', ...
'CO_FirstMin_ac', ...
'CO_HistogramAMI_even_2_5', ...
'CO_trev_1_num', ...
'MD_hrv_classic_pnn40', ...
'SB_BinaryStats_mean_longstretch1', ...
'SB_TransitionMatrix_3ac_sumdiagcov', ...
'PD_PeriodicityWang_th0_01', ...
'CO_Embed2_Dist_tau_d_expfit_meandiff', ...
'IN_AutoMutualInfoStats_40_gaussian_fmmi', ...
'FC_LocalSimple_mean1_tauresrat', ...
'DN_OutlierInclude_p_001_mdrmd', ...
'DN_OutlierInclude_n_001_mdrmd', ...
'SP_Summaries_welch_rect_area_5_1', ...
'SB_BinaryStats_diff_longstretch0', ...
'SB_MotifThree_quantile_hh', ...
'SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1', ...
'SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1', ...
'SP_Summaries_welch_rect_centroid', ...
'FC_LocalSimple_mean3_stderr'
};

% Add basic properties of the distribution (mean and standard deviation) as catch24 if desired:
if doCatch24
additionals = {'DN_Mean', 'DN_Spread_Std'};
featureNames = [featureNames, additionals];
end
featureNames = GetAllFeatureNames(doCatch24);

%-------------------------------------------------------------------------------
% Compute all features from their local catch22 (compiled) implementations
% Compute all features from their local compiled implementations
%-------------------------------------------------------------------------------
numFeatures = length(featureNames);
featureValues = zeros(numFeatures,1);
Expand Down
13 changes: 1 addition & 12 deletions wrap_Matlab/mexAll.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@
includeFiles = cellfun(@(x) fullfile(basePath, x), CFileNames, 'UniformOutput', false);

% Get function names
fid = fopen('../featureList.txt','r');
i = 1;
tline = fgetl(fid);
featureNames{i} = tline;
while ischar(tline)
i = i + 1;
tline = fgetl(fid);
if ischar(tline)
featureNames{i} = tline;
end
end
fclose(fid);
featureNames = GetAllFeatureNames(true);

% mex all feature functions separately
numFeatures = length(featureNames);
Expand Down
47 changes: 22 additions & 25 deletions wrap_Matlab/testing.m
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
% get function names
fid = fopen('../featureList.txt','r');
i = 1;
tline = fgetl(fid);
featureNames{i} = tline;
while ischar(tline)
i = i+1;
tline = fgetl(fid);
featureNames{i} = tline;
end
fclose(fid);
%-------------------------------------------------------------------------------
% Get the function names
featureNames = GetAllFeatureNames();
numFeatures = length(featureNames);

% get the data
%-------------------------------------------------------------------------------
% Get the data
dataFileNames = {'../testData/test.txt', '../testData/test2.txt'};
for j = 1:2

numTestFiles = length(dataFileNames);

fprintf(1,'Testing %u compiled features on %u data files\n',numFeatures,numTestFiles);

%-------------------------------------------------------------------------------
% Test all functions on all the data files
for j = 1:numTestFiles

dataFileName = dataFileNames{j};
fprintf('\n%s\n', dataFileName)
fprintf('\n%s\n\n', dataFileName)

fileID = fopen(dataFileName,'r');

data = fscanf(fileID,'%f');

for featureInd = 1:length(featureNames)-1

featureName = featureNames{featureInd};

fh = str2func(['catch22_', featureName]);
for featureInd = 1:numFeatures

featureName = featureNames{featureInd};
fh = str2func(['catch22_', featureName]);
out = fh(data');

fprintf("%s: %1.6f\n", featureName, out);
end

fclose(fileID);

end
19 changes: 0 additions & 19 deletions wrap_Matlab/testing_all.m

This file was deleted.

Binary file removed wrap_Python/.DS_Store
Binary file not shown.
Binary file removed wrap_Python/catch22/.DS_Store
Binary file not shown.

0 comments on commit 2e1a271

Please sign in to comment.