├── .github └── workflows │ └── github-repo-stats.yml ├── .gitignore ├── C ├── .gitignore ├── CO_AutoCorr.c ├── CO_AutoCorr.h ├── DN_HistogramMode_10.c ├── DN_HistogramMode_10.h ├── DN_HistogramMode_5.c ├── DN_HistogramMode_5.h ├── DN_Mean.c ├── DN_Mean.h ├── DN_OutlierInclude.c ├── DN_OutlierInclude.h ├── DN_Spread_Std.c ├── DN_Spread_Std.h ├── FC_LocalSimple.c ├── FC_LocalSimple.h ├── IN_AutoMutualInfoStats.c ├── IN_AutoMutualInfoStats.h ├── MD_hrv.c ├── MD_hrv.h ├── PD_PeriodicityWang.c ├── PD_PeriodicityWang.h ├── SB_BinaryStats.c ├── SB_BinaryStats.h ├── SB_CoarseGrain.c ├── SB_CoarseGrain.h ├── SB_MotifThree.c ├── SB_MotifThree.h ├── SB_TransitionMatrix.c ├── SB_TransitionMatrix.h ├── SC_FluctAnal.c ├── SC_FluctAnal.h ├── SP_Summaries.c ├── SP_Summaries.h ├── butterworth.c ├── butterworth.h ├── fft.c ├── fft.h ├── helper_functions.c ├── helper_functions.h ├── histcounts.c ├── histcounts.h ├── main.c ├── main.h ├── runAllTS.sh ├── splinefit.c ├── splinefit.h ├── stats.c └── stats.h ├── LICENSE ├── Matlab ├── BasisOperations │ ├── BF_Binarize.m │ ├── CO_AutoCorr.m │ ├── CO_FirstZero.m │ ├── CO_trev.m │ ├── DN_HistogramMode.m │ ├── DN_OutlierInclude_001_mdrmd.m │ ├── NK_hist2.m │ ├── SB_CoarseGrain_quantile.m │ ├── SB_TransitionMatrix.m │ ├── SC_FluctAnal_q2_taustep50_k1_logi_prop_r1.m │ ├── SP_Summaries_welch_rect.m │ ├── buffer_.m │ ├── decimate_.m │ ├── downsample_.m │ ├── filtfilt_.m │ ├── histcounts_.m │ ├── myButter.m │ ├── poly_.m │ ├── splinefit.m │ ├── test_zp2ss.m │ ├── testfilt.m │ └── welchy.m ├── CO_Embed2_Dist_tau_d_expfit_meandiff.m ├── CO_FirstMin_ac.m ├── CO_HistogramAMI_even_2_5.m ├── CO_f1ecac.m ├── CO_trev_1_num.m ├── DN_HistogramMode_10.m ├── DN_HistogramMode_5.m ├── DN_Mean.m ├── DN_OutlierInclude_n_001_mdrmd.m ├── DN_OutlierInclude_p_001_mdrmd.m ├── DN_Spread_Std.m ├── FC_LocalSimple_mean1_tauresrat.m ├── FC_LocalSimple_mean3_stderr.m ├── IN_AutoMutualInfoStats_40_gaussian_fmmi.m ├── MD_hrv_classic_pnn40.m ├── PD_PeriodicityWang_th0_01.m ├── SB_BinaryStats_diff_longstretch0.m ├── SB_BinaryStats_mean_longstretch1.m ├── SB_MotifThree_quantile_hh.m ├── SB_TransitionMatrix_3ac_sumdiagcov.m ├── SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1.m ├── SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1.m ├── SP_Summaries_welch_rect_area_5_1.m └── SP_Summaries_welch_rect_centroid.m ├── README.md ├── catch22.m ├── featureList.txt ├── img ├── PerformanceComparisonFig4.png └── catch22_logo_square.png ├── testData ├── runtests.sh ├── test.txt ├── test2.txt ├── test2_output.txt ├── testInf.txt ├── testInfMinus.txt ├── testNaN.txt ├── testShort.txt ├── testShort_output.txt ├── testSinusoid.txt ├── testSinusoid_output.txt └── test_output.txt └── wrap_Matlab ├── GetAllFeatureNames.m ├── M_wrapper.c ├── M_wrapper.h ├── catch22_CO_Embed2_Dist_tau_d_expfit_meandiff.c ├── catch22_CO_FirstMin_ac.c ├── catch22_CO_HistogramAMI_even_2_5.c ├── catch22_CO_f1ecac.c ├── catch22_CO_trev_1_num.c ├── catch22_DN_HistogramMode_10.c ├── catch22_DN_HistogramMode_5.c ├── catch22_DN_Mean.c ├── catch22_DN_OutlierInclude_n_001_mdrmd.c ├── catch22_DN_OutlierInclude_p_001_mdrmd.c ├── catch22_DN_Spread_Std.c ├── catch22_FC_LocalSimple_mean1_tauresrat.c ├── catch22_FC_LocalSimple_mean3_stderr.c ├── catch22_IN_AutoMutualInfoStats_40_gaussian_fmmi.c ├── catch22_MD_hrv_classic_pnn40.c ├── catch22_PD_PeriodicityWang_th0_01.c ├── catch22_SB_BinaryStats_diff_longstretch0.c ├── catch22_SB_BinaryStats_mean_longstretch1.c ├── catch22_SB_MotifThree_quantile_hh.c ├── catch22_SB_TransitionMatrix_3ac_sumdiagcov.c ├── catch22_SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1.c ├── catch22_SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1.c ├── catch22_SP_Summaries_welch_rect_area_5_1.c ├── catch22_SP_Summaries_welch_rect_centroid.c ├── catch22_all.m ├── mexAll.m └── testing.m /.github/workflows/github-repo-stats.yml: -------------------------------------------------------------------------------- 1 | name: github-repo-stats 2 | 3 | on: 4 | schedule: 5 | # Run this once per day, towards the end of the day for keeping the most 6 | # recent data point most meaningful (hours are interpreted in UTC). 7 | - cron: "0 23 * * *" 8 | workflow_dispatch: # Allow for running this manually. 9 | 10 | jobs: 11 | j1: 12 | name: github-repo-stats 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: run-ghrs 16 | # Use latest release. 17 | uses: jgehrcke/github-repo-stats@RELEASE 18 | with: 19 | ghtoken: ${{ secrets.ghrs_github_api_token }} 20 | 21 | 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.prj 2 | *.mexmaci64 3 | *.mexmaca64 4 | *.mat 5 | *.m~ 6 | .DS_Store 7 | *.vscode 8 | *.code-workspace 9 | */run_features 10 | -------------------------------------------------------------------------------- /C/.gitignore: -------------------------------------------------------------------------------- 1 | codegen 2 | *.prj 3 | *.mexmaci64 4 | *.o 5 | C_polished 6 | generated 7 | header 8 | timeSeries* 9 | featureOutputs -------------------------------------------------------------------------------- /C/CO_AutoCorr.h: -------------------------------------------------------------------------------- 1 | #ifndef CO_AUTOCORR_H 2 | #define CO_AUTOCORR_H 3 | 4 | #if __cplusplus 5 | # include 6 | typedef std::complex< double > cplx; 7 | #else 8 | # include 9 | #if defined(__GNUC__) || defined(__GNUG__) 10 | typedef double complex cplx; 11 | #elif defined(_MSC_VER) 12 | typedef _Dcomplex cplx; 13 | #endif 14 | #endif 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "stats.h" 21 | #include "fft.h" 22 | 23 | extern int nextpow2(int n); 24 | extern void dot_multiply(cplx a[], cplx b[], int size); 25 | extern double * CO_AutoCorr(const double y[], const int size, const int tau[], const int tau_size); 26 | extern double * co_autocorrs(const double y[], const int size); 27 | extern int co_firstzero(const double y[], const int size, const int maxtau); 28 | extern double CO_Embed2_Basic_tau_incircle(const double y[], const int size, const double radius, const int tau); 29 | extern double CO_Embed2_Dist_tau_d_expfit_meandiff(const double y[], const int size); 30 | extern int CO_FirstMin_ac(const double y[], const int size); 31 | extern double CO_trev_1_num(const double y[], const int size); 32 | extern double CO_f1ecac(const double y[], const int size); 33 | extern double CO_HistogramAMI_even_2_5(const double y[], const int size); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /C/DN_HistogramMode_10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "stats.h" 7 | #include "histcounts.h" 8 | 9 | double DN_HistogramMode_10(const double y[], const int size) 10 | { 11 | // NaN check 12 | for(int i = 0; i < size; i++) 13 | { 14 | if(isnan(y[i])) 15 | { 16 | return NAN; 17 | } 18 | } 19 | 20 | const int nBins = 10; 21 | 22 | int * histCounts; 23 | double * binEdges; 24 | 25 | histcounts(y, size, nBins, &histCounts, &binEdges); 26 | 27 | double maxCount = 0; 28 | int numMaxs = 1; 29 | double out = 0;; 30 | for(int i = 0; i < nBins; i++) 31 | { 32 | // printf("binInd=%i, binCount=%i, binEdge=%1.3f \n", i, histCounts[i], binEdges[i]); 33 | 34 | if (histCounts[i] > maxCount) 35 | { 36 | maxCount = histCounts[i]; 37 | numMaxs = 1; 38 | out = (binEdges[i] + binEdges[i+1])*0.5; 39 | } 40 | else if (histCounts[i] == maxCount){ 41 | 42 | numMaxs += 1; 43 | out += (binEdges[i] + binEdges[i+1])*0.5; 44 | } 45 | } 46 | out = out/numMaxs; 47 | 48 | // arrays created dynamically in function histcounts 49 | free(histCounts); 50 | free(binEdges); 51 | 52 | return out; 53 | } 54 | 55 | /* 56 | double DN_HistogramMode_10(double y[], int size) 57 | { 58 | 59 | double min = DBL_MAX, max=-DBL_MAX; 60 | for(int i = 0; i < size; i++) 61 | { 62 | if (y[i] < min) 63 | { 64 | min = y[i]; 65 | } 66 | if (y[i] > max) 67 | { 68 | max = y[i]; 69 | } 70 | } 71 | 72 | double binStep = (max - min)/10; 73 | 74 | // fprintf(stdout, "min=%f, max=%f, binStep=%f \n", min, max, binStep); 75 | 76 | int histCounts[10] = {0}; 77 | for(int i = 0; i < size; i++) 78 | { 79 | int binsLeft = 10; 80 | int lowerInd = 0, upperInd = 10; 81 | while(binsLeft > 1) 82 | { 83 | int limitInd = (upperInd - lowerInd)/2 + lowerInd; 84 | double limit = limitInd * binStep + min; 85 | 86 | if (y[i] < limit) 87 | { 88 | upperInd = limitInd; 89 | } 90 | else 91 | { 92 | lowerInd = limitInd; 93 | } 94 | binsLeft = upperInd - lowerInd; 95 | } 96 | histCounts[lowerInd] += 1; 97 | } 98 | 99 | double maxCount = 0; 100 | int maxCountInd = 0; 101 | for(int i = 0; i < 10; i++) 102 | { 103 | // fprintf(stdout, "binInd=%i, binCount=%i \n", i, histCounts[i]); 104 | 105 | if (histCounts[i] > maxCount) 106 | { 107 | maxCountInd = i; 108 | maxCount = histCounts[i]; 109 | } 110 | } 111 | return binStep*(maxCountInd+0.5) + min; 112 | } 113 | */ 114 | -------------------------------------------------------------------------------- /C/DN_HistogramMode_10.h: -------------------------------------------------------------------------------- 1 | #ifndef DN_HISTOGRAMMODE_10 2 | #define DN_HISTOGRAMMODE_10 3 | #include 4 | #include 5 | #include "stats.h" 6 | 7 | extern double DN_HistogramMode_10(const double y[], const int size); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /C/DN_HistogramMode_5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "stats.h" 6 | #include "histcounts.h" 7 | 8 | double DN_HistogramMode_5(const double y[], const int size) 9 | { 10 | 11 | // NaN check 12 | for(int i = 0; i < size; i++) 13 | { 14 | if(isnan(y[i])) 15 | { 16 | return NAN; 17 | } 18 | } 19 | 20 | const int nBins = 5; 21 | 22 | int * histCounts; 23 | double * binEdges; 24 | 25 | histcounts(y, size, nBins, &histCounts, &binEdges); 26 | 27 | /* 28 | for(int i = 0; i < nBins; i++){ 29 | printf("histCounts[%i] = %i\n", i, histCounts[i]); 30 | } 31 | for(int i = 0; i < nBins+1; i++){ 32 | printf("binEdges[%i] = %1.3f\n", i, binEdges[i]); 33 | } 34 | */ 35 | 36 | double maxCount = 0; 37 | int numMaxs = 1; 38 | double out = 0;; 39 | for(int i = 0; i < nBins; i++) 40 | { 41 | // printf("binInd=%i, binCount=%i, binEdge=%1.3f \n", i, histCounts[i], binEdges[i]); 42 | 43 | if (histCounts[i] > maxCount) 44 | { 45 | maxCount = histCounts[i]; 46 | numMaxs = 1; 47 | out = (binEdges[i] + binEdges[i+1])*0.5; 48 | } 49 | else if (histCounts[i] == maxCount){ 50 | 51 | numMaxs += 1; 52 | out += (binEdges[i] + binEdges[i+1])*0.5; 53 | } 54 | } 55 | out = out/numMaxs; 56 | 57 | // arrays created dynamically in function histcounts 58 | free(histCounts); 59 | free(binEdges); 60 | 61 | return out; 62 | } 63 | 64 | /* 65 | double DN_HistogramMode_5(double y[], int size) 66 | { 67 | 68 | double min = DBL_MAX, max=-DBL_MAX; 69 | for(int i = 0; i < size; i++) 70 | { 71 | if (y[i] < min) 72 | { 73 | min = y[i]; 74 | } 75 | if (y[i] > max) 76 | { 77 | max = y[i]; 78 | } 79 | } 80 | 81 | double binStep = (max - min)/5; 82 | 83 | // fprintf(stdout, "min=%f, max=%f, binStep=%f \n", min, max, binStep); 84 | 85 | int histCounts[5] = {0}; 86 | for(int i = 0; i < size; i++) 87 | { 88 | int binsLeft = 5; 89 | int lowerInd = 0, upperInd = 10; 90 | while(binsLeft > 1) 91 | { 92 | int limitInd = (upperInd - lowerInd)/2 + lowerInd; 93 | double limit = limitInd * binStep + min; 94 | 95 | if (y[i] < limit) 96 | { 97 | upperInd = limitInd; 98 | } 99 | else 100 | { 101 | lowerInd = limitInd; 102 | } 103 | binsLeft = upperInd - lowerInd; 104 | } 105 | histCounts[lowerInd] += 1; 106 | } 107 | 108 | double maxCount = 0; 109 | int maxCountInd = 0; 110 | for(int i = 0; i < 5; i++) 111 | { 112 | // fprintf(stdout, "binInd=%i, binCount=%i \n", i, histCounts[i]); 113 | 114 | if (histCounts[i] > maxCount) 115 | { 116 | maxCountInd = i; 117 | maxCount = histCounts[i]; 118 | } 119 | } 120 | return binStep*(maxCountInd+0.5) + min; 121 | } 122 | 123 | */ 124 | -------------------------------------------------------------------------------- /C/DN_HistogramMode_5.h: -------------------------------------------------------------------------------- 1 | #ifndef DN_HISTOGRAMMODE_5 2 | #define DN_HISTOGRAMMODE_5 3 | #include 4 | #include 5 | #include "stats.h" 6 | 7 | extern double DN_HistogramMode_5(const double y[], const int size); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /C/DN_Mean.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | double DN_Mean(const double a[], const int size) 4 | { 5 | double m = 0.0; 6 | for (int i = 0; i < size; i++) { 7 | m += a[i]; 8 | } 9 | m /= size; 10 | return m; 11 | } 12 | -------------------------------------------------------------------------------- /C/DN_Mean.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Trent Henderson 27 September 2021 3 | // 4 | 5 | #ifndef DN_MEAN 6 | #define DN_MEAN 7 | 8 | #include 9 | 10 | extern double DN_Mean(const double a[], const int size); 11 | 12 | #endif /* DN_MEAN */ -------------------------------------------------------------------------------- /C/DN_OutlierInclude.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "stats.h" 8 | 9 | double DN_OutlierInclude_np_001_mdrmd(const double y[], const int size, const int sign) 10 | { 11 | 12 | // NaN check 13 | for(int i = 0; i < size; i++) 14 | { 15 | if(isnan(y[i])) 16 | { 17 | return NAN; 18 | } 19 | } 20 | 21 | double inc = 0.01; 22 | int tot = 0; 23 | double * yWork = malloc(size * sizeof(double)); 24 | 25 | // apply sign and check constant time series 26 | int constantFlag = 1; 27 | for(int i = 0; i < size; i++) 28 | { 29 | if(y[i] != y[0]) 30 | { 31 | constantFlag = 0; 32 | } 33 | 34 | // apply sign, save in new variable 35 | yWork[i] = sign*y[i]; 36 | 37 | // count pos/ negs 38 | if(yWork[i] >= 0){ 39 | tot += 1; 40 | } 41 | 42 | } 43 | if(constantFlag){ 44 | free(yWork); 45 | return 0; // if constant, return 0 46 | } 47 | 48 | // find maximum (or minimum, depending on sign) 49 | double maxVal = max_(yWork, size); 50 | 51 | // maximum value too small? return 0 52 | if(maxVal < inc){ 53 | free(yWork); 54 | return 0; 55 | } 56 | 57 | int nThresh = maxVal/inc + 1; 58 | 59 | // save the indices where y > threshold 60 | double * r = malloc(size * sizeof * r); 61 | 62 | // save the median over indices with absolute value > threshold 63 | double * msDti1 = malloc(nThresh * sizeof(double)); 64 | double * msDti3 = malloc(nThresh * sizeof(double)); 65 | double * msDti4 = malloc(nThresh * sizeof(double)); 66 | 67 | for(int j = 0; j < nThresh; j++) 68 | { 69 | //printf("j=%i, thr=%1.3f\n", j, j*inc); 70 | 71 | int highSize = 0; 72 | 73 | for(int i = 0; i < size; i++) 74 | { 75 | if(yWork[i] >= j*inc) 76 | { 77 | r[highSize] = i+1; 78 | //printf("r[%i]=%1.f \n", highSize, r[highSize]); 79 | highSize += 1; 80 | } 81 | } 82 | 83 | // intervals between high-values 84 | double * Dt_exc = malloc(highSize * sizeof(double)); 85 | 86 | for(int i = 0; i < highSize-1; i++) 87 | { 88 | //printf("i=%i, r[i+1]=%1.f, r[i]=%1.f \n", i, r[i+1], r[i]); 89 | Dt_exc[i] = r[i+1] - r[i]; 90 | } 91 | 92 | /* 93 | // median 94 | double medianOut; 95 | medianOut = median(r, highSize); 96 | */ 97 | 98 | msDti1[j] = mean(Dt_exc, highSize-1); 99 | msDti3[j] = (highSize-1)*100.0/tot; 100 | msDti4[j] = median(r, highSize) / ((double)size/2) - 1; 101 | 102 | //printf("msDti1[%i] = %1.3f, msDti13[%i] = %1.3f, msDti4[%i] = %1.3f\n", 103 | // j, msDti1[j], j, msDti3[j], j, msDti4[j]); 104 | 105 | free(Dt_exc); 106 | 107 | } 108 | 109 | int trimthr = 2; 110 | int mj = 0; 111 | int fbi = nThresh-1; 112 | for(int i = 0; i < nThresh; i ++) 113 | { 114 | if (msDti3[i] > trimthr) 115 | { 116 | mj = i; 117 | } 118 | if (isnan(msDti1[nThresh-1-i])) 119 | { 120 | fbi = nThresh-1-i; 121 | } 122 | } 123 | 124 | double outputScalar; 125 | int trimLimit = mj < fbi ? mj : fbi; 126 | outputScalar = median(msDti4, trimLimit+1); 127 | 128 | free(r); 129 | free(yWork); 130 | free(msDti1); 131 | free(msDti3); 132 | free(msDti4); 133 | 134 | return outputScalar; 135 | } 136 | 137 | double DN_OutlierInclude_p_001_mdrmd(const double y[], const int size) 138 | { 139 | return DN_OutlierInclude_np_001_mdrmd(y, size, 1.0); 140 | } 141 | 142 | double DN_OutlierInclude_n_001_mdrmd(const double y[], const int size) 143 | { 144 | return DN_OutlierInclude_np_001_mdrmd(y, size, -1.0); 145 | } 146 | 147 | double DN_OutlierInclude_abs_001(const double y[], const int size) 148 | { 149 | double inc = 0.01; 150 | double maxAbs = 0; 151 | double * yAbs = malloc(size * sizeof * yAbs); 152 | 153 | for(int i = 0; i < size; i++) 154 | { 155 | // yAbs[i] = (y[i] > 0) ? y[i] : -y[i]; 156 | yAbs[i] = (y[i] > 0) ? y[i] : -y[i]; 157 | 158 | if(yAbs[i] > maxAbs) 159 | { 160 | maxAbs = yAbs[i]; 161 | } 162 | } 163 | 164 | int nThresh = maxAbs/inc + 1; 165 | 166 | printf("nThresh = %i\n", nThresh); 167 | 168 | // save the indices where y > threshold 169 | double * highInds = malloc(size * sizeof * highInds); 170 | 171 | // save the median over indices with absolute value > threshold 172 | double * msDti3 = malloc(nThresh * sizeof * msDti3); 173 | double * msDti4 = malloc(nThresh * sizeof * msDti4); 174 | 175 | for(int j = 0; j < nThresh; j++) 176 | { 177 | int highSize = 0; 178 | 179 | for(int i = 0; i < size; i++) 180 | { 181 | if(yAbs[i] >= j*inc) 182 | { 183 | // fprintf(stdout, "%i, ", i); 184 | 185 | highInds[highSize] = i; 186 | highSize += 1; 187 | } 188 | } 189 | 190 | // median 191 | double medianOut; 192 | medianOut = median(highInds, highSize); 193 | 194 | msDti3[j] = (highSize-1)*100.0/size; 195 | msDti4[j] = medianOut / (size/2) - 1; 196 | 197 | } 198 | 199 | int trimthr = 2; 200 | int mj = 0; 201 | for(int i = 0; i < nThresh; i ++) 202 | { 203 | if (msDti3[i] > trimthr) 204 | { 205 | mj = i; 206 | } 207 | } 208 | 209 | double outputScalar; 210 | outputScalar = median(msDti4, mj); 211 | 212 | free(highInds); 213 | free(yAbs); 214 | free(msDti4); 215 | 216 | return outputScalar; 217 | } 218 | -------------------------------------------------------------------------------- /C/DN_OutlierInclude.h: -------------------------------------------------------------------------------- 1 | #ifndef DN_OUTLIERINCLUDE_ABS_001 2 | #define DN_OUTLIERINCLUDE_ABS_001 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "stats.h" 8 | 9 | extern double DN_OutlierInclude_abs_001(const double y[], const int size); 10 | extern double DN_OutlierInclude_np_001_mdrmd(const double y[], const int size, const int sign); 11 | extern double DN_OutlierInclude_p_001_mdrmd(const double y[], const int size); 12 | extern double DN_OutlierInclude_n_001_mdrmd(const double y[], const int size); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /C/DN_Spread_Std.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stats.h" 3 | 4 | double DN_Spread_Std(const double a[], const int size) 5 | { 6 | double m = mean(a, size); 7 | double sd = 0.0; 8 | for (int i = 0; i < size; i++) { 9 | sd += pow(a[i] - m, 2); 10 | } 11 | sd = sqrt(sd / (size - 1)); 12 | return sd; 13 | } 14 | -------------------------------------------------------------------------------- /C/DN_Spread_Std.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Trent Henderson 27 September 2021 3 | // 4 | 5 | #ifndef DN_SPREADSTD 6 | #define DN_SPREADSTD 7 | 8 | #include 9 | 10 | extern double DN_Spread_Std(const double a[], const int size); 11 | 12 | #endif /* DN_SPREADSTD */ -------------------------------------------------------------------------------- /C/FC_LocalSimple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stats.h" 4 | #include "CO_AutoCorr.h" 5 | 6 | static void abs_diff(const double a[], const int size, double b[]) 7 | { 8 | for (int i = 1; i < size; i++) { 9 | b[i - 1] = fabs(a[i] - a[i - 1]); 10 | } 11 | } 12 | 13 | double fc_local_simple(const double y[], const int size, const int train_length) 14 | { 15 | double * y1 = malloc((size - 1) * sizeof *y1); 16 | abs_diff(y, size, y1); 17 | double m = mean(y1, size - 1); 18 | free(y1); 19 | return m; 20 | } 21 | 22 | double FC_LocalSimple_mean_tauresrat(const double y[], const int size, const int train_length) 23 | { 24 | 25 | // NaN check 26 | for(int i = 0; i < size; i++) 27 | { 28 | if(isnan(y[i])) 29 | { 30 | return NAN; 31 | } 32 | } 33 | 34 | double * res = malloc((size - train_length) * sizeof *res); 35 | 36 | for (int i = 0; i < size - train_length; i++) 37 | { 38 | double yest = 0; 39 | for (int j = 0; j < train_length; j++) 40 | { 41 | yest += y[i+j]; 42 | 43 | } 44 | yest /= train_length; 45 | 46 | res[i] = y[i+train_length] - yest; 47 | } 48 | 49 | double resAC1stZ = co_firstzero(res, size - train_length, size - train_length); 50 | double yAC1stZ = co_firstzero(y, size, size); 51 | double output = resAC1stZ/yAC1stZ; 52 | 53 | free(res); 54 | return output; 55 | 56 | } 57 | 58 | double FC_LocalSimple_mean_stderr(const double y[], const int size, const int train_length) 59 | { 60 | // NaN check 61 | for(int i = 0; i < size; i++) 62 | { 63 | if(isnan(y[i])) 64 | { 65 | return NAN; 66 | } 67 | } 68 | 69 | double * res = malloc((size - train_length) * sizeof *res); 70 | 71 | for (int i = 0; i < size - train_length; i++) 72 | { 73 | double yest = 0; 74 | for (int j = 0; j < train_length; j++) 75 | { 76 | yest += y[i+j]; 77 | 78 | } 79 | yest /= train_length; 80 | 81 | res[i] = y[i+train_length] - yest; 82 | } 83 | 84 | double output = stddev(res, size - train_length); 85 | 86 | free(res); 87 | return output; 88 | 89 | } 90 | 91 | double FC_LocalSimple_mean3_stderr(const double y[], const int size) 92 | { 93 | return FC_LocalSimple_mean_stderr(y, size, 3); 94 | } 95 | 96 | double FC_LocalSimple_mean1_tauresrat(const double y[], const int size){ 97 | return FC_LocalSimple_mean_tauresrat(y, size, 1); 98 | } 99 | 100 | double FC_LocalSimple_mean_taures(const double y[], const int size, const int train_length) 101 | { 102 | double * res = malloc((size - train_length) * sizeof *res); 103 | 104 | // first z-score 105 | // no, assume ts is z-scored!! 106 | //zscore_norm(y, size); 107 | 108 | for (int i = 0; i < size - train_length; i++) 109 | { 110 | double yest = 0; 111 | for (int j = 0; j < train_length; j++) 112 | { 113 | yest += y[i+j]; 114 | 115 | } 116 | yest /= train_length; 117 | 118 | res[i] = y[i+train_length] - yest; 119 | } 120 | 121 | int output = co_firstzero(res, size - train_length, size - train_length); 122 | 123 | free(res); 124 | return output; 125 | 126 | } 127 | 128 | double FC_LocalSimple_lfit_taures(const double y[], const int size) 129 | { 130 | // set tau from first AC zero crossing 131 | int train_length = co_firstzero(y, size, size); 132 | 133 | double * xReg = malloc(train_length * sizeof * xReg); 134 | // double * yReg = malloc(train_length * sizeof * yReg); 135 | for(int i = 1; i < train_length+1; i++) 136 | { 137 | xReg[i-1] = i; 138 | } 139 | 140 | double * res = malloc((size - train_length) * sizeof *res); 141 | 142 | double m = 0.0, b = 0.0; 143 | 144 | for (int i = 0; i < size - train_length; i++) 145 | { 146 | linreg(train_length, xReg, y+i, &m, &b); 147 | 148 | // fprintf(stdout, "i=%i, m=%f, b=%f\n", i, m, b); 149 | 150 | res[i] = y[i+train_length] - (m * (train_length+1) + b); 151 | } 152 | 153 | int output = co_firstzero(res, size - train_length, size - train_length); 154 | 155 | free(res); 156 | free(xReg); 157 | // free(yReg); 158 | 159 | return output; 160 | 161 | } 162 | 163 | 164 | -------------------------------------------------------------------------------- /C/FC_LocalSimple.h: -------------------------------------------------------------------------------- 1 | #ifndef FC_LOCALSIMPLE_H 2 | #define FC_LOCALSIMPLE_H 3 | #include 4 | #include 5 | #include "stats.h" 6 | #include "CO_AutoCorr.h" 7 | 8 | extern double fc_local_simple(const double y[], const int size, const int train_length); 9 | extern double FC_LocalSimple_mean_taures(const double y[], const int size, const int train_length); 10 | extern double FC_LocalSimple_lfit_taures(const double y[], const int size); 11 | extern double FC_LocalSimple_mean_tauresrat(const double y[], const int size, const int train_length); 12 | extern double FC_LocalSimple_mean1_tauresrat(const double y[], const int size); 13 | extern double FC_LocalSimple_mean_stderr(const double y[], const int size, const int train_length); 14 | extern double FC_LocalSimple_mean3_stderr(const double y[], const int size); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /C/IN_AutoMutualInfoStats.c: -------------------------------------------------------------------------------- 1 | // 2 | // IN_AutoMutualInfoStats.c 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 22/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | #include 9 | 10 | #include "IN_AutoMutualInfoStats.h" 11 | #include "CO_AutoCorr.h" 12 | #include "stats.h" 13 | 14 | double IN_AutoMutualInfoStats_40_gaussian_fmmi(const double y[], const int size) 15 | { 16 | // NaN check 17 | for(int i = 0; i < size; i++) 18 | { 19 | if(isnan(y[i])) 20 | { 21 | return NAN; 22 | } 23 | } 24 | 25 | // maximum time delay 26 | int tau = 40; 27 | 28 | // don't go above half the signal length 29 | if(tau > ceil((double)size/2)){ 30 | tau = ceil((double)size/2); 31 | } 32 | 33 | // compute autocorrelations and compute automutual information 34 | double * ami = malloc(size * sizeof(double)); 35 | for(int i = 0; i < tau; i++){ 36 | double ac = autocorr_lag(y,size, i+1); 37 | ami[i] = -0.5 * log(1 - ac*ac); 38 | // printf("ami[%i]=%1.7f\n", i, ami[i]); 39 | } 40 | 41 | // find first minimum of automutual information 42 | double fmmi = tau; 43 | for(int i = 1; i < tau-1; i++){ 44 | if(ami[i] < ami[i-1] & ami[i] < ami[i+1]){ 45 | fmmi = i; 46 | // printf("found minimum at %i\n", i); 47 | break; 48 | } 49 | } 50 | 51 | free(ami); 52 | 53 | return fmmi; 54 | } 55 | -------------------------------------------------------------------------------- /C/IN_AutoMutualInfoStats.h: -------------------------------------------------------------------------------- 1 | // 2 | // IN_AutoMutualInfoStats.h 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 22/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #ifndef IN_AutoMutualInfoStats_h 10 | #define IN_AutoMutualInfoStats_h 11 | 12 | #include 13 | 14 | extern double IN_AutoMutualInfoStats_40_gaussian_fmmi(const double y[], const int size); 15 | 16 | #endif /* IN_AutoMutualInfoStats_h */ 17 | -------------------------------------------------------------------------------- /C/MD_hrv.c: -------------------------------------------------------------------------------- 1 | // 2 | // MD_hrv.c 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 22/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #include "MD_hrv.h" 10 | #include "stats.h" 11 | 12 | double MD_hrv_classic_pnn40(const double y[], const int size){ 13 | 14 | // NaN check 15 | for(int i = 0; i < size; i++) 16 | { 17 | if(isnan(y[i])) 18 | { 19 | return NAN; 20 | } 21 | } 22 | 23 | const int pNNx = 40; 24 | 25 | // compute diff 26 | double * Dy = malloc((size-1) * sizeof(double)); 27 | diff(y, size, Dy); 28 | 29 | double pnn40 = 0; 30 | for(int i = 0; i < size-1; i++){ 31 | if(fabs(Dy[i])*1000 > pNNx){ 32 | pnn40 += 1; 33 | } 34 | } 35 | 36 | free(Dy); 37 | 38 | return pnn40/(size-1); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /C/MD_hrv.h: -------------------------------------------------------------------------------- 1 | // 2 | // MD_hrv.h 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 22/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #ifndef MD_hrv_h 10 | #define MD_hrv_h 11 | 12 | #include 13 | 14 | extern double MD_hrv_classic_pnn40(const double y[], const int size); 15 | 16 | #endif /* MD_hrv_h */ 17 | -------------------------------------------------------------------------------- /C/PD_PeriodicityWang.c: -------------------------------------------------------------------------------- 1 | // 2 | // PD_PeriodicityWang.c 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 28/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | 12 | #include "PD_PeriodicityWang.h" 13 | #include "splinefit.h" 14 | #include "stats.h" 15 | 16 | int PD_PeriodicityWang_th0_01(const double * y, const int size){ 17 | 18 | // NaN check 19 | for(int i = 0; i < size; i++) 20 | { 21 | if(isnan(y[i])) 22 | { 23 | return 0; 24 | } 25 | } 26 | 27 | const double th = 0.01; 28 | 29 | double * ySpline = malloc(size * sizeof(double)); 30 | 31 | // fit a spline with 3 nodes to the data 32 | splinefit(y, size, ySpline); 33 | 34 | //printf("spline fit complete.\n"); 35 | 36 | // subtract spline from data to remove trend 37 | double * ySub = malloc(size * sizeof(double)); 38 | for(int i = 0; i < size; i++){ 39 | ySub[i] = y[i] - ySpline[i]; 40 | //printf("ySub[%i] = %1.5f\n", i, ySub[i]); 41 | } 42 | 43 | // compute autocorrelations up to 1/3 of the length of the time series 44 | int acmax = (int)ceil((double)size/3); 45 | 46 | double * acf = malloc(acmax*sizeof(double)); 47 | for(int tau = 1; tau <= acmax; tau++){ 48 | // correlation/ covariance the same, don't care for scaling (cov would be more efficient) 49 | acf[tau-1] = autocov_lag(ySub, size, tau); 50 | //printf("acf[%i] = %1.9f\n", tau-1, acf[tau-1]); 51 | } 52 | 53 | //printf("ACF computed.\n"); 54 | 55 | // find troughts and peaks 56 | double * troughs = malloc(acmax * sizeof(double)); 57 | double * peaks = malloc(acmax * sizeof(double)); 58 | int nTroughs = 0; 59 | int nPeaks = 0; 60 | double slopeIn = 0; 61 | double slopeOut = 0; 62 | for(int i = 1; i < acmax-1; i ++){ 63 | slopeIn = acf[i] - acf[i-1]; 64 | slopeOut = acf[i+1] - acf[i]; 65 | 66 | if(slopeIn < 0 & slopeOut > 0) 67 | { 68 | // printf("trough at %i\n", i); 69 | troughs[nTroughs] = i; 70 | nTroughs += 1; 71 | } 72 | else if(slopeIn > 0 & slopeOut < 0) 73 | { 74 | // printf("peak at %i\n", i); 75 | peaks[nPeaks] = i; 76 | nPeaks += 1; 77 | } 78 | } 79 | 80 | //printf("%i troughs and %i peaks found.\n", nTroughs, nPeaks); 81 | 82 | 83 | // search through all peaks for one that meets the conditions: 84 | // (a) a trough before it 85 | // (b) difference between peak and trough is at least 0.01 86 | // (c) peak corresponds to positive correlation 87 | int iPeak = 0; 88 | double thePeak = 0; 89 | int iTrough = 0; 90 | double theTrough = 0; 91 | 92 | int out = 0; 93 | 94 | for(int i = 0; i < nPeaks; i++){ 95 | iPeak = peaks[i]; 96 | thePeak = acf[iPeak]; 97 | 98 | //printf("i=%i/%i, iPeak=%i, thePeak=%1.3f\n", i, nPeaks-1, iPeak, thePeak); 99 | 100 | // find trough before this peak 101 | int j = -1; 102 | while(troughs[j+1] < iPeak && j+1 < nTroughs){ 103 | // printf("j=%i/%i, iTrough=%i, theTrough=%1.3f\n", j+1, nTroughs-1, (int)troughs[j+1], acf[(int)troughs[j+1]]); 104 | j++; 105 | } 106 | if(j == -1) 107 | continue; 108 | 109 | iTrough = troughs[j]; 110 | theTrough = acf[iTrough]; 111 | 112 | // (a) should be implicit 113 | 114 | // (b) different between peak and trough it as least 0.01 115 | if(thePeak - theTrough < th) 116 | continue; 117 | 118 | // (c) peak corresponds to positive correlation 119 | if(thePeak < 0) 120 | continue; 121 | 122 | // use this frequency that first fulfils all conditions. 123 | out = iPeak; 124 | break; 125 | } 126 | 127 | //printf("Before freeing stuff.\n"); 128 | 129 | free(ySpline); 130 | free(ySub); 131 | free(acf); 132 | free(troughs); 133 | free(peaks); 134 | 135 | return out; 136 | 137 | } 138 | -------------------------------------------------------------------------------- /C/PD_PeriodicityWang.h: -------------------------------------------------------------------------------- 1 | // 2 | // PD_PeriodicityWang.h 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 28/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #ifndef PD_PeriodicityWang_h 10 | #define PD_PeriodicityWang_h 11 | 12 | #include 13 | 14 | extern int PD_PeriodicityWang_th0_01(const double * y, const int size); 15 | 16 | #endif /* PD_PeriodicityWang_h */ 17 | -------------------------------------------------------------------------------- /C/SB_BinaryStats.c: -------------------------------------------------------------------------------- 1 | // 2 | // SB_BinaryStats.c 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 22/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #include "SB_BinaryStats.h" 10 | #include "stats.h" 11 | 12 | double SB_BinaryStats_diff_longstretch0(const double y[], const int size){ 13 | 14 | // NaN check 15 | for(int i = 0; i < size; i++) 16 | { 17 | if(isnan(y[i])) 18 | { 19 | return NAN; 20 | } 21 | } 22 | 23 | // binarize 24 | int * yBin = malloc((size-1) * sizeof(int)); 25 | for(int i = 0; i < size-1; i++){ 26 | 27 | double diffTemp = y[i+1] - y[i]; 28 | yBin[i] = diffTemp < 0 ? 0 : 1; 29 | 30 | /* 31 | if( i < 300) 32 | printf("%i, y[i+1]=%1.3f, y[i]=%1.3f, yBin[i]=%i\n", i, y[i+1], y[i], yBin[i]); 33 | */ 34 | 35 | } 36 | 37 | int maxstretch0 = 0; 38 | int last1 = 0; 39 | for(int i = 0; i < size-1; i++){ 40 | if(yBin[i] == 1 | i == size-2){ 41 | double stretch0 = i - last1; 42 | if(stretch0 > maxstretch0){ 43 | maxstretch0 = stretch0; 44 | } 45 | last1 = i; 46 | } 47 | } 48 | 49 | free(yBin); 50 | 51 | return maxstretch0; 52 | } 53 | 54 | double SB_BinaryStats_mean_longstretch1(const double y[], const int size){ 55 | 56 | // NaN check 57 | for(int i = 0; i < size; i++) 58 | { 59 | if(isnan(y[i])) 60 | { 61 | return NAN; 62 | } 63 | } 64 | 65 | // binarize 66 | int * yBin = malloc((size-1) * sizeof(int)); 67 | double yMean = mean(y, size); 68 | for(int i = 0; i < size-1; i++){ 69 | 70 | yBin[i] = (y[i] - yMean <= 0) ? 0 : 1; 71 | //printf("yBin[%i]=%i\n", i, yBin[i]); 72 | 73 | } 74 | 75 | int maxstretch1 = 0; 76 | int last1 = 0; 77 | for(int i = 0; i < size-1; i++){ 78 | if(yBin[i] == 0 | i == size-2){ 79 | double stretch1 = i - last1; 80 | if(stretch1 > maxstretch1){ 81 | maxstretch1 = stretch1; 82 | } 83 | last1 = i; 84 | } 85 | 86 | } 87 | 88 | free(yBin); 89 | 90 | return maxstretch1; 91 | } 92 | -------------------------------------------------------------------------------- /C/SB_BinaryStats.h: -------------------------------------------------------------------------------- 1 | // 2 | // SB_BinaryStats.h 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 22/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #ifndef SB_BinaryStats_h 10 | #define SB_BinaryStats_h 11 | 12 | #include 13 | 14 | extern double SB_BinaryStats_diff_longstretch0(const double y[], const int size); 15 | extern double SB_BinaryStats_mean_longstretch1(const double y[], const int size); 16 | 17 | #endif /* SB_BinaryStats_h */ 18 | -------------------------------------------------------------------------------- /C/SB_CoarseGrain.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "stats.h" 6 | #include "helper_functions.h" 7 | 8 | void sb_coarsegrain(const double y[], const int size, const char how[], const int num_groups, int labels[]) 9 | { 10 | int i, j; 11 | if (strcmp(how, "quantile") == 1) { 12 | fprintf(stdout, "ERROR in sb_coarsegrain: unknown coarse-graining method\n"); 13 | exit(1); 14 | } 15 | 16 | /* 17 | for(int i = 0; i < size; i++){ 18 | printf("yin coarsegrain[%i]=%1.4f\n", i, y[i]); 19 | } 20 | */ 21 | 22 | double * th = malloc((num_groups + 1) * 2 * sizeof(th)); 23 | double * ls = malloc((num_groups + 1) * 2 * sizeof(th)); 24 | linspace(0, 1, num_groups + 1, ls); 25 | for (i = 0; i < num_groups + 1; i++) { 26 | //double quant = quantile(y, size, ls[i]); 27 | th[i] = quantile(y, size, ls[i]); 28 | } 29 | th[0] -= 1; 30 | for (i = 0; i < num_groups; i++) { 31 | for (j = 0; j < size; j++) { 32 | if (y[j] > th[i] && y[j] <= th[i + 1]) { 33 | labels[j] = i + 1; 34 | } 35 | } 36 | } 37 | 38 | free(th); 39 | free(ls); 40 | } 41 | -------------------------------------------------------------------------------- /C/SB_CoarseGrain.h: -------------------------------------------------------------------------------- 1 | #ifndef SB_COARSEGRAIN_H 2 | #define SB_COARSEGRAIN_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "stats.h" 8 | #include "helper_functions.h" 9 | 10 | extern void sb_coarsegrain(const double y[], const int size, const char how[], const int num_groups, int labels[]); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /C/SB_MotifThree.h: -------------------------------------------------------------------------------- 1 | #ifndef SB_MOTIFTHREE_H 2 | #define SB_MOTIFTHREE_H 3 | #include 4 | #include 5 | #include 6 | #include "SB_CoarseGrain.h" 7 | #include "helper_functions.h" 8 | 9 | extern double SB_MotifThree_quantile_hh(const double y[], const int size); 10 | extern double * sb_motifthree(const double y[], int size, const char how[]); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /C/SB_TransitionMatrix.c: -------------------------------------------------------------------------------- 1 | // 2 | // SB_TransitionMatrix.c 3 | // 4 | // 5 | // Created by Carl Henning Lubba on 23/09/2018. 6 | // 7 | 8 | #include "SB_TransitionMatrix.h" 9 | #include "butterworth.h" 10 | #include "CO_AutoCorr.h" 11 | #include "SB_CoarseGrain.h" 12 | #include "stats.h" 13 | 14 | double SB_TransitionMatrix_3ac_sumdiagcov(const double y[], const int size) 15 | { 16 | 17 | // NaN and const check 18 | int constant = 1; 19 | for(int i = 0; i < size; i++) 20 | { 21 | if(isnan(y[i])) 22 | { 23 | return NAN; 24 | } 25 | if(y[i] != y[0]){ 26 | constant = 0; 27 | } 28 | } 29 | if (constant){ 30 | return NAN; 31 | } 32 | 33 | const int numGroups = 3; 34 | 35 | int tau = co_firstzero(y, size, size); 36 | 37 | double * yFilt = malloc(size * sizeof(double)); 38 | 39 | // sometimes causes problems in filt!!! needs fixing. 40 | /* 41 | if(tau > 1){ 42 | butterworthFilter(y, size, 4, 0.8/tau, yFilt); 43 | } 44 | */ 45 | 46 | for(int i = 0; i < size; i++){ 47 | yFilt[i] = y[i]; 48 | } 49 | 50 | /* 51 | for(int i = 0; i < size; i++){ 52 | printf("yFilt[%i]=%1.4f\n", i, yFilt[i]); 53 | } 54 | */ 55 | 56 | int nDown = (size-1)/tau+1; 57 | double * yDown = malloc(nDown * sizeof(double)); 58 | 59 | for(int i = 0; i < nDown; i++){ 60 | yDown[i] = yFilt[i*tau]; 61 | } 62 | 63 | /* 64 | for(int i = 0; i < nDown; i++){ 65 | printf("yDown[%i]=%1.4f\n", i, yDown[i]); 66 | } 67 | */ 68 | 69 | 70 | // transfer to alphabet 71 | int * yCG = malloc(nDown * sizeof(double)); 72 | sb_coarsegrain(yDown, nDown, "quantile", numGroups, yCG); 73 | 74 | /* 75 | for(int i = 0; i < nDown; i++){ 76 | printf("yCG[%i]=%i\n", i, yCG[i]); 77 | } 78 | */ 79 | 80 | 81 | double T[3][3]; 82 | for(int i = 0; i < numGroups; i++){ 83 | for(int j = 0; j < numGroups; j++){ 84 | T[i][j] = 0; 85 | } 86 | } 87 | 88 | // more efficient way of doing the below 89 | for(int j = 0; j < nDown-1; j++){ 90 | T[yCG[j]-1][yCG[j+1]-1] += 1; 91 | } 92 | 93 | /* 94 | for(int i = 0; i < numGroups; i++){ 95 | for(int j = 0; j < numGroups; j++){ 96 | printf("%1.f, ", T[i][j]); 97 | } 98 | printf("\n"); 99 | } 100 | */ 101 | 102 | /* 103 | for(int i = 0; i < numGroups; i++){ 104 | for(int j = 0; j < nDown-1; j++){ 105 | if(yCG[j] == i+1){ 106 | T[i][yCG[j+1]-1] += 1; 107 | } 108 | } 109 | } 110 | */ 111 | 112 | for(int i = 0; i < numGroups; i++){ 113 | for(int j = 0; j < numGroups; j++){ 114 | T[i][j] /= (nDown-1); 115 | // printf("T(%i, %i) = %1.3f\n", i, j, T[i][j]); 116 | 117 | } 118 | } 119 | 120 | double column1[3] = {0}; 121 | double column2[3] = {0}; 122 | double column3[3] = {0}; 123 | 124 | for(int i = 0; i < numGroups; i++){ 125 | column1[i] = T[i][0]; 126 | column2[i] = T[i][1]; 127 | column3[i] = T[i][2]; 128 | // printf("column3(%i) = %1.3f\n", i, column3[i]); 129 | } 130 | 131 | double *columns[3]; 132 | columns[0] = &(column1[0]); 133 | columns[1] = &(column2[0]); 134 | columns[2] = &(column3[0]); 135 | 136 | 137 | double COV[3][3]; 138 | double covTemp = 0; 139 | for(int i = 0; i < numGroups; i++){ 140 | for(int j = i; j < numGroups; j++){ 141 | 142 | covTemp = cov(columns[i], columns[j], 3); 143 | 144 | COV[i][j] = covTemp; 145 | COV[j][i] = covTemp; 146 | 147 | // printf("COV(%i , %i) = %1.3f\n", i, j, COV[i][j]); 148 | } 149 | } 150 | 151 | double sumdiagcov = 0; 152 | for(int i = 0; i < numGroups; i++){ 153 | sumdiagcov += COV[i][i]; 154 | } 155 | 156 | free(yFilt); 157 | free(yDown); 158 | free(yCG); 159 | 160 | return sumdiagcov; 161 | 162 | 163 | } 164 | -------------------------------------------------------------------------------- /C/SB_TransitionMatrix.h: -------------------------------------------------------------------------------- 1 | // 2 | // SB_TransitionMatrix.h 3 | // 4 | // 5 | // Created by Carl Henning Lubba on 23/09/2018. 6 | // 7 | 8 | #ifndef SB_TransitionMatrix_h 9 | #define SB_TransitionMatrix_h 10 | 11 | #include 12 | 13 | extern double SB_TransitionMatrix_3ac_sumdiagcov(const double y[], const int size); 14 | 15 | #endif /* SB_TransitionMatrix_h */ 16 | -------------------------------------------------------------------------------- /C/SC_FluctAnal.h: -------------------------------------------------------------------------------- 1 | #ifndef SC_FLUCTANAL 2 | #define SC_FLUCTANAL 3 | #include 4 | #include 5 | #include "stats.h" 6 | #include "CO_AutoCorr.h" 7 | 8 | extern double SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(const double y[], const int size); 9 | extern double SC_FluctAnal_2_50_1_logi_prop_r1(const double y[], const int size, const char how[]); 10 | extern double SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(const double y[], const int size); 11 | #endif 12 | -------------------------------------------------------------------------------- /C/SP_Summaries.c: -------------------------------------------------------------------------------- 1 | // 2 | // SP_Summaries.c 3 | // 4 | // 5 | // Created by Carl Henning Lubba on 23/09/2018. 6 | // 7 | 8 | #include "SP_Summaries.h" 9 | #include "CO_AutoCorr.h" 10 | 11 | int welch(const double y[], const int size, const int NFFT, const double Fs, const double window[], const int windowWidth, double ** Pxx, double ** f){ 12 | 13 | double dt = 1.0/Fs; 14 | double df = 1.0/(nextpow2(windowWidth))/dt; 15 | double m = mean(y, size); 16 | 17 | // number of windows, should be 1 18 | int k = floor((double)size/((double)windowWidth/2.0))-1; 19 | 20 | // normalising scale factor 21 | double KMU = k * pow(norm_(window, windowWidth),2); 22 | 23 | double * P = malloc(NFFT * sizeof(double)); 24 | for(int i = 0; i < NFFT; i++){ 25 | P[i] = 0; 26 | } 27 | 28 | // fft variables 29 | cplx * F = malloc(NFFT * sizeof *F); 30 | cplx * tw = malloc(NFFT * sizeof *tw); 31 | twiddles(tw, NFFT); 32 | 33 | double * xw = malloc(windowWidth * sizeof(double)); 34 | for(int i = 0; i0 & i < Nout-1){ 87 | (*Pxx)[i] *= 2; 88 | } 89 | } 90 | /* 91 | for(int i = 0; i < Nout; i++){ 92 | printf("Pxx[%i]: %1.3f\n", i, Pxx[i]); 93 | } 94 | */ 95 | 96 | *f = malloc(Nout * sizeof(double)); 97 | for(int i = 0; i < Nout; i++){ 98 | (*f)[i] = (double)i*df; 99 | } 100 | /* 101 | for(int i = 0; i < Nout; i++){ 102 | printf("f[%i]: %1.3f\n", i, (*f)[i]); 103 | } 104 | */ 105 | 106 | free(P); 107 | free(F); 108 | free(tw); 109 | free(xw); 110 | 111 | return Nout; 112 | } 113 | 114 | double SP_Summaries_welch_rect(const double y[], const int size, const char what[]) 115 | { 116 | 117 | // NaN check 118 | for(int i = 0; i < size; i++) 119 | { 120 | if(isnan(y[i])) 121 | { 122 | return NAN; 123 | } 124 | } 125 | 126 | // rectangular window for Welch-spectrum 127 | double * window = malloc(size * sizeof(double)); 128 | for(int i = 0; i < size; i++){ 129 | window[i] = 1; 130 | } 131 | 132 | double Fs = 1.0; // sampling frequency 133 | int N = nextpow2(size); 134 | 135 | double * S; 136 | double * f; 137 | 138 | // compute Welch-power 139 | int nWelch = welch(y, size, N, Fs, window, size, &S, &f); 140 | free(window); 141 | 142 | // angualr frequency and spectrum on that 143 | double * w = malloc(nWelch * sizeof(double)); 144 | double * Sw = malloc(nWelch * sizeof(double)); 145 | 146 | double PI = 3.14159265359; 147 | for(int i = 0; i < nWelch; i++){ 148 | w[i] = 2*PI*f[i]; 149 | Sw[i] = S[i]/(2*PI); 150 | //printf("w[%i]=%1.3f, Sw[%i]=%1.3f\n", i, w[i], i, Sw[i]); 151 | if(isinf(Sw[i]) | isinf(-Sw[i])){ 152 | return 0; 153 | } 154 | } 155 | 156 | double dw = w[1] - w[0]; 157 | 158 | double * csS = malloc(nWelch * sizeof(double)); 159 | cumsum(Sw, nWelch, csS); 160 | /* 161 | for(int i=0; i csSThres){ 175 | centroid = w[i]; 176 | break; 177 | } 178 | } 179 | 180 | output = centroid; 181 | 182 | } 183 | else if(strcmp(what, "area_5_1") == 0){ 184 | double area_5_1 = 0;; 185 | for(int i=0; i 12 | 13 | extern double SP_Summaries_welch_rect(const double y[], const int size, const char what[]); 14 | extern double SP_Summaries_welch_rect_area_5_1(const double y[], const int size); 15 | extern double SP_Summaries_welch_rect_centroid(const double y[], const int size); 16 | 17 | #endif /* SP_Summaries_h */ 18 | -------------------------------------------------------------------------------- /C/butterworth.h: -------------------------------------------------------------------------------- 1 | // 2 | // butterworth.h 3 | // 4 | // 5 | // Created by Carl Henning Lubba on 23/09/2018. 6 | // 7 | 8 | #ifndef butterworth_h 9 | #define butterworth_h 10 | 11 | #include 12 | 13 | extern void butterworthFilter(const double y[], const int size, const int nPoles, const double W, double out[]); 14 | 15 | #endif /* butterworth_h */ 16 | -------------------------------------------------------------------------------- /C/fft.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #if __cplusplus 6 | # include 7 | typedef std::complex< double > cplx; 8 | #else 9 | # include 10 | #if defined(__GNUC__) || defined(__GNUG__) 11 | typedef double complex cplx; 12 | #elif defined(_MSC_VER) 13 | typedef _Dcomplex cplx; 14 | #endif 15 | #endif 16 | 17 | #ifndef CMPLX 18 | #define CMPLX(x, y) ((cplx)((double)(x) + _Imaginary_I * (double)(y))) 19 | #endif 20 | 21 | #include "helper_functions.h" 22 | 23 | void twiddles(cplx a[], int size) 24 | { 25 | 26 | double PI = 3.14159265359; 27 | 28 | for (int i = 0; i < size; i++) { 29 | // cplx tmp = { 0, -PI * i / size }; 30 | #if defined(__GNUC__) || defined(__GNUG__) 31 | cplx tmp = 0.0 - PI * i / size * I; 32 | #elif defined(_MSC_VER) 33 | cplx tmp = {0.0, -PI * i / size }; 34 | #endif 35 | a[i] = cexp(tmp); 36 | //a[i] = cexp(-I * M_PI * i / size); 37 | } 38 | } 39 | 40 | static void _fft(cplx a[], cplx out[], int size, int step, cplx tw[]) 41 | { 42 | if (step < size) { 43 | _fft(out, a, size, step * 2, tw); 44 | _fft(out + step, a + step, size, step * 2, tw); 45 | 46 | for (int i = 0; i < size; i += 2 * step) { 47 | //cplx t = tw[i] * out[i + step]; 48 | cplx t = _Cmulcc(tw[i], out[i + step]); 49 | a[i / 2] = _Caddcc(out[i], t); 50 | a[(i + size) / 2] = _Cminuscc(out[i], t); 51 | } 52 | } 53 | } 54 | 55 | void fft(cplx a[], int size, cplx tw[]) 56 | { 57 | cplx * out = malloc(size * sizeof(cplx)); 58 | memcpy(out, a, size * sizeof(cplx)); 59 | _fft(a, out, size, 1, tw); 60 | free(out); 61 | } 62 | -------------------------------------------------------------------------------- /C/fft.h: -------------------------------------------------------------------------------- 1 | #ifndef FFT_H 2 | #define FFT_H 3 | //#include 4 | 5 | #if __cplusplus 6 | # include 7 | typedef std::complex< double > cplx; 8 | #else 9 | # include 10 | #if defined(__GNUC__) || defined(__GNUG__) 11 | typedef double complex cplx; 12 | #elif defined(_MSC_VER) 13 | typedef _Dcomplex cplx; 14 | #endif 15 | #endif 16 | 17 | #include 18 | #include 19 | #ifndef CMPLX 20 | #define CMPLX(x, y) ((cplx)((double)(x) + _Complex_I * (double)(y))) 21 | #endif 22 | extern void twiddles(cplx a[], int size); 23 | // extern void _fft(cplx a[], cplx out[], int size, int step, cplx tw[]); 24 | extern void fft(cplx a[], int size, cplx tw[]); 25 | extern void ifft(cplx a[], int size, cplx tw[]); 26 | #endif 27 | -------------------------------------------------------------------------------- /C/helper_functions.c: -------------------------------------------------------------------------------- 1 | #if __cplusplus 2 | # include 3 | typedef std::complex< double > cplx; 4 | #else 5 | # include 6 | #if defined(__GNUC__) || defined(__GNUG__) 7 | typedef double complex cplx; 8 | #elif defined(_MSC_VER) 9 | typedef _Dcomplex cplx; 10 | #endif 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "stats.h" 18 | 19 | // compare function for qsort, for array of doubles 20 | static int compare (const void * a, const void * b) 21 | { 22 | if (*(double*)a < *(double*)b) { 23 | return -1; 24 | } else if (*(double*)a > *(double*)b) { 25 | return 1; 26 | } else { 27 | return 0; 28 | } 29 | } 30 | 31 | // wrapper for qsort for array of doubles. Sorts in-place 32 | void sort(double y[], int size) 33 | { 34 | qsort(y, size, sizeof(*y), compare); 35 | } 36 | 37 | // linearly spaced vector 38 | void linspace(double start, double end, int num_groups, double out[]) 39 | { 40 | double step_size = (end - start) / (num_groups - 1); 41 | for (int i = 0; i < num_groups; i++) { 42 | out[i] = start; 43 | start += step_size; 44 | } 45 | return; 46 | } 47 | 48 | double quantile(const double y[], const int size, const double quant) 49 | { 50 | double quant_idx, q, value; 51 | int idx_left, idx_right; 52 | double * tmp = malloc(size * sizeof(*y)); 53 | memcpy(tmp, y, size * sizeof(*y)); 54 | sort(tmp, size); 55 | 56 | /* 57 | for(int i=0; i < size; i++){ 58 | printf("y[%i]=%1.4f\n", i, y[i]); 59 | } 60 | for(int i=0; i < size; i++){ 61 | printf("sorted[%i]=%1.4f\n", i, tmp[i]); 62 | } 63 | */ 64 | 65 | // out of range limit? 66 | q = 0.5 / size; 67 | if (quant < q) { 68 | value = tmp[0]; // min value 69 | free(tmp); 70 | return value; 71 | } else if (quant > (1 - q)) { 72 | value = tmp[size - 1]; // max value 73 | free(tmp); 74 | return value; 75 | } 76 | 77 | quant_idx = size * quant - 0.5; 78 | idx_left = (int)floor(quant_idx); 79 | idx_right = (int)ceil(quant_idx); 80 | value = tmp[idx_left] + (quant_idx - idx_left) * (tmp[idx_right] - tmp[idx_left]) / (idx_right - idx_left); 81 | free(tmp); 82 | return value; 83 | } 84 | 85 | void binarize(const double a[], const int size, int b[], const char how[]) 86 | { 87 | double m = 0.0; 88 | if (strcmp(how, "mean") == 0) { 89 | m = mean(a, size); 90 | } else if (strcmp(how, "median") == 0) { 91 | m = median(a, size); 92 | } 93 | for (int i = 0; i < size; i++) { 94 | b[i] = (a[i] > m) ? 1 : 0; 95 | } 96 | return; 97 | } 98 | 99 | double f_entropy(const double a[], const int size) 100 | { 101 | double f = 0.0; 102 | for (int i = 0; i < size; i++) { 103 | if (a[i] > 0) { 104 | f += a[i] * log(a[i]); 105 | } 106 | } 107 | return -1 * f; 108 | } 109 | 110 | void subset(const int a[], int b[], const int start, const int end) 111 | { 112 | int j = 0; 113 | for (int i = start; i < end; i++) { 114 | b[j++] = a[i]; 115 | } 116 | return; 117 | } 118 | 119 | #if defined(__GNUC__) || defined(__GNUG__) 120 | cplx _Cmulcc(const cplx x, const cplx y) { 121 | /*double a = x._Val[0]; 122 | double b = x._Val[1]; 123 | 124 | double c = y._Val[0]; 125 | double d = y._Val[1]; 126 | 127 | cplx result = { (a * c - b * d), (a * d + c * b) }; 128 | */ 129 | return x*y; 130 | } 131 | 132 | cplx _Cminuscc(const cplx x, const cplx y) { 133 | //cplx result = { x._Val[0] - y._Val[0], x._Val[1] - y._Val[1] }; 134 | return x - y; 135 | } 136 | 137 | cplx _Caddcc(const cplx x, const cplx y) { 138 | // cplx result = { x._Val[0] + y._Val[0], x._Val[1] + y._Val[1] }; 139 | return x + y; 140 | } 141 | 142 | cplx _Cdivcc(const cplx x, const cplx y) { 143 | 144 | double a = creal(x); 145 | double b = cimag(x); 146 | 147 | double c = creal(y); 148 | double d = cimag(y); 149 | 150 | cplx result = (a*c + b*d) / (c*c + d*d) + (b*c - a*d)/(c*c + d*d) * I; 151 | 152 | return result; 153 | 154 | // return x / y; 155 | } 156 | 157 | #elif defined(_MSC_VER) 158 | cplx _Cminuscc(const cplx x, const cplx y) { 159 | cplx result = { x._Val[0] - y._Val[0], x._Val[1] - y._Val[1] }; 160 | return result; 161 | } 162 | 163 | cplx _Caddcc(const cplx x, const cplx y) { 164 | cplx result = { x._Val[0] + y._Val[0], x._Val[1] + y._Val[1] }; 165 | return result; 166 | } 167 | 168 | cplx _Cdivcc(const cplx x, const cplx y) { 169 | double a = x._Val[0]; 170 | double b = x._Val[1]; 171 | 172 | double c = y._Val[0]; 173 | double d = y._Val[1]; 174 | 175 | cplx result = { (a*c + b*d) / (c*c + d*d), (b*c - a*d)/(c*c + d*d)}; 176 | 177 | return result; 178 | } 179 | #endif 180 | -------------------------------------------------------------------------------- /C/helper_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef HELPER_FUNCTIONS_H 2 | #define HELPER_FUNCTIONS_H 3 | #include 4 | #include 5 | #include 6 | #include "stats.h" 7 | 8 | #if __cplusplus 9 | # include 10 | typedef std::complex< double > cplx; 11 | #else 12 | # include 13 | #if defined(__GNUC__) || defined(__GNUG__) 14 | typedef double complex cplx; 15 | #elif defined(_MSC_VER) 16 | typedef _Dcomplex cplx; 17 | #endif 18 | #endif 19 | 20 | extern void linspace(double start, double end, int num_groups, double out[]); 21 | extern double quantile(const double y[], const int size, const double quant); 22 | extern void sort(double y[], int size); 23 | extern void binarize(const double a[], const int size, int b[], const char how[]); 24 | extern double f_entropy(const double a[], const int size); 25 | extern void subset(const int a[], int b[], const int start, const int end); 26 | 27 | extern cplx _Cminuscc(const cplx x, const cplx y); 28 | extern cplx _Caddcc(const cplx x, const cplx y); 29 | extern cplx _Cdivcc(const cplx x, const cplx y); 30 | #if defined(__GNUC__) || defined(__GNUG__) 31 | extern cplx _Cmulcc(const cplx x, const cplx y); 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /C/histcounts.c: -------------------------------------------------------------------------------- 1 | // 2 | // histcounts.c 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 19/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | 12 | #include "stats.h" 13 | #include "histcounts.h" 14 | 15 | int num_bins_auto(const double y[], const int size){ 16 | 17 | double maxVal = max_(y, size); 18 | double minVal = min_(y, size); 19 | 20 | if (stddev(y, size) < 0.001){ 21 | return 0; 22 | } 23 | 24 | return ceil((maxVal-minVal)/(3.5*stddev(y, size)/pow(size, 1/3.))); 25 | 26 | } 27 | 28 | int histcounts_preallocated(const double y[], const int size, int nBins, int * binCounts, double * binEdges) 29 | { 30 | 31 | int i = 0; 32 | 33 | // check min and max of input array 34 | double minVal = DBL_MAX, maxVal=-DBL_MAX; 35 | for(int i = 0; i < size; i++) 36 | { 37 | // printf("histcountInput %i: %1.3f\n", i, y[i]); 38 | 39 | if (y[i] < minVal) 40 | { 41 | minVal = y[i]; 42 | } 43 | if (y[i] > maxVal) 44 | { 45 | maxVal = y[i]; 46 | } 47 | } 48 | 49 | // and derive bin width from it 50 | double binStep = (maxVal - minVal)/nBins; 51 | 52 | // variable to store counted occurances in 53 | for(i = 0; i < nBins; i++) 54 | { 55 | binCounts[i] = 0; 56 | } 57 | 58 | for(i = 0; i < size; i++) 59 | { 60 | 61 | int binInd = (y[i]-minVal)/binStep; 62 | if(binInd < 0) 63 | binInd = 0; 64 | if(binInd >= nBins) 65 | binInd = nBins-1; 66 | //printf("histcounts, i=%i, binInd=%i, nBins=%i\n", i, binInd, nBins); 67 | binCounts[binInd] += 1; 68 | 69 | } 70 | 71 | for(i = 0; i < nBins+1; i++) 72 | { 73 | binEdges[i] = i * binStep + minVal; 74 | } 75 | 76 | /* 77 | // debug 78 | for(i=0;i maxVal) 104 | { 105 | maxVal = y[i]; 106 | } 107 | } 108 | 109 | // if no number of bins given, choose spaces automatically 110 | if (nBins <= 0){ 111 | nBins = ceil((maxVal-minVal)/(3.5*stddev(y, size)/pow(size, 1/3.))); 112 | } 113 | 114 | // and derive bin width from it 115 | double binStep = (maxVal - minVal)/nBins; 116 | 117 | // variable to store counted occurances in 118 | *binCounts = malloc(nBins * sizeof(int)); 119 | for(i = 0; i < nBins; i++) 120 | { 121 | (*binCounts)[i] = 0; 122 | } 123 | 124 | for(i = 0; i < size; i++) 125 | { 126 | 127 | int binInd = (y[i]-minVal)/binStep; 128 | if(binInd < 0) 129 | binInd = 0; 130 | if(binInd >= nBins) 131 | binInd = nBins-1; 132 | (*binCounts)[binInd] += 1; 133 | 134 | } 135 | 136 | *binEdges = malloc((nBins+1) * sizeof(double)); 137 | for(i = 0; i < nBins+1; i++) 138 | { 139 | (*binEdges)[i] = i * binStep + minVal; 140 | } 141 | 142 | /* 143 | // debug 144 | for(i=0;i 0 163 | binIdentity[i] = 0; 164 | 165 | // go through bin edges 166 | for(int j = 0; j < nEdges; j++){ 167 | if(y[i] < binEdges[j]){ 168 | binIdentity[i] = j; 169 | break; 170 | } 171 | } 172 | } 173 | 174 | return binIdentity; 175 | 176 | } 177 | 178 | int * histcount_edges(const double y[], const int size, const double binEdges[], const int nEdges) 179 | { 180 | 181 | 182 | int * histcounts = malloc(nEdges * sizeof(int)); 183 | for(int i = 0; i < nEdges; i++){ 184 | histcounts[i] = 0; 185 | } 186 | 187 | for(int i = 0; i < size; i++) 188 | { 189 | // go through bin edges 190 | for(int j = 0; j < nEdges; j++){ 191 | if(y[i] <= binEdges[j]){ 192 | histcounts[j] += 1; 193 | break; 194 | } 195 | } 196 | } 197 | 198 | return histcounts; 199 | 200 | } 201 | -------------------------------------------------------------------------------- /C/histcounts.h: -------------------------------------------------------------------------------- 1 | // 2 | // histcounts.h 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 19/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #ifndef histcounts_h 10 | #define histcounts_h 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | extern int num_bins_auto(const double y[], const int size); 17 | extern int histcounts(const double y[], const int size, int nBins, int ** binCounts, double ** binEdges); 18 | extern int histcounts_preallocated(const double y[], const int size, int nBins, int * binCounts, double * binEdges); 19 | extern int * histcount_edges(const double y[], const int size, const double binEdges[], const int nEdges); 20 | extern int * histbinassign(const double y[], const int size, const double binEdges[], const int nEdges); 21 | 22 | #endif /* histcounts_h */ 23 | -------------------------------------------------------------------------------- /C/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | /* Include files */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | /* Function Declarations */ 11 | //extern int main(int argc, const char * const argv[]); 12 | extern int main(int argc, char * argv[]); 13 | 14 | #endif 15 | 16 | /* End of code generation (main.h) */ 17 | -------------------------------------------------------------------------------- /C/runAllTS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | help() 4 | { 5 | echo "" 6 | echo "Usage: $0 -i indir -o outdir -a append_string -s" 7 | echo -e "\t-h Show this help message" 8 | echo -e "\t-i Path to a directory containing input time-series files (.txt with one time series value per line). Default: './timeSeries'" 9 | echo -e "\t-o Path to a directory in which to save output feature values. Default: './featureOutput'" 10 | echo -e "\t-a A string (minus extension) appended to the input file names to create the output file names. Default: 'output'" 11 | echo -e "\t-s A switch to evaluate catch22 (0) or catch24 (1). Default: 0" 12 | exit 1 13 | } 14 | 15 | while getopts "i:o:a:s:h" opt 16 | do 17 | case "$opt" in 18 | i) indir="$OPTARG" ;; 19 | o) outdir="$OPTARG" ;; 20 | a) append="$OPTARG" ;; 21 | s) catch24="$OPTARG" ;; 22 | h) help ;; 23 | esac 24 | done 25 | 26 | srcdir=$(dirname "$0}") 27 | 28 | if [ -z "$indir" ] 29 | then 30 | indir="./timeSeries" 31 | fi 32 | 33 | if [ -z "$outdir" ] 34 | then 35 | outdir="./featureOutput" 36 | fi 37 | 38 | if [ -z "$append" ] 39 | then 40 | append="output" 41 | fi 42 | 43 | if [ -z "$catch24" ] 44 | then 45 | catch24=0 46 | fi 47 | 48 | indir="$(dirname $indir)/$(basename $indir)" 49 | outdir="$(dirname $outdir)/$(basename $outdir)" 50 | mkdir -p $outdir 51 | 52 | # Loop through each file in indir and save the feature outputs 53 | for entry in "${indir}"/*.txt 54 | do 55 | filename=$(basename "$entry") 56 | extension="${filename##*.}" 57 | filename="${filename%.*}" 58 | fullfile="${outdir}/${filename}${append}.${extension}" 59 | if [ "${filename: -${#append}}" != "${append}" ] 60 | then 61 | yes $catch24 | "${srcdir}/run_features" $entry $fullfile > /dev/null 62 | 63 | if [ -s $fullfile ] # Remove file if catch22 errors 64 | then 65 | echo "Output written to ${fullfile}" 66 | else 67 | rm $fullfile 68 | fi 69 | 70 | fi 71 | done 72 | -------------------------------------------------------------------------------- /C/splinefit.h: -------------------------------------------------------------------------------- 1 | // 2 | // splinefit.h 3 | // C_polished 4 | // 5 | // Created by Carl Henning Lubba on 27/09/2018. 6 | // Copyright © 2018 Carl Henning Lubba. All rights reserved. 7 | // 8 | 9 | #ifndef splinefit_h 10 | #define splinefit_h 11 | 12 | #include 13 | 14 | extern int splinefit(const double *y, const int size, double *yOut); 15 | 16 | #endif /* splinefit_h */ 17 | -------------------------------------------------------------------------------- /C/stats.h: -------------------------------------------------------------------------------- 1 | #ifndef STATS_H 2 | #define STATS_H 3 | #include 4 | #include 5 | #include 6 | 7 | extern double max_(const double a[], const int size); 8 | extern double min_(const double a[], const int size); 9 | extern double mean(const double a[], const int size); 10 | extern double sum(const double a[], const int size); 11 | extern void cumsum(const double a[], const int size, double b[]); 12 | extern void icumsum(const int a[], const int size, int b[]); 13 | extern double isum(const int a[], const int size); 14 | extern double median(const double a[], const int size); 15 | extern double stddev(const double a[], const int size); 16 | extern double corr(const double x[], const double y[], const int size); 17 | extern double cov(const double x[], const double y[], const int size); 18 | extern double cov_mean(const double x[], const double y[], const int size); 19 | extern double autocorr_lag(const double x[], const int size, const int lag); 20 | extern double autocov_lag(const double x[], const int size, const int lag); 21 | extern void zscore_norm(double a[], int size); 22 | extern void zscore_norm2(const double a[], const int size, double b[]); 23 | extern double moment(const double a[], const int size, const int start, const int end, const int r); 24 | extern void diff(const double a[], const int size, double b[]); 25 | extern int linreg(const int n, const double x[], const double y[], double* m, double* b); //, double* r); 26 | extern double norm_(const double a[], const int size); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/BF_Binarize.m: -------------------------------------------------------------------------------- 1 | function yBin = BF_Binarize(y,binarizeHow) 2 | % BF_Binarize Converts an input vector into a binarized version 3 | 4 | % ------------------------------------------------------------------------------ 5 | % Copyright (C) 2017, Ben D. Fulcher , 6 | % 7 | % 8 | % If you use this code for your research, please cite the following two papers: 9 | % 10 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 11 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 12 | % DOI: 10.1016/j.cels.2017.10.001 13 | % 14 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 15 | % analysis: the empirical structure of time series and their methods", 16 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 17 | % DOI: 10.1098/rsif.2013.0048 18 | % 19 | % This function is free software: you can redistribute it and/or modify it under 20 | % the terms of the GNU General Public License as published by the Free Software 21 | % Foundation, either version 3 of the License, or (at your option) any later 22 | % version. 23 | % 24 | % This program is distributed in the hope that it will be useful, but WITHOUT 25 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 26 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 27 | % details. 28 | % 29 | % You should have received a copy of the GNU General Public License along with 30 | % this program. If not, see . 31 | % ------------------------------------------------------------------------------ 32 | 33 | %------------------------------------------------------------------------------- 34 | % Check inputs, set defaults: 35 | %------------------------------------------------------------------------------- 36 | if nargin < 2 || isempty(binarizeHow) 37 | binarizeHow = 'diff'; 38 | end 39 | 40 | %------------------------------------------------------------------------------- 41 | % function to transform real values to 0 if <=0 and 1 if >0: 42 | %------------------------------------------------------------------------------- 43 | 44 | function Y = stepBinary(X) 45 | 46 | Y = zeros(size(X),'like',X); 47 | Y(X > 0) = 1; 48 | 49 | end 50 | 51 | %------------------------------------------------------------------------------- 52 | % Do the binary transformation: 53 | %------------------------------------------------------------------------------- 54 | 55 | switch binarizeHow 56 | case 'diff' 57 | % Binary signal: 1 for stepwise increases, 0 for stepwise decreases 58 | yBin = stepBinary(diff(y)); 59 | 60 | case 'mean' 61 | % Binary signal: 1 for above mean, 0 for below mean 62 | yBin = stepBinary(y - mean(y)); 63 | 64 | case 'median' 65 | % Binary signal: 1 for above median, 0 for below median 66 | yBin = stepBinary(y - median(y)); 67 | 68 | case 'iqr' 69 | % Binary signal: 1 if inside interquartile range, 0 otherwise 70 | iqr = quantile(y,[0.25, 0.75]); 71 | iniqr = (y > iqr(1) & y <= iqr(2)); 72 | yBin = zeros(length(y),1); 73 | yBin(iniqr) = 1; 74 | 75 | otherwise 76 | error('Unknown binary transformation setting ''%s''',binarizeHow) 77 | end 78 | 79 | end 80 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/CO_AutoCorr.m: -------------------------------------------------------------------------------- 1 | function out = CO_AutoCorr(y,tau,whatMethod) 2 | % CO_AutoCorr Compute the autocorrelation of an input time series 3 | % 4 | %---INPUTS: 5 | % y, a scalar time series column vector. 6 | % 7 | % tau, the time-delay. If tau is a scalar, returns autocorrelation for y at that 8 | % lag. If tau is a vector, returns autocorrelations for y at that set of 9 | % lags. Can set tau empty, [], to return the full function for the 10 | % 'Fourier' estimation method. 11 | % 12 | % whatMethod, the method of computing the autocorrelation: 'Fourier', 13 | % 'TimeDomainStat', or 'TimeDomain'. 14 | % 15 | %---OUTPUT: the autocorrelation at the given time-lag. 16 | % 17 | %---NOTES: 18 | % Specifying whatMethod = 'TimeDomain' can tolerate NaN values in the time 19 | % series. 20 | % 21 | % Computing mean/std across the full time series makes a significant difference 22 | % for short time series, but can produce values outside [-1,+1]. The 23 | % filtering-based method used by Matlab's autocorr, is probably the best for 24 | % short time series, and is implemented here by specifying: whatMethod = 25 | % 'Fourier'. 26 | 27 | % ------------------------------------------------------------------------------ 28 | % Copyright (C) 2017, Ben D. Fulcher , 29 | % 30 | % 31 | % If you use this code for your research, please cite the following two papers: 32 | % 33 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 34 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 35 | % DOI: 10.1016/j.cels.2017.10.001 36 | % 37 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 38 | % analysis: the empirical structure of time series and their methods", 39 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 40 | % DOI: 10.1098/rsif.2013.0048 41 | % 42 | % This function is free software: you can redistribute it and/or modify it under 43 | % the terms of the GNU General Public License as published by the Free Software 44 | % Foundation, either version 3 of the License, or (at your option) any later 45 | % version. 46 | % 47 | % This program is distributed in the hope that it will be useful, but WITHOUT 48 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 49 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 50 | % details. 51 | % 52 | % You should have received a copy of the GNU General Public License along with 53 | % this program. If not, see . 54 | % ------------------------------------------------------------------------------ 55 | 56 | % ------------------------------------------------------------------------------ 57 | % Check inputs: 58 | % ------------------------------------------------------------------------------ 59 | if nargin < 2 60 | tau = 1; % Use a lag of 1 by default 61 | end 62 | 63 | if nargin < 3 || isempty(whatMethod) 64 | whatMethod = 'Fourier'; 65 | end 66 | 67 | % ------------------------------------------------------------------------------ 68 | % Evaluate the time-series autocorrelation 69 | % ------------------------------------------------------------------------------ 70 | 71 | switch whatMethod 72 | case 'Fourier' 73 | % ------------------------------------------------------------------------------ 74 | % Estimation based on Matlab function autocorr, based on method of: 75 | % [1] Box, G. E. P., G. M. Jenkins, and G. C. Reinsel. Time Series 76 | % Analysis: Forecasting and Control. 3rd edition. Upper Saddle River, 77 | % NJ: Prentice-Hall, 1994. 78 | 79 | nFFT = 2^(nextpow2(length(y))+1); 80 | F = fft(y-mean(y),nFFT); 81 | F = F.*conj(F); 82 | acf = ifft(F); 83 | acf = acf./acf(1); % Normalize 84 | acf = real(acf); 85 | 86 | acf = acf(1:length(y)); 87 | 88 | if isempty(tau) % return the full function 89 | out = acf; 90 | else % return a specific set of values 91 | out = zeros(length(tau),1); 92 | for i = 1:length(tau) 93 | if (tau(i) > length(acf)-1) || (tau(i) < 0) 94 | out(i) = NaN; 95 | else 96 | out(i) = acf(tau(i)+1); 97 | end 98 | end 99 | end 100 | 101 | 102 | 103 | end 104 | 105 | end 106 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/CO_FirstZero.m: -------------------------------------------------------------------------------- 1 | function out = CO_FirstZero(y,corrFun,maxTau) 2 | % CO_FirstZero The first zero-crossing of a given autocorrelation function 3 | % 4 | %---INPUTS: 5 | % 6 | % y, the input time series 7 | % corrFun, the self-correlation function to measure: 8 | % (i) 'ac': normal linear autocorrelation function. Uses CO_AutoCorr to 9 | % calculate autocorrelations. 10 | % maxTau, a maximum time-delay to search up to. 11 | % 12 | % In future, could add an option to return the point at which the function 13 | % crosses the axis, rather than the first integer lag at which it has already 14 | % crossed (what is currently implemented). 15 | 16 | % ------------------------------------------------------------------------------ 17 | % Copyright (C) 2017, Ben D. Fulcher , 18 | % 19 | % 20 | % If you use this code for your research, please cite the following two papers: 21 | % 22 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 23 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 24 | % DOI: 10.1016/j.cels.2017.10.001 25 | % 26 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 27 | % analysis: the empirical structure of time series and their methods", 28 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 29 | % DOI: 10.1098/rsif.2013.0048 30 | % 31 | % This function is free software: you can redistribute it and/or modify it under 32 | % the terms of the GNU General Public License as published by the Free Software 33 | % Foundation, either version 3 of the License, or (at your option) any later 34 | % version. 35 | % 36 | % This program is distributed in the hope that it will be useful, but WITHOUT 37 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 38 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 39 | % details. 40 | % 41 | % You should have received a copy of the GNU General Public License along with 42 | % this program. If not, see . 43 | % ------------------------------------------------------------------------------ 44 | 45 | % ------------------------------------------------------------------------------ 46 | % Check inputs: 47 | % ------------------------------------------------------------------------------ 48 | 49 | N = length(y); % the length of the time series 50 | 51 | if nargin < 2 || isempty(corrFun) 52 | corrFun = 'ac'; % autocorrelation by default 53 | end 54 | if nargin < 3 || isempty(maxTau) 55 | maxTau = N; % search up to a maximum of the length of the time series 56 | % maxTau = 400; % searches up to this maximum time lag 57 | % maxTau = min(maxTau,N); % searched up to the length of the time series if this is less than maxTau 58 | end 59 | 60 | % ------------------------------------------------------------------------------ 61 | % Select the self-correlation function as an inline function 62 | % Eventually could add additional self-correlation functions 63 | switch corrFun 64 | case 'ac' 65 | % Autocorrelation at all time lags 66 | corrs = CO_AutoCorr(y,[],'Fourier'); 67 | corrs = corrs(2:end); % remove the zero-lag result 68 | otherwise 69 | error('Unknown correlation function ''%s''',corrFun); 70 | end 71 | 72 | % Calculate autocorrelation at increasing lags, until you find a negative one 73 | for tau = 1:maxTau-1 74 | if corrs(tau) < 0 % we know it starts positive (1), so first negative will be the zero-crossing 75 | out = tau; return 76 | end 77 | end 78 | 79 | % If haven't left yet, set output to maxTau 80 | out = maxTau; 81 | 82 | % make sure this is a scalar output 83 | coder.varsize('out', [1, 1], [0 0]) 84 | 85 | end 86 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/CO_trev.m: -------------------------------------------------------------------------------- 1 | function out = CO_trev(y, tau) 2 | % CO_trev Normalized nonlinear autocorrelation, trev function of a time series 3 | % 4 | % Calculates the trev function, a normalized nonlinear autocorrelation, 5 | % mentioned in the documentation of the TSTOOL nonlinear time-series analysis 6 | % package (available here: http://www.physik3.gwdg.de/tstool/). 7 | % 8 | % The quantity is often used as a nonlinearity statistic in surrogate data 9 | % analysis, cf. "Surrogate time series", T. Schreiber and A. Schmitz, Physica D, 10 | % 142(3-4) 346 (2000). 11 | % 12 | %---INPUTS: 13 | % 14 | % y, time series 15 | % 16 | % tau, time lag (can be 'ac' or 'mi' to set as the first zero-crossing of the 17 | % autocorrelation function, or the first minimum of the automutual 18 | % information function, respectively) 19 | % 20 | %---OUTPUTS: 21 | % the trev numerator and the denominator. 22 | 23 | % ------------------------------------------------------------------------------ 24 | % Copyright (C) 2017, Ben D. Fulcher , 25 | % 26 | % 27 | % If you use this code for your research, please cite the following two papers: 28 | % 29 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 30 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 31 | % DOI: 10.1016/j.cels.2017.10.001 32 | % 33 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 34 | % analysis: the empirical structure of time series and their methods", 35 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 36 | % DOI: 10.1098/rsif.2013.0048 37 | % 38 | % This function is free software: you can redistribute it and/or modify it under 39 | % the terms of the GNU General Public License as published by the Free Software 40 | % Foundation, either version 3 of the License, or (at your option) any later 41 | % version. 42 | % 43 | % This program is distributed in the hope that it will be useful, but WITHOUT 44 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 45 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 46 | % details. 47 | % 48 | % You should have received a copy of the GNU General Public License along with 49 | % this program. If not, see . 50 | % ------------------------------------------------------------------------------ 51 | 52 | % ------------------------------------------------------------------------------ 53 | %% Set defaults: 54 | % ------------------------------------------------------------------------------ 55 | if nargin < 2 || isempty(tau) 56 | tau = 1; 57 | end 58 | 59 | % ------------------------------------------------------------------------------ 60 | % Compute trev quantities 61 | % ------------------------------------------------------------------------------ 62 | 63 | yn = y(1:end-tau); 64 | yn1 = y(1+tau:end); % yn, tau steps ahead 65 | 66 | % ------------------------------------------------------------------------------ 67 | % Fill output struct 68 | % ------------------------------------------------------------------------------ 69 | 70 | % % The numerator 71 | out.num = mean((yn1-yn).^3); 72 | 73 | % The denominator 74 | out.denom = (mean((yn1-yn).^2))^(3/2); 75 | 76 | end 77 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/DN_HistogramMode.m: -------------------------------------------------------------------------------- 1 | function out = DN_HistogramMode(y,numBins) 2 | % DN_HistogramMode Mode of a data vector. 3 | % 4 | % Measures the mode of the data vector using histograms with a given number 5 | % of bins. 6 | % 7 | %---INPUTS: 8 | % 9 | % y, the input data vector 10 | % 11 | % numBins, the number of bins to use in the histogram. 12 | 13 | % ------------------------------------------------------------------------------ 14 | % Copyright (C) 2017, Ben D. Fulcher , 15 | % 16 | % 17 | % If you use this code for your research, please cite the following two papers: 18 | % 19 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 20 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 21 | % DOI: 10.1016/j.cels.2017.10.001 22 | % 23 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 24 | % analysis: the empirical structure of time series and their methods", 25 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 26 | % DOI: 10.1098/rsif.2013.0048 27 | % 28 | % This function is free software: you can redistribute it and/or modify it under 29 | % the terms of the GNU General Public License as published by the Free Software 30 | % Foundation, either version 3 of the License, or (at your option) any later 31 | % version. 32 | % 33 | % This program is distributed in the hope that it will be useful, but WITHOUT 34 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 35 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 36 | % details. 37 | % 38 | % You should have received a copy of the GNU General Public License along with 39 | % this program. If not, see . 40 | % ------------------------------------------------------------------------------ 41 | 42 | if nargin < 2 43 | numBins = 'auto'; % ceil(sqrt(length(y))); 44 | end 45 | 46 | % Compute the histogram from the data: 47 | [N,binEdges] = histcounts_(y,numBins); 48 | 49 | % Compute bin centers from bin edges: 50 | binCenters = mean([binEdges(1:end-1); binEdges(2:end)]); 51 | 52 | % Mean position of maximums (if multiple): 53 | out = mean(binCenters(N == max(N))); 54 | 55 | end 56 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/NK_hist2.m: -------------------------------------------------------------------------------- 1 | function [MN, xedges, yedges] = NK_hist2(x, y, xedges, yedges) 2 | % function MN = NK_hist2(x, y, xedges, yedges) 3 | % 4 | % 2D histogram: Extract the number of joint events - (x,y) data value pairs 5 | % that fall in each bin of the grid defined by xedges and yedges. 6 | % 7 | % ==================================================================== 8 | % Uses: 9 | % [N,BIN] = histc(X,EDGES) 10 | % which returns 11 | % 1) N is a LENGTH(EDGES) vector, N(k) will count the value X(i) if EDGES(k) <= X(i) < EDGES(k+1). The 12 | % last bin will count any values of X that match EDGES(end). 13 | % 2) an index matrix BIN. 14 | % If X is a vector, N(K) = SUM(BIN==K). 15 | % BIN is zero for out of range values. 16 | % If X is an m-by-n matrix, then, for j=1:n, N(K,j) = SUM(BIN(:,j)==K); end 17 | % ==================================================================== 18 | % 19 | % Please, see the notes to histc too. 20 | % N.B. It is always a better idea to use the 21 | % HISTC mex (a much faster compiled C code) if you have it 22 | % Then just replace the histc with HISTC in all calls 23 | % contained in the NK_hist2() .m function 24 | % 25 | % (c) Nedialko Krouchev 2006, Universite de Montreal, GRSNC 26 | 27 | if nargin ~= 4 28 | error('The four input arguments are required!'); 29 | end 30 | if any(size(x) ~= size(y)) 31 | error('The size of the two first input vectors should be same!'); 32 | end 33 | 34 | [xn, xbin] = histc(x,xedges); 35 | [yn, ybin] = histc(y,yedges); 36 | 37 | xnbin = length(xedges); 38 | ynbin = length(yedges); 39 | 40 | %% xbin, ybin are zero for out of range values 41 | kkL = find( xxedges(xnbin) ); 49 | if ~isempty( kkR ) 50 | xnbin = xnbin + 1; xedges(xnbin) = max(x); 51 | end 52 | xbin( kkR ) = xnbin; 53 | 54 | kkL = find( yyedges(ynbin) ); 61 | if ~isempty( kkR ) 62 | ynbin = ynbin + 1; 63 | yedges(ynbin) = max(y); 64 | end 65 | ybin( kkR ) = ynbin; 66 | 67 | xyBinEdges = 1:xnbin*ynbin; 68 | 69 | % ==================================================================== 70 | % A more Elegant end-spiel: 71 | % 72 | % If x belongs to jBin=xbin(x), and y belongs to iBin=ybin(y), 73 | % Then (x,y) pairs belong "columnwise" to: 74 | % ijBin = (jBin-1)*ynbin + iBin 75 | 76 | xyBin = (xbin-1)*ynbin + ybin; 77 | 78 | 79 | % ==================================================================== 80 | 81 | MN = histc(xyBin, xyBinEdges); 82 | MN = reshape(MN, ynbin, xnbin); 83 | end -------------------------------------------------------------------------------- /Matlab/BasisOperations/SB_CoarseGrain_quantile.m: -------------------------------------------------------------------------------- 1 | function yth = SB_CoarseGrain_quantile(y,numGroups) 2 | % SB_CoarseGrain Coarse-grains a continuous time series to a discrete alphabet. 3 | % 4 | %---INPUTS: 5 | % howtocg = 'quantile' puts an equal number into each bin, the method of coarse-graining 6 | % 7 | % numGroups, either specifies the size of the alphabet for 'quantile' and 'updown' 8 | % or sets the timedelay for the embedding subroutines 9 | 10 | % ------------------------------------------------------------------------------ 11 | % Copyright (C) 2017, Ben D. Fulcher , 12 | % 13 | % 14 | % If you use this code for your research, please cite the following two papers: 15 | % 16 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 17 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 18 | % DOI: 10.1016/j.cels.2017.10.001 19 | % 20 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 21 | % analysis: the empirical structure of time series and their methods", 22 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 23 | % DOI: 10.1098/rsif.2013.0048 24 | % 25 | % This function is free software: you can redistribute it and/or modify it under 26 | % the terms of the GNU General Public License as published by the Free Software 27 | % Foundation, either version 3 of the License, or (at your option) any later 28 | % version. 29 | % 30 | % This program is distributed in the hope that it will be useful, but WITHOUT 31 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 32 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 33 | % details. 34 | % 35 | % You should have received a copy of the GNU General Public License along with 36 | % this program. If not, see . 37 | % ------------------------------------------------------------------------------ 38 | 39 | N = length(y); % length of the input sequence 40 | 41 | % ------------------------------------------------------------------------------ 42 | % Do the coarse graining 43 | % ------------------------------------------------------------------------------ 44 | 45 | % quantile 46 | th = quantile(y,linspace(0,1,numGroups+1)); % thresholds for dividing the time series values 47 | th(1) = th(1)-1; % this ensures the first point is included 48 | % turn the time series into a set of numbers from 1:numGroups 49 | yth = zeros(N,1); 50 | for i = 1:numGroups 51 | yth(y > th(i) & y <= th(i+1)) = i; 52 | end 53 | 54 | if any(yth == 0) 55 | error('All values in the sequence were not assigned to a group') 56 | end 57 | 58 | end 59 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/buffer_.m: -------------------------------------------------------------------------------- 1 | function y_buff = buffer_(y, tau) 2 | 3 | % replacement for y_buff = buffer(y,tau) 4 | 5 | nCols = ceil(length(y)/tau); 6 | yPadded = zeros(nCols*tau,1); 7 | yPadded(1:length(y)) = y; 8 | y_buff = reshape(yPadded, tau, nCols); -------------------------------------------------------------------------------- /Matlab/BasisOperations/decimate_.m: -------------------------------------------------------------------------------- 1 | function out = decimate_(y, q) 2 | 3 | nfilt = 4; 4 | 5 | nd = length(y); 6 | 7 | [b,a] = myButter(nfilt, 0.8/q); 8 | 9 | % be sure to filter in both directions to make sure the filtered data has zero phase 10 | % make a data vector properly pre- and ap- pended to filter forwards and back 11 | % so end effects can be obliterated. 12 | out_filt = filtfilt_(b,a,y); 13 | nbeg = 1; 14 | out = out_filt((nbeg:q:nd)'); 15 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/downsample_.m: -------------------------------------------------------------------------------- 1 | %------------------------------------------------------------------------- 2 | function [y, h] = downsample_( x, q ) 3 | 4 | p = 1; 5 | bta = 5; 6 | N = 10; 7 | 8 | if (p==1) && (q==1) 9 | y = x; 10 | h = 1; 11 | return 12 | end 13 | pqmax = max(p,q); 14 | if length(N)>1 % use input filter 15 | L = length(N); 16 | h = N; 17 | else % design filter 18 | if( N>0 ) 19 | fc = 1/2/pqmax; 20 | L = 2*N*pqmax + 1; 21 | h = firls( L-1, [0 2*fc 2*fc 1], [1 1 0 0]).*kaiser(L,bta)' ; 22 | h = p*h/sum(h); 23 | else 24 | L = p; 25 | h = ones(1,p); 26 | end 27 | end 28 | 29 | Lhalf = (L-1)/2; 30 | isvect = any(size(x)==1); 31 | if isvect 32 | Lx = length(x); 33 | else 34 | Lx = size(x, 1); 35 | end 36 | 37 | % Need to delay output so that downsampling by q hits center tap of filter. 38 | nz = floor(q-mod(Lhalf,q)); 39 | z = zeros(1,nz); 40 | h = [z h(:).']; % ensure that h is a row vector. 41 | Lhalf = Lhalf + nz; 42 | 43 | % Number of samples removed from beginning of output sequence 44 | % to compensate for delay of linear phase filter: 45 | delay = floor(ceil(Lhalf)/q); 46 | 47 | % Need to zero-pad so output length is exactly ceil(Lx*p/q). 48 | nz1 = 0; 49 | while ceil( ((Lx-1)*p+length(h)+nz1 )/q ) - delay < ceil(Lx*p/q) 50 | nz1 = nz1+1; 51 | end 52 | h = [h zeros(1,nz1)]; 53 | 54 | % ---- HERE'S THE CALL TO UPFIRDN ---------------------------- 55 | y = upfirdn(x,h,p,q); 56 | 57 | % Get rid of trailing and leading data so input and output signals line up 58 | % temporally: 59 | Ly = ceil(Lx*p/q); % output length 60 | % Ly = floor((Lx-1)*p/q+1); <-- alternately, to prevent "running-off" the 61 | % data (extrapolation) 62 | if isvect 63 | y(1:delay) = []; 64 | y(Ly+1:end) = []; 65 | else 66 | y(1:delay,:) = []; 67 | y(Ly+1:end,:) = []; 68 | end 69 | 70 | h([1:nz (end-nz1+1):end]) = []; % get rid of leading and trailing zeros 71 | % in case filter is output -------------------------------------------------------------------------------- /Matlab/BasisOperations/filtfilt_.m: -------------------------------------------------------------------------------- 1 | function y = filtfilt_(b,a,x) 2 | %FILTFILT Zero-phase forward and reverse digital IIR filtering. 3 | % Y = FILTFILT(B, A, X) filters the data in vector X with the filter 4 | % described by vectors A and B to create the filtered data Y. The filter 5 | % is described by the difference equation: 6 | % 7 | % a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) 8 | % - a(2)*y(n-1) - ... - a(na+1)*y(n-na) 9 | % 10 | % The length of the input X must be more than three times the filter 11 | % order, defined as max(length(B)-1,length(A)-1). 12 | % 13 | % References: 14 | % [1] Sanjit K. Mitra, Digital Signal Processing, 2nd ed., 15 | % McGraw-Hill, 2001 16 | % [2] Fredrik Gustafsson, Determining the initial states in forward- 17 | % backward filtering, IEEE Transactions on Signal Processing, 18 | % pp. 988-992, April 1996, Volume 44, Issue 4 19 | 20 | % Copyright 1988-2014 The MathWorks, Inc. 21 | 22 | 23 | %% Parse coefficient coefficients vectors and determine initial conditions 24 | 25 | na = numel(a); 26 | 27 | L = 1; 28 | % Check coefficients 29 | b = b(:); 30 | a = a(:); 31 | nb = numel(b); 32 | nfilt = max(nb,na); 33 | nfact = max(1,3*(nfilt-1)); % length of edge transients 34 | 35 | % Zero pad shorter coefficient vector as needed 36 | if nb < nfilt 37 | b(nfilt,1)=0; 38 | elseif na < nfilt 39 | a(nfilt,1)=0; 40 | end 41 | 42 | % Compute initial conditions to remove DC offset 43 | if nfilt>1 44 | zi = ( eye(nfilt-1) - [-a(2:nfilt), [eye(nfilt-2); ... 45 | zeros(1,nfilt-2)]] ) \ ... 46 | ( b(2:nfilt) - b(1)*a(2:nfilt) ); 47 | else 48 | zi = zeros(0,1); 49 | end 50 | 51 | %% Filter the data 52 | for ii=1:L 53 | 54 | y = [2*x(1)-x(nfact+1:-1:2); x; 2*x(end)-x(end-1:-1:end-nfact)]; 55 | 56 | % filter, reverse data, filter again, and reverse data again 57 | y = filter(b(:,ii),a(:,ii),y,zi(:,ii)*y(1)); 58 | y = y(end:-1:1); 59 | y = filter(b(:,ii),a(:,ii),y,zi(:,ii)*y(1)); 60 | 61 | % retain reversed central section of y 62 | y = y(end-nfact:-1:nfact+1); 63 | end 64 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/histcounts_.m: -------------------------------------------------------------------------------- 1 | function [N, binEdges] = histcounts_(d, nBinsIn, normalise) 2 | % own function for counting 3 | 4 | if nargin<2 || isempty(nBinsIn) 5 | nBinsIn = []; 6 | end 7 | 8 | if nargin<3 || isempty(normalise) 9 | normalise = false; 10 | end 11 | 12 | 13 | dMinMax = [min(d), max(d)]; 14 | dRange = dMinMax(2) - dMinMax(1); 15 | 16 | % fixed or automatic number of bins 17 | if isempty(nBinsIn) 18 | nBins = ceil(dRange/(3.5*std(d)/(numel(d)^(1/3)))); 19 | else 20 | nBins = nBinsIn; 21 | end 22 | 23 | % compute edges 24 | binWidth = dRange/nBins; 25 | binEdges = dMinMax(1) + (0:nBins)*binWidth; 26 | 27 | % count occurences in bins 28 | N = zeros(nBins, 1); 29 | d_ = d - dMinMax(1); 30 | for i = 1:length(d_) 31 | binInd = floor(d_(i)/binWidth)+1; 32 | binInd = max(1, binInd); 33 | binInd = min(nBins, binInd); 34 | N(binInd) = N(binInd) + 1; 35 | end 36 | 37 | % probability normalisation 38 | if normalise 39 | N = N./numel(d); 40 | end -------------------------------------------------------------------------------- /Matlab/BasisOperations/myButter.m: -------------------------------------------------------------------------------- 1 | function [Z_out, P_out] = myButter(n, W) 2 | % Digital Butterworth filter, either 2 or 3 outputs 3 | % Jan Simon, 2014, BSD licence 4 | % See docs of BUTTER for input and output 5 | % Fast hack with limited accuracy: Handle with care! 6 | % Until n=15 the relative difference to Matlab's BUTTER is < 100*eps 7 | V = tan(W * 1.5707963267948966); 8 | Q = exp((1.5707963267948966i / n) * ((2 + n - 1):2:(3 * n - 1))); 9 | nQ = length(Q); 10 | 11 | Sg = V ^ nQ; 12 | Sp = V * Q; 13 | Sz = []; 14 | 15 | % Bilinear transform: 16 | P = (1 + Sp) ./ (1 - Sp); 17 | Z = repmat(-1, size(P)); 18 | if isempty(Sz) 19 | G = real(Sg / prod(1 - Sp)); 20 | else 21 | G = real(Sg * prod(1 - Sz) / prod(1 - Sp)); 22 | Z(1:length(Sz)) = (1 + Sz) ./ (1 - Sz); 23 | end 24 | 25 | % From Zeros, Poles and Gain to B (numerator) and A (denominator): 26 | Z_out = G * real(poly(Z')); 27 | P_out = real(poly(P)); 28 | -------------------------------------------------------------------------------- /Matlab/BasisOperations/poly_.m: -------------------------------------------------------------------------------- 1 | function c = poly_(x) 2 | %POLY Convert roots to polynomial. 3 | % POLY(A), when A is an N by N matrix, is a row vector with 4 | % N+1 elements which are the coefficients of the 5 | % characteristic polynomial, det(lambda*eye(size(A)) - A). 6 | % 7 | % POLY(V), when V is a vector, is a vector whose elements are 8 | % the coefficients of the polynomial whose roots are the 9 | % elements of V. For vectors, ROOTS and POLY are inverse 10 | % functions of each other, up to ordering, scaling, and 11 | % roundoff error. 12 | % 13 | % Examples: 14 | % 15 | % roots(poly(1:20)) generates Wilkinson's famous example. 16 | % 17 | % Class support for inputs A,V: 18 | % float: double, single 19 | % 20 | % See also ROOTS, CONV, RESIDUE, POLYVAL. 21 | 22 | % Copyright 1984-2014 The MathWorks, Inc. 23 | 24 | [m,n] = size(x); 25 | if m == n 26 | % Characteristic polynomial (square x) 27 | e = eig(x); 28 | elseif (m==1) || (n==1) 29 | e = x; 30 | else 31 | error(message('MATLAB:poly:InputSize')) 32 | end 33 | 34 | % Strip out infinities 35 | e = e( isfinite(e) ); 36 | 37 | % Expand recursion formula 38 | n = length(e); 39 | c = [1 zeros(1,n,class(x))]; 40 | for j=1:n 41 | j 42 | c(2:(j+1)) 43 | e(j) 44 | c(1:j) 45 | e(j).*c(1:j) 46 | 47 | c(2:(j+1)) = c(2:(j+1)) - e(j).*c(1:j); 48 | end 49 | 50 | % The result should be real if the roots are complex conjugates. 51 | if isequal(sort(e(imag(e)>0)),sort(conj(e(imag(e)<0)))) 52 | c = real(c); 53 | end -------------------------------------------------------------------------------- /Matlab/BasisOperations/test_zp2ss.m: -------------------------------------------------------------------------------- 1 | function out = test_zp2ss(z,p,k) 2 | 3 | out = zp2ss(z,p,k); -------------------------------------------------------------------------------- /Matlab/BasisOperations/testfilt.m: -------------------------------------------------------------------------------- 1 | % testFilter 2 | 3 | fileID = fopen('/Users/carl/PycharmProjects/catch22/C/timeSeries/tsid0133.txt','r'); 4 | tsData = fscanf(fileID,'%f'); 5 | fclose(fileID); 6 | 7 | [b, a] = myButter(4, 0.8/24); 8 | 9 | tsDatafilt = filter(b,a,tsData) -------------------------------------------------------------------------------- /Matlab/BasisOperations/welchy.m: -------------------------------------------------------------------------------- 1 | function [Pxx, F] = calc_psd(X, NFFT, Fs, WINDOW) 2 | % Calculate Power Spectral Density 3 | % [Pxx ,F]= PSD(X, NFFT, Fs, WINDOW) estimates the Power Spectral Density of 4 | % signal vector X using Welch's averaged periodogram method. X is 5 | % divided into sections, then windowed by the WINDOW parameter 6 | % The magnitude squared of the length NFFT DFTs of the sections are 7 | % averaged to form Pxx. Pxx is length NFFT/2+1 for NFFT even. the default fot WINDOW is a rectangular window . 8 | % Fs is the sampling frequency which is used for scaling of plots. 9 | % 10 | % Author(s): T. Krauss, 3-26-93 11 | % Copyright (c) 1984-94 by The MathWorks, Inc. 12 | % Revision: Roni P, 10.8.01 13 | % EU, dt used in computations 14 | % EU, df used to get frequency scale 15 | % X - The signal we want to estimate the psd for. 16 | % NFFT - number of data points of each window 17 | % Fs - Sampling frequency 18 | % Window - The type of window to use 19 | % Example of use: 20 | % dt = 0.01; 21 | % f = 10; % Frequency to find 22 | % t = 0:dt:10; % Create time vector 23 | % x = sin(2*pi*f*t); % create a signal 24 | % nfft = 64; % Window should be less than 256. 25 | % Fs = 1/dt; % Sampling frequency 26 | % window = hanning(nfft); % Use hanning as window 27 | % [Pxx, F] = calc_psd(x, nfft, Fs, window); 28 | % plot(F,Pxx); xlabel('Frequency [Hz]'); ylabel('Amplitude'); 29 | 30 | if (nargin <= 2) 31 | error('Not enough input parameters, exiting...'); 32 | end 33 | 34 | % % make sure the windows width is a power of 2 35 | % NFFT = 2^(nextpow2(NFFT)-1); % this stinks. 36 | 37 | windowWidth = numel(WINDOW);%2^(nextpow2(numel(WINDOW))-1); % 38 | 39 | dt = 1/Fs; 40 | df = 1/(2^(nextpow2(numel(WINDOW))))/dt; 41 | if (nargin == 3) 42 | w = ones(windowWidth, 1); 43 | end 44 | if (nargin == 4) 45 | w = WINDOW; 46 | w = w(:); % Make sure w is a column vector 47 | end 48 | 49 | X = X(:); % Make sure X is a column vector 50 | k = floor(numel(X)/(windowWidth/2))-1; % Number of windows 51 | index = 1:windowWidth; 52 | KMU = k*norm(w)^2; % Normalizing scale factor 53 | w = w(:); 54 | P = zeros(NFFT, 1); 55 | 56 | for i = 1:k 57 | xw = w.*X(index); 58 | index = index + windowWidth/2; % Continue to next window 59 | P = P + abs(fft(xw, NFFT)).^2; 60 | end 61 | 62 | Pxx = dt*(P(1:NFFT/2+1))/KMU; 63 | % strange correction here, don't know why it's neccesary!! 64 | Pxx(2:end-1) = Pxx(2:end-1)*2; 65 | 66 | n = max(size(Pxx)); 67 | F = (0:n-1)'*df; -------------------------------------------------------------------------------- /Matlab/CO_Embed2_Dist_tau_d_expfit_meandiff.m: -------------------------------------------------------------------------------- 1 | function out = CO_Embed2_Dist_tau_d_expfit_meandiff(y) 2 | % CO_Embed2_Dist Analyzes distances in a 2-d embedding space of a time series. 3 | % 4 | % Returns statistics on the sequence of successive Euclidean distances between 5 | % points in a two-dimensional time-delay embedding space with a given 6 | % time-delay, tau. 7 | % 8 | % Outputs the the mean distance, the 9 | % spread of distances, and statistics from an exponential fit to the 10 | % distribution of distances. 11 | % 12 | %---INPUTS: 13 | % y, a z-scored column vector representing the input time series. 14 | % tau, the time delay. 15 | 16 | % ------------------------------------------------------------------------------ 17 | % Copyright (C) 2017, Ben D. Fulcher , 18 | % 19 | % 20 | % If you use this code for your research, please cite the following two papers: 21 | % 22 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 23 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 24 | % DOI: 10.1016/j.cels.2017.10.001 25 | % 26 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 27 | % analysis: the empirical structure of time series and their methods", 28 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 29 | % DOI: 10.1098/rsif.2013.0048 30 | % 31 | % This function is free software: you can redistribute it and/or modify it under 32 | % the terms of the GNU General Public License as published by the Free Software 33 | % Foundation, either version 3 of the License, or (at your option) any later 34 | % version. 35 | % 36 | % This program is distributed in the hope that it will be useful, but WITHOUT 37 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 38 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 39 | % details. 40 | % 41 | % You should have received a copy of the GNU General Public License along with 42 | % this program. If not, see . 43 | % ------------------------------------------------------------------------------ 44 | 45 | % no combination of single functions 46 | coder.inline('never'); 47 | 48 | % ------------------------------------------------------------------------------ 49 | %% Check inputs: 50 | % ------------------------------------------------------------------------------ 51 | 52 | N = length(y); % time-series length 53 | 54 | tau = CO_FirstZero(y,'ac'); 55 | if tau > N/10 56 | tau = floor(N/10); 57 | end 58 | 59 | % ------------------------------------------------------------------------------ 60 | % 2-dimensional time-delay embedding: 61 | % ------------------------------------------------------------------------------ 62 | 63 | m = [y(1:end-tau), y(1+tau:end)]; 64 | 65 | % ------------------------------------------------------------------------------ 66 | % Calculate Euclidean distances between successive points in this space, d: 67 | % ------------------------------------------------------------------------------ 68 | 69 | d = sqrt(diff(m(:,1)).^2 + diff(m(:,2)).^2); % Euclidean distance 70 | 71 | % % ------------------------------------------------------------------------------ 72 | % % Empirical distance distribution often fits Exponential distribution quite well 73 | % % Fit to all values (often some extreme outliers, but oh well) 74 | % l = expfit(d); 75 | l = mean(d); % maybe this is stupid, but I seriously don't see the difference 76 | 77 | %% Sum of abs differences between exp fit and observed: 78 | 79 | [N, binEdges] = histcounts_(d, [], true); 80 | 81 | % from edges to centers 82 | binCentres = mean([binEdges(1:end-1); binEdges(2:end)])'; 83 | 84 | % exponential fit in each bin 85 | z = binCentres ./ l; 86 | expf = exp(-z) ./ l; 87 | expf(expf<0) = 0; 88 | 89 | d_expfit_meandiff = mean(abs(N - expf)); % mean absolute error of fit 90 | 91 | out = d_expfit_meandiff; 92 | 93 | end 94 | -------------------------------------------------------------------------------- /Matlab/CO_FirstMin_ac.m: -------------------------------------------------------------------------------- 1 | function out = CO_FirstMin_ac(y) 2 | % CO_FirstMin Time of first minimum in a given correlation function 3 | % 4 | %---INPUTS: 5 | % y, the input time series 6 | % 7 | % Note that selecting 'ac' is unusual operation: standard operations are the 8 | % first zero-crossing of the autocorrelation (as in CO_FirstZero), or the first 9 | % minimum of the mutual information function ('mi'). 10 | 11 | % ------------------------------------------------------------------------------ 12 | % Copyright (C) 2017, Ben D. Fulcher , 13 | % 14 | % 15 | % If you use this code for your research, please cite the following two papers: 16 | % 17 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 18 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 19 | % DOI: 10.1016/j.cels.2017.10.001 20 | % 21 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 22 | % analysis: the empirical structure of time series and their methods", 23 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 24 | % DOI: 10.1098/rsif.2013.0048 25 | % 26 | % This function is free software: you can redistribute it and/or modify it under 27 | % the terms of the GNU General Public License as published by the Free Software 28 | % Foundation, either version 3 of the License, or (at your option) any later 29 | % version. 30 | % 31 | % This program is distributed in the hope that it will be useful, but WITHOUT 32 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 33 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 34 | % details. 35 | % 36 | % You should have received a copy of the GNU General Public License along with 37 | % this program. If not, see . 38 | % ------------------------------------------------------------------------------ 39 | 40 | % no combination of single functions 41 | coder.inline('never'); 42 | 43 | N = length(y); % Time-series length 44 | 45 | % ------------------------------------------------------------------------------ 46 | % Define the autocorrelation function 47 | % ------------------------------------------------------------------------------ 48 | 49 | % Autocorrelation implemented as CO_AutoCorr 50 | corrfn = @(x) CO_AutoCorr(y,x,'Fourier'); 51 | 52 | % ------------------------------------------------------------------------------ 53 | % Search for a minimum 54 | % ------------------------------------------------------------------------------ 55 | % (Incrementally through time lags until a minimum is found) 56 | 57 | autoCorr = zeros(N-1,1); % preallocate autocorrelation vector 58 | for i = 1:N-1 59 | % Calculate the auto-correlation at this lag: 60 | autoCorr(i) = corrfn(i); 61 | 62 | % Hit a NaN before got to a minimum -- there is no minimum 63 | if isnan(autoCorr(i)) 64 | % warning('No minimum in %s [[time series too short to find it?]]',minWhat) 65 | out = NaN; return 66 | end 67 | 68 | % We're at a minimum: 69 | if i==2 && (autoCorr(2) > autoCorr(1)) 70 | % already increases at lag of 2 from lag of 1: a minimum (since ac(0) is maximal) 71 | out = 1; 72 | return 73 | elseif (i > 2) && (autoCorr(i-2) > autoCorr(i-1)) && (autoCorr(i-1) < autoCorr(i)) % minimum at previous i 74 | out = i-1; % I found the first minimum! 75 | return 76 | end 77 | end 78 | 79 | % Still decreasing -- no minimum was found after searching all across the time series: 80 | out = N; 81 | 82 | end 83 | -------------------------------------------------------------------------------- /Matlab/CO_HistogramAMI_even_2_5.m: -------------------------------------------------------------------------------- 1 | function out = CO_HistogramAMI_even_2_5(y) 2 | % CO_HistogramAMI The automutual information of the distribution using histograms. 3 | % 4 | % The approach used to bin the data is provided. 5 | % 6 | %---INPUTS: 7 | % 8 | % y, the input time series 9 | % 10 | % tau, 2: the time-lag 11 | % 12 | % meth, 'even': evenly-spaced bins through the range of the time series, 13 | % 14 | % numBins, 5: the number of bins 15 | % 16 | %---OUTPUT: the automutual information calculated in this way. 17 | 18 | % Uses the hist2 function (renamed NK_hist2.m here) by Nedialko Krouchev, obtained 19 | % from Matlab Central, 20 | % http://www.mathworks.com/matlabcentral/fileexchange/12346-hist2-for-the-people 21 | % [[hist2 for the people by Nedialko Krouchev, 20 Sep 2006 (Updated 21 Sep 2006)]] 22 | 23 | % ------------------------------------------------------------------------------ 24 | % Copyright (C) 2017, Ben D. Fulcher , 25 | % 26 | % 27 | % If you use this code for your research, please cite the following two papers: 28 | % 29 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 30 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 31 | % DOI: 10.1016/j.cels.2017.10.001 32 | % 33 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 34 | % analysis: the empirical structure of time series and their methods", 35 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 36 | % DOI: 10.1098/rsif.2013.0048 37 | % 38 | % This function is free software: you can redistribute it and/or modify it under 39 | % the terms of the GNU General Public License as published by the Free Software 40 | % Foundation, either version 3 of the License, or (at your option) any later 41 | % version. 42 | % 43 | % This program is distributed in the hope that it will be useful, but WITHOUT 44 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 45 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 46 | % details. 47 | % 48 | % You should have received a copy of the GNU General Public License along with 49 | % this program. If not, see . 50 | % ------------------------------------------------------------------------------ 51 | 52 | % no combination of single functions 53 | coder.inline('never'); 54 | 55 | % ------------------------------------------------------------------------------ 56 | %% Check Inputs: 57 | % ------------------------------------------------------------------------------ 58 | 59 | % Number of options: 60 | % remove outliers first?, number of bins, range of bins, bin sizes 61 | 62 | tau = 2; 63 | % meth = 'even'; 64 | numBins = 5; 65 | 66 | % ------------------------------------------------------------------------------ 67 | %% Bins by standard deviation (=1) 68 | % ------------------------------------------------------------------------------ 69 | 70 | % even 71 | b = linspace(min(y)-0.1,max(y)+0.1,numBins+1); % +0.1 to make sure all points included 72 | 73 | nb = length(b) - 1; % number of bins (-1 since b defines edges) 74 | 75 | % ------------------------------------------------------------------------------ 76 | % Form the time-delay vectors y1 and y2 77 | % ------------------------------------------------------------------------------ 78 | 79 | y1 = y(1:end-tau); 80 | y2 = y(1+tau:end); 81 | 82 | % (1) Joint distribution of y1 and y2 83 | pij = NK_hist2(y1,y2,b,b); 84 | pij = pij(1:nb,1:nb); % joint 85 | pij = pij/sum(sum(pij)); % joint 86 | pi = sum(pij,1); % marginal 87 | pj = sum(pij,2); % other marginal 88 | 89 | % Old-fashioned method (should give same result): 90 | % pi = histc(y1,b); pi = pi(1:nb); pi = pi/sum(pi); % marginal 91 | % pj = histc(y2,b); pj= pj(1:nb); pj = pj/sum(pj); % other marginal 92 | 93 | pii = ones(nb,1)*pi; 94 | pjj = pj*ones(1,nb); 95 | 96 | r = (pij > 0); % Defining the range in this way, we set log(0) = 0 97 | ami = sum(pij(r).*log(pij(r)./pii(r)./pjj(r))); 98 | 99 | out = ami; 100 | 101 | end 102 | -------------------------------------------------------------------------------- /Matlab/CO_f1ecac.m: -------------------------------------------------------------------------------- 1 | function out = CO_f1ecac(y) 2 | % CO_f1ecac The 1/e correlation length 3 | % 4 | % Finds where autocorrelation function first crosses 1/e 5 | % 6 | %---INPUT: 7 | % y, the input time series. 8 | 9 | % ------------------------------------------------------------------------------ 10 | % Copyright (C) 2017, Ben D. Fulcher , 11 | % 12 | % 13 | % If you use this code for your research, please cite the following two papers: 14 | % 15 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 16 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 17 | % DOI: 10.1016/j.cels.2017.10.001 18 | % 19 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 20 | % analysis: the empirical structure of time series and their methods", 21 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 22 | % DOI: 10.1098/rsif.2013.0048 23 | % 24 | % This function is free software: you can redistribute it and/or modify it under 25 | % the terms of the GNU General Public License as published by the Free Software 26 | % Foundation, either version 3 of the License, or (at your option) any later 27 | % version. 28 | % 29 | % This program is distributed in the hope that it will be useful, but WITHOUT 30 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 31 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 32 | % details. 33 | % 34 | % You should have received a copy of the GNU General Public License along with 35 | % this program. If not, see . 36 | % ------------------------------------------------------------------------------ 37 | 38 | % no combination of single functions 39 | coder.inline('never'); 40 | 41 | N = length(y); % time-series length 42 | thresh = 1/exp(1); % 1/e threshold 43 | 44 | a = zeros(N,1); % autocorrelations 45 | a(1) = 1; % perfect autocorrelation when no lag 46 | for i = 2:N 47 | a(i) = CO_AutoCorr(y,i-1,'Fourier'); 48 | if ((a(i-1)-thresh)*(a(i)-thresh) < 0) 49 | % Crossed the 1/e line 50 | out = i-1; % -1 since i is tau+1 51 | return 52 | end 53 | end 54 | 55 | % If no minimum in entire spectrum return the maximum value 56 | out = N; 57 | 58 | end 59 | -------------------------------------------------------------------------------- /Matlab/CO_trev_1_num.m: -------------------------------------------------------------------------------- 1 | function out = CO_trev_1_num(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | outStruct = CO_trev(y, 1); 7 | 8 | out = outStruct.num; -------------------------------------------------------------------------------- /Matlab/DN_HistogramMode_10.m: -------------------------------------------------------------------------------- 1 | function out = DN_HistogramMode_10(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = DN_HistogramMode(y, 10); -------------------------------------------------------------------------------- /Matlab/DN_HistogramMode_5.m: -------------------------------------------------------------------------------- 1 | function out = DN_HistogramMode_5(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = DN_HistogramMode(y, 5); -------------------------------------------------------------------------------- /Matlab/DN_Mean.m: -------------------------------------------------------------------------------- 1 | function out = DN_Mean(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = DN_Mean(y, 5); -------------------------------------------------------------------------------- /Matlab/DN_OutlierInclude_n_001_mdrmd.m: -------------------------------------------------------------------------------- 1 | function out = DN_OutlierInclude_n_001_mdrmd(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = DN_OutlierInclude_001_mdrmd(y, 'n'); 7 | -------------------------------------------------------------------------------- /Matlab/DN_OutlierInclude_p_001_mdrmd.m: -------------------------------------------------------------------------------- 1 | function out = DN_OutlierInclude_p_001_mdrmd(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = DN_OutlierInclude_001_mdrmd(y, 'p'); 7 | -------------------------------------------------------------------------------- /Matlab/DN_Spread_Std.m: -------------------------------------------------------------------------------- 1 | function out = DN_Spread_Std(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = DN_Spread_Std(y, 5); -------------------------------------------------------------------------------- /Matlab/FC_LocalSimple_mean1_tauresrat.m: -------------------------------------------------------------------------------- 1 | function out = FC_LocalSimple_mean1_tauresrat(y) 2 | % FC_LocalSimple Simple local time-series forecasting. 3 | % 4 | % Simple predictors using the past trainLength values of the time series to 5 | % predict its next value. 6 | % 7 | %---INPUTS: 8 | % y, the input time series 9 | % 10 | % ------------------------------------------------------------------------------ 11 | % Copyright (C) 2017, Ben D. Fulcher , 12 | % 13 | % 14 | % If you use this code for your research, please cite the following two papers: 15 | % 16 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 17 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 18 | % DOI: 10.1016/j.cels.2017.10.001 19 | % 20 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 21 | % analysis: the empirical structure of time series and their methods", 22 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 23 | % DOI: 10.1098/rsif.2013.0048 24 | % 25 | % This function is free software: you can redistribute it and/or modify it under 26 | % the terms of the GNU General Public License as published by the Free Software 27 | % Foundation, either version 3 of the License, or (at your option) any later 28 | % version. 29 | % 30 | % This program is distributed in the hope that it will be useful, but WITHOUT 31 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 32 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 33 | % details. 34 | % 35 | % You should have received a copy of the GNU General Public License along with 36 | % this program. If not, see . 37 | % ------------------------------------------------------------------------------ 38 | 39 | % no combination of single functions 40 | coder.inline('never'); 41 | 42 | % ------------------------------------------------------------------------- 43 | %% Set defaults 44 | % ------------------------------------------------------------------------- 45 | 46 | trainLength = 1; 47 | 48 | N = length(y); % Time-series length 49 | 50 | % ------------------------------------------------------------------------------ 51 | % Do the local prediction 52 | % ------------------------------------------------------------------------------ 53 | if strcmp(trainLength,'ac') 54 | lp = CO_FirstZero(y,'ac'); % make it tau 55 | else 56 | lp = trainLength; % the length of the subsegment preceeding to use to predict the subsequent value 57 | end 58 | evalr = lp+1:N; % range over which to evaluate the forecast 59 | if length(evalr)==0 60 | % warning('Time series too short for forecasting'); 61 | out = NaN; return 62 | end 63 | res = zeros(length(evalr),1); % residuals 64 | for i = 1:length(evalr) 65 | res(i) = mean(y(evalr(i)-lp:evalr(i)-1)) - y(evalr(i)); % prediction-value 66 | end 67 | 68 | % tauresrat 69 | out = CO_FirstZero(res,'ac')/CO_FirstZero(y,'ac'); 70 | 71 | end 72 | -------------------------------------------------------------------------------- /Matlab/FC_LocalSimple_mean3_stderr.m: -------------------------------------------------------------------------------- 1 | function out = FC_LocalSimple_mean3_stderr(y) 2 | % FC_LocalSimple Simple local time-series forecasting. 3 | % 4 | % Simple predictors using the past trainLength values of the time series to 5 | % predict its next value. 6 | % 7 | %---INPUTS: 8 | % y, the input time series 9 | % 10 | % ------------------------------------------------------------------------------ 11 | % Copyright (C) 2017, Ben D. Fulcher , 12 | % 13 | % 14 | % If you use this code for your research, please cite the following two papers: 15 | % 16 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 17 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 18 | % DOI: 10.1016/j.cels.2017.10.001 19 | % 20 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 21 | % analysis: the empirical structure of time series and their methods", 22 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 23 | % DOI: 10.1098/rsif.2013.0048 24 | % 25 | % This function is free software: you can redistribute it and/or modify it under 26 | % the terms of the GNU General Public License as published by the Free Software 27 | % Foundation, either version 3 of the License, or (at your option) any later 28 | % version. 29 | % 30 | % This program is distributed in the hope that it will be useful, but WITHOUT 31 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 32 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 33 | % details. 34 | % 35 | % You should have received a copy of the GNU General Public License along with 36 | % this program. If not, see . 37 | % ------------------------------------------------------------------------------ 38 | 39 | % no combination of single functions 40 | coder.inline('never'); 41 | 42 | %------------------------------------------------------------------------------- 43 | %% Set defaults: 44 | %------------------------------------------------------------------------------- 45 | 46 | trainLength = 3; 47 | 48 | N = length(y); % Time-series length 49 | 50 | % ------------------------------------------------------------------------------ 51 | % Do the local prediction 52 | % ------------------------------------------------------------------------------ 53 | 54 | lp = trainLength; % the length of the subsegment preceeding to use to predict the subsequent value 55 | 56 | evalr = lp+1:N; % range over which to evaluate the forecast 57 | if length(evalr)==0 58 | % warning('Time series too short for forecasting'); 59 | out = NaN; return 60 | end 61 | res = zeros(length(evalr),1); % residuals 62 | for i = 1:length(evalr) 63 | res(i) = mean(y(evalr(i)-lp:evalr(i)-1)) - y(evalr(i)); % prediction-value 64 | end 65 | 66 | % Spread of residuals: 67 | % stderr 68 | out = std(res); 69 | 70 | end 71 | -------------------------------------------------------------------------------- /Matlab/IN_AutoMutualInfoStats_40_gaussian_fmmi.m: -------------------------------------------------------------------------------- 1 | function out = IN_AutoMutualInfoStats_40_gaussian_fmmi(y) 2 | % IN_AutoMutualInfoStats Statistics on automutual information function for a time series. 3 | % 4 | %---INPUTS: 5 | % y, column vector of time series data 6 | % 7 | % maxTau, maximal time delay 8 | % 9 | % estMethod = 'gaussian' 10 | % 11 | %---OUTPUTS: 12 | % out = fmmi, statistic on the AMIs and their pattern across 13 | % the range of specified time delays. 14 | 15 | % ------------------------------------------------------------------------------ 16 | % Copyright (C) 2017, Ben D. Fulcher , 17 | % 18 | % 19 | % If you use this code for your research, please cite the following two papers: 20 | % 21 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 22 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 23 | % DOI: 10.1016/j.cels.2017.10.001 24 | % 25 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 26 | % analysis: the empirical structure of time series and their methods", 27 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 28 | % DOI: 10.1098/rsif.2013.0048 29 | % 30 | % This function is free software: you can redistribute it and/or modify it under 31 | % the terms of the GNU General Public License as published by the Free Software 32 | % Foundation, either version 3 of the License, or (at your option) any later 33 | % version. 34 | % 35 | % This program is distributed in the hope that it will be useful, but WITHOUT 36 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 37 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 38 | % details. 39 | % 40 | % You should have received a copy of the GNU General Public License along with 41 | % this program. If not, see . 42 | % ------------------------------------------------------------------------------ 43 | 44 | % no combination of single functions 45 | coder.inline('never'); 46 | 47 | % ------------------------------------------------------------------------------ 48 | %% Preliminaries 49 | % ------------------------------------------------------------------------------ 50 | N = length(y); % length of time series 51 | 52 | % ------------------------------------------------------------------------------ 53 | %% Check Inputs 54 | % ------------------------------------------------------------------------------ 55 | 56 | % maxTau: the maximum time delay to investigate 57 | maxTau = 40; 58 | 59 | % Don't go above N/2 60 | maxTau = min(maxTau,ceil(N/2)); 61 | 62 | % ------------------------------------------------------------------------------ 63 | %% Get the AMI data: 64 | % ------------------------------------------------------------------------------ 65 | 66 | % do this manually, Gaussian really is the easiest MI 67 | autocorrs = autocorrelation(y, maxTau); 68 | ami = -0.5*log(1 - autocorrs.^2); 69 | 70 | 71 | % ------------------------------------------------------------------------------ 72 | % Output statistics: 73 | % ------------------------------------------------------------------------------ 74 | lami = length(ami); 75 | 76 | % First minimum of mutual information across range 77 | dami = diff(ami); 78 | extremai = find(dami(1:end-1).*dami(2:end) < 0 & dami(1:end-1)<0); 79 | if isempty(extremai) 80 | % fmmi 81 | out = lami; % actually represents lag, because indexes don't but diff delays by 1 82 | else 83 | % fmmi 84 | out = min(extremai); 85 | end 86 | 87 | end 88 | 89 | function out = autocorrelation(y, maxLag) 90 | 91 | N = length(y); 92 | 93 | if maxLag >= N 94 | maxLag = N-1; 95 | end 96 | 97 | out = zeros(1,maxLag); 98 | 99 | for lag = 1:maxLag 100 | corrs = corrcoef(y(1:end-lag), y(1+lag:end)); 101 | out(lag) = corrs(2,1); 102 | end 103 | 104 | end 105 | -------------------------------------------------------------------------------- /Matlab/MD_hrv_classic_pnn40.m: -------------------------------------------------------------------------------- 1 | function out = MD_hrv_classic_pnn40(y) 2 | % MD_hrv_classic Classic heart rate variability (HRV) statistics. 3 | % 4 | % Typically assumes an NN/RR time series in units of seconds. 5 | % 6 | %---INPUTS: 7 | % y, the input time series. 8 | % 9 | %---OUTPUTS: 10 | % pNN40 11 | % cf. "The pNNx files: re-examining a widely used heart rate variability 12 | % measure", J.E. Mietus et al., Heart 88(4) 378 (2002) 13 | % 14 | % Code is heavily derived from that provided by Max A. Little: 15 | % http://www.maxlittle.net/ 16 | 17 | % ------------------------------------------------------------------------------ 18 | % Copyright (C) 2017, Ben D. Fulcher , 19 | % 20 | % 21 | % If you use this code for your research, please cite the following two papers: 22 | % 23 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 24 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 25 | % DOI: 10.1016/j.cels.2017.10.001 26 | % 27 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 28 | % analysis: the empirical structure of time series and their methods", 29 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 30 | % DOI: 10.1098/rsif.2013.0048 31 | % 32 | % This function is free software: you can redistribute it and/or modify it under 33 | % the terms of the GNU General Public License as published by the Free Software 34 | % Foundation, either version 3 of the License, or (at your option) any later 35 | % version. 36 | % 37 | % This program is distributed in the hope that it will be useful, but WITHOUT 38 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 39 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 40 | % details. 41 | % 42 | % You should have received a copy of the GNU General Public License along with 43 | % this program. If not, see . 44 | % ------------------------------------------------------------------------------ 45 | 46 | % no combination of single functions 47 | coder.inline('never'); 48 | 49 | % Standard defaults 50 | diffy = diff(y); 51 | N = length(y); % time-series length 52 | 53 | % ------------------------------------------------------------------------------ 54 | % Calculate pNNx percentage 55 | % ------------------------------------------------------------------------------ 56 | % pNNx: recommendation as per Mietus et. al. 2002, "The pNNx files: ...", Heart 57 | % strange to do this for a z-scored time series... 58 | % pnntime = 20; 59 | 60 | Dy = abs(diffy) * 1000; 61 | 62 | % Anonymous function to do the PNNx calcualtion: 63 | PNNxfn = @(x) sum(Dy > x)/(N-1); 64 | 65 | % % exceed = sum(Dy > pnntime); 66 | % out.pnn5 = PNNxfn(5); %sum(Dy > 5)/(N-1); % proportion of difference magnitudes greater than 0.005*sigma 67 | % out.pnn10 = PNNxfn(10); %sum(Dy > 10)/(N-1); 68 | % out.pnn20 = PNNxfn(20); %sum(Dy > 20)/(N-1); 69 | % out.pnn30 = PNNxfn(30); %sum(Dy > 30)/(N-1); 70 | % pnn40 71 | out = PNNxfn(40); %sum(Dy > 40)/(N-1); 72 | 73 | 74 | end 75 | -------------------------------------------------------------------------------- /Matlab/PD_PeriodicityWang_th0_01.m: -------------------------------------------------------------------------------- 1 | function out = PD_PeriodicityWang_th0_01(y_in) 2 | % PD_PeriodicityWang Periodicity extraction measure of Wang et al. 3 | % 4 | % Implements an idea based on the periodicity extraction measure proposed in: 5 | % 6 | % "Structure-based Statistical Features and Multivariate Time Series Clustering" 7 | % Wang, X. and Wirth, A. and Wang, L. 8 | % Seventh IEEE International Conference on Data Mining, 351--360 (2007) 9 | % DOI: 10.1109/ICDM.2007.103 10 | % 11 | % Detrends the time series using a single-knot cubic regression spline 12 | % and then computes autocorrelations up to one third of the length of 13 | % the time series. The frequency is the first peak in the autocorrelation 14 | % function satisfying a set of conditions. 15 | % 16 | % This code uses the SPLINEFIT v1.13.0.0 function by Jonas Lundgren from 17 | % Matlab Central accessed on 25 Aug 2018. 18 | % 19 | %---INPUT: 20 | % y, the input time series. 21 | % 22 | 23 | % ------------------------------------------------------------------------------ 24 | % Copyright (C) 2017, Ben D. Fulcher , 25 | % 26 | % 27 | % If you use this code for your research, please cite the following two papers: 28 | % 29 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 30 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 31 | % DOI: 10.1016/j.cels.2017.10.001 32 | % 33 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 34 | % analysis: the empirical structure of time series and their methods", 35 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 36 | % DOI: 10.1098/rsif.2013.0048 37 | % 38 | % This function is free software: you can redistribute it and/or modify it under 39 | % the terms of the GNU General Public License as published by the Free Software 40 | % Foundation, either version 3 of the License, or (at your option) any later 41 | % version. 42 | % 43 | % This program is distributed in the hope that it will be useful, but WITHOUT 44 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 45 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 46 | % details. 47 | % 48 | % You should have received a copy of the GNU General Public License along with 49 | % this program. If not, see . 50 | % ------------------------------------------------------------------------------ 51 | 52 | % no combination of single functions 53 | coder.inline('never'); 54 | 55 | % ------------------------------------------------------------------------------ 56 | %% Foreplay 57 | % ------------------------------------------------------------------------------ 58 | N = length(y_in); % length of the time series 59 | th = 0.01; % [0, 0.01, 0.1, 0.2, 1/sqrt(N), 5/sqrt(N), 10/sqrt(N)]; % the thresholds with which to count a peak 60 | 61 | % ------------------------------------------------------------------------------ 62 | %% 1: Detrend using a regression spline with 3 knots 63 | % ------------------------------------------------------------------------------ 64 | 65 | ppSpline = splinefit(y_in'); 66 | 67 | y_spl = ppval(ppSpline,1:N); 68 | % x = (ppSpline.breaks(1):ppSpline.breaks(2))-1; 69 | % y_spl_1 = ppSpline.coefs(1,1)*x.^3 + ppSpline.coefs(1,2)*x.^2 + ppSpline.coefs(1,3)*x.^1 + ppSpline.coefs(1,4); 70 | % x = (ppSpline.breaks(2):ppSpline.breaks(3))-ppSpline.breaks(2)+1; 71 | % y_spl_2 = ppSpline.coefs(2,1)*x.^3 + ppSpline.coefs(2,2)*x.^2 + ppSpline.coefs(2,3)*x.^1 + ppSpline.coefs(2,4); 72 | % y_spl = [y_spl_1, y_spl_2]; 73 | 74 | y = y_in - y_spl'; 75 | 76 | %% 2. Compute autocorrelations up to 1/3 the length of the time series. 77 | acmax = ceil(N/3); % compute autocorrelations up to this lag 78 | acf = zeros(acmax,1); % the autocorrelation function 79 | for i = 1:acmax % i is the \tau, the AC lag 80 | acf(i) = mean(y(1:N-i).*y(i+1:N)); 81 | end 82 | 83 | % ------------------------------------------------------------------------------ 84 | %% 3. Frequency is the first peak satisfying the following conditions: 85 | % ------------------------------------------------------------------------------ 86 | % (a) a trough before it 87 | % (b) difference between peak and trough is at least 0.01 88 | % (c) peak corresponds to positive correlation 89 | 90 | % (i) find peaks and troughs in ACF 91 | diffac = diff(acf); % differenced time series 92 | sgndiffac = sign(diffac); % sign of differenced time series 93 | bath = diff(sgndiffac); % differenced, signed, differenced time series 94 | troughs = find(bath == 2) + 1; % finds troughs 95 | peaks = find(bath == -2) + 1; % finds peaks 96 | npeaks = length(peaks); 97 | 98 | out = 0; 99 | 100 | for i = 1:npeaks % search through all peaks for one that meets the condition 101 | ipeak = peaks(i); % acf lag at which there is a peak 102 | thepeak = acf(ipeak); % acf at the peak 103 | ftrough = find(troughs < ipeak,1,'last'); 104 | if isempty(ftrough); continue; end 105 | itrough = troughs(ftrough); % acf lag at which there is a trough (the first one preceeding the peak) 106 | thetrough = acf(itrough); % acf at the trough 107 | 108 | % (a) a trough before it: should be implicit in the ftrough bit above 109 | % if troughs(1)>ipeak % the first trough is after it 110 | % continue 111 | % end 112 | 113 | % (b) difference between peak and trough is at least 0.01 114 | if thepeak - thetrough < th 115 | continue 116 | end 117 | 118 | % (c) peak corresponds to positive correlation 119 | if thepeak < 0 120 | continue 121 | end 122 | 123 | % we made it! Use this frequency! 124 | out = ipeak; break 125 | end 126 | 127 | 128 | end 129 | -------------------------------------------------------------------------------- /Matlab/SB_BinaryStats_diff_longstretch0.m: -------------------------------------------------------------------------------- 1 | function out = SB_BinaryStats_diff_longstretch0(y) 2 | % SB_BinaryStats Statistics on a binary symbolization of the time series 3 | % 4 | % Binary symbolization of the time series is a symbolic string of 0s and 1s. 5 | % 6 | % Provides information about the coarse-grained behavior of the time series 7 | % 8 | %---INPUTS: 9 | % y, the input time series 10 | % 11 | % binaryMethod, the symbolization rule: 12 | % 'diff': by whether incremental differences of the time series are 13 | % positive (1), or negative (0), 14 | % 15 | %---OUTPUTS: 16 | % Include the Shannon entropy of the string, the longest stretches of 0s 17 | % or 1s, the mean length of consecutive 0s or 1s, and the spread of consecutive 18 | % strings of 0s or 1s. 19 | 20 | % ------------------------------------------------------------------------------ 21 | % Copyright (C) 2017, Ben D. Fulcher , 22 | % 23 | % 24 | % If you use this code for your research, please cite the following two papers: 25 | % 26 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 27 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 28 | % DOI: 10.1016/j.cels.2017.10.001 29 | % 30 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 31 | % analysis: the empirical structure of time series and their methods", 32 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 33 | % DOI: 10.1098/rsif.2013.0048 34 | % 35 | % This function is free software: you can redistribute it and/or modify it under 36 | % the terms of the GNU General Public License as published by the Free Software 37 | % Foundation, either version 3 of the License, or (at your option) any later 38 | % version. 39 | % 40 | % This program is distributed in the hope that it will be useful, but WITHOUT 41 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 42 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 43 | % details. 44 | % 45 | % You should have received a copy of the GNU General Public License along with 46 | % this program. If not, see . 47 | % ------------------------------------------------------------------------------ 48 | 49 | % no combination of single functions 50 | coder.inline('never'); 51 | 52 | %------------------------------------------------------------------------------- 53 | % Set defaults: 54 | %------------------------------------------------------------------------------- 55 | 56 | binaryMethod = 'diff'; 57 | 58 | %------------------------------------------------------------------------------- 59 | % Binarize the time series: 60 | %------------------------------------------------------------------------------- 61 | yBin = BF_Binarize(y,binaryMethod); 62 | 63 | %------------------------------------------------------------------------------- 64 | % Consecutive string of ones / zeros (normalized by length) 65 | %------------------------------------------------------------------------------- 66 | difffy = diff(find([1;yBin;1])); 67 | stretch0 = difffy(difffy ~= 1) - 1; 68 | 69 | %------------------------------------------------------------------------------- 70 | % pstretches 71 | %------------------------------------------------------------------------------- 72 | 73 | if isempty(stretch0) % all 1s (almost impossible to actually occur) 74 | longstretch0 = 0; 75 | else 76 | longstretch0 = max(stretch0); % longest consecutive stretch of zeros 77 | end 78 | 79 | out = longstretch0; 80 | 81 | end 82 | -------------------------------------------------------------------------------- /Matlab/SB_BinaryStats_mean_longstretch1.m: -------------------------------------------------------------------------------- 1 | function out = SB_BinaryStats_mean_longstretch1(y) 2 | % SB_BinaryStats Statistics on a binary symbolization of the time series 3 | % 4 | % Binary symbolization of the time series is a symbolic string of 0s and 1s. 5 | % 6 | % Provides information about the coarse-grained behavior of the time series 7 | % 8 | %---INPUTS: 9 | % y, the input time series 10 | % 11 | % binaryMethod, the symbolization rule: 12 | % 'diff': by whether incremental differences of the time series are 13 | % positive (1), or negative (0), 14 | % 15 | %---OUTPUTS: 16 | % Include the Shannon entropy of the string, the longest stretches of 0s 17 | % or 1s, the mean length of consecutive 0s or 1s, and the spread of consecutive 18 | % strings of 0s or 1s. 19 | 20 | % ------------------------------------------------------------------------------ 21 | % Copyright (C) 2017, Ben D. Fulcher , 22 | % 23 | % 24 | % If you use this code for your research, please cite the following two papers: 25 | % 26 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 27 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 28 | % DOI: 10.1016/j.cels.2017.10.001 29 | % 30 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 31 | % analysis: the empirical structure of time series and their methods", 32 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 33 | % DOI: 10.1098/rsif.2013.0048 34 | % 35 | % This function is free software: you can redistribute it and/or modify it under 36 | % the terms of the GNU General Public License as published by the Free Software 37 | % Foundation, either version 3 of the License, or (at your option) any later 38 | % version. 39 | % 40 | % This program is distributed in the hope that it will be useful, but WITHOUT 41 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 42 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 43 | % details. 44 | % 45 | % You should have received a copy of the GNU General Public License along with 46 | % this program. If not, see . 47 | % ------------------------------------------------------------------------------ 48 | 49 | % no combination of single functions 50 | coder.inline('never'); 51 | 52 | %------------------------------------------------------------------------------- 53 | % Set defaults: 54 | %------------------------------------------------------------------------------- 55 | 56 | binaryMethod = 'mean'; 57 | 58 | %------------------------------------------------------------------------------- 59 | % Binarize the time series: 60 | %------------------------------------------------------------------------------- 61 | yBin = BF_Binarize(y,binaryMethod); 62 | 63 | %------------------------------------------------------------------------------- 64 | % Consecutive string of ones (normalized by length) 65 | %------------------------------------------------------------------------------- 66 | difffy = diff(find([0;yBin;0] == 0)); 67 | stretch1 = difffy(difffy ~= 1) - 1; 68 | 69 | %------------------------------------------------------------------------------- 70 | % pstretches 71 | %------------------------------------------------------------------------------- 72 | 73 | if isempty(stretch1) % all 1s (almost impossible to actually occur) 74 | longstretch1 = 0; 75 | else 76 | longstretch1 = max(stretch1); % longest consecutive stretch of zeros 77 | end 78 | 79 | out = longstretch1; 80 | 81 | end 82 | -------------------------------------------------------------------------------- /Matlab/SB_MotifThree_quantile_hh.m: -------------------------------------------------------------------------------- 1 | function out = SB_MotifThree_quantile_hh(y) 2 | % SB_MotifThree Motifs in a coarse-graining of a time series to a 3-letter alphabet 3 | % 4 | % (As SB_MotifTwo but with a 3-letter alphabet) 5 | % 6 | %---INPUTS: 7 | % y, time series to analyze 8 | % cgHow, the coarse-graining method to use. 'quantile': equiprobable alphabet by time-series value 9 | % 10 | %---OUTPUTS: 11 | % Statistics on words of length 1, 2, 3, and 4. 12 | 13 | % ------------------------------------------------------------------------------ 14 | % Copyright (C) 2017, Ben D. Fulcher , 15 | % 16 | % 17 | % If you use this code for your research, please cite the following two papers: 18 | % 19 | % (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated 20 | % Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017). 21 | % DOI: 10.1016/j.cels.2017.10.001 22 | % 23 | % (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series 24 | % analysis: the empirical structure of time series and their methods", 25 | % J. Roy. Soc. Interface 10(83) 20130048 (2013). 26 | % DOI: 10.1098/rsif.2013.0048 27 | % 28 | % This function is free software: you can redistribute it and/or modify it under 29 | % the terms of the GNU General Public License as published by the Free Software 30 | % Foundation, either version 3 of the License, or (at your option) any later 31 | % version. 32 | % 33 | % This program is distributed in the hope that it will be useful, but WITHOUT 34 | % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 35 | % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 36 | % details. 37 | % 38 | % You should have received a copy of the GNU General Public License along with 39 | % this program. If not, see . 40 | % ------------------------------------------------------------------------------ 41 | 42 | % no combination of single functions 43 | coder.inline('never'); 44 | 45 | %------------------------------------------------------------------------------- 46 | %% Set defaults: 47 | %------------------------------------------------------------------------------- 48 | 49 | % quantile graining 50 | yt = SB_CoarseGrain_quantile(y,3); 51 | 52 | N = length(yt); % Length of the symbolized sequence derived from the time series 53 | 54 | % So we have a vector yt with entries \in {1,2,3} 55 | 56 | % ------------------------------------------------------------------------------ 57 | %% Words of length 1 58 | % ------------------------------------------------------------------------------ 59 | r1 = cell(3,1); % stores ranges as vectors 60 | % out1 = zeros(3,1); % stores probabilities as doubles 61 | 62 | for i = 1:3 63 | r1{i} = find(yt == i); 64 | % out1(i) = length(r1{i})/N; 65 | end 66 | 67 | 68 | % ------------------------------------------------------------------------------ 69 | %% Words of length 2 70 | % ------------------------------------------------------------------------------ 71 | % Make sure ranges are valid for looking at the next one 72 | for i = 1:3 73 | if (~isempty(r1{i})) && (r1{i}(end) == N) 74 | r1{i} = r1{i}(1:end-1); 75 | end 76 | end 77 | 78 | r2 = cell(3,3); 79 | out2 = zeros(3,3); 80 | for i = 1:3 81 | for j = 1:3 82 | r2{i,j} = r1{i}(yt(r1{i}+1) == j); 83 | out2(i,j) = length(r2{i,j})/(N-1); 84 | end 85 | end 86 | 87 | % hh 88 | out = f_entropy(out2); % entropy of this result 89 | 90 | %------------------------------------------------------------------------------- 91 | function h = f_entropy(x) 92 | % entropy of a set of counts, log(0)=0 93 | h = -sum(x(x > 0).*log(x(x > 0))); 94 | end 95 | 96 | end 97 | -------------------------------------------------------------------------------- /Matlab/SB_TransitionMatrix_3ac_sumdiagcov.m: -------------------------------------------------------------------------------- 1 | function out = SB_TransitionMatrix_3ac_sumdiagcov(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | outStruct = SB_TransitionMatrix(y, 3, 'ac'); 7 | 8 | out = outStruct.sumdiagcov; -------------------------------------------------------------------------------- /Matlab/SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1.m: -------------------------------------------------------------------------------- 1 | function out = SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = SC_FluctAnal_q2_taustep50_k1_logi_prop_r1(y, 'dfa', 2); -------------------------------------------------------------------------------- /Matlab/SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1.m: -------------------------------------------------------------------------------- 1 | function out = SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | out = SC_FluctAnal_q2_taustep50_k1_logi_prop_r1(y, 'rsrangefit'); -------------------------------------------------------------------------------- /Matlab/SP_Summaries_welch_rect_area_5_1.m: -------------------------------------------------------------------------------- 1 | function out = SP_Summaries_welch_rect_area_5_1(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | outStruct = SP_Summaries_welch_rect(y); 7 | out = outStruct.area_5_1; -------------------------------------------------------------------------------- /Matlab/SP_Summaries_welch_rect_centroid.m: -------------------------------------------------------------------------------- 1 | function out = SP_Summaries_welch_rect_centroid(y) 2 | 3 | % no combination of single functions 4 | coder.inline('never'); 5 | 6 | outStruct = SP_Summaries_welch_rect(y); 7 | out = outStruct.centroid; 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

catch22 logo

2 | 3 |

catch22: CAnonical Time-series CHaracteristics

4 | 5 |

6 | 7 | 8 | 9 |

10 | 11 | _catch22_ is a collection of 22 time-series features coded in C that can be run from Python, R, Matlab, and Julia, licensed under the [GNU GPL v3 license](http://www.gnu.org/licenses/gpl-3.0.html) (or later). 12 | The _catch22_ features are a high-performing subset of the over 7000 features in [_hctsa_](https://github.com/benfulcher/hctsa). 13 | 14 | The features were selected based on their classification performance across a collection of 93 real-world time-series classification problems, as described in our open-access paper, [📗 Lubba et al. (2019). _catch22_: CAnonical Time-series CHaracteristics](https://doi.org/10.1007/s10618-019-00647-x). 15 | 16 | ## [📙📘📗___catch22_ documentation__](https://time-series-features.gitbook.io/catch22/) 17 | 18 | There is [comprehensive documentation](https://time-series-features.gitbook.io/catch22/) for _catch22_, including: 19 | 20 | - Installation instructions (across C, python, R, Julia, and Matlab) 21 | - Information about the theory behind and behavior of each of the features, 22 | - A list of publications that have used or extended _catch22_ 23 | - And more :yum: 24 | 25 | ## Installation and Usage in Python, R, Matlab, Julia, and compiled C 26 | 27 | There are also native versions of this code for other programming languages: 28 | 29 | - [Rcatch22](https://github.com/hendersontrent/Rcatch22) (R) `install.packages("Rcatch22")` 30 | - [pycatch22](https://github.com/DynamicsAndNeuralSystems/pycatch22) (python) `pip install pycatch22` 31 | - [Catch22.jl](https://github.com/brendanjohnharris/Catch22.jl) (Julia) `Pkg.add("Catch22")` 32 | 33 | You can also use the C-compiled features directly, or in Matlab, following the [detailed installation instructions in the documentation](https://time-series-features.gitbook.io/catch22/). 34 | 35 | ## Acknowledgement :+1: 36 | 37 | If you use this software, please read and cite this open-access article: 38 | 39 | - 📗 Lubba et al. [_catch22_: CAnonical Time-series CHaracteristics](https://doi.org/10.1007/s10618-019-00647-x), _Data Min Knowl Disc_ __33__, 1821 (2019). 40 | 41 | ## Performance Summary 42 | 43 | Summary of the performance of the _catch22_ feature set across 93 classification problems, and a comparison to the [_hctsa_ feature set](https://github.com/benfulcher/hctsa) (cf. Fig. 4 from [our paper](https://doi.org/10.1007/s10618-019-00647-x)): 44 | 45 | ![](img/PerformanceComparisonFig4.png) 46 | 47 | ## Notes 48 | 49 | - When presenting results using _catch22_, you must identify the version used to allow clear reproduction of your results. For example, `CO_f1ecac` was altered from an integer-valued output to a linearly interpolated real-valued output from v0.3. 50 | - _catch22_ features only evaluate _dynamical_ properties of time series and do not respond to basic differences in the location (e.g., mean) or spread (e.g., variance). 51 | - If the location and spread of the raw time-series distribution may be important for your application, you should apply the function argument `catch24 = true` (`TRUE` in R, `True` in Python) to your call to the _catch22_ function in the language of your choice. This will result in 24 features being calculated: the _catch22_ features in addition to mean and standard deviation. 52 | - Time series are _z_-scored internally (for features other than mean and standard deviation), which means that, e.g., constant time series will lead to `NaN` outputs. 53 | - Time-series data are taken as an ordered sequence of values (without time stamps). We assume an evenly sampled time series. 54 | - See language-specific usage information in the [docs](https://time-series-features.gitbook.io/catch22/). 55 | - The computational pipeline used to generate the _catch22_ feature set is in the [`op_importance`](https://github.com/chlubba/op_importance) repository. 56 | -------------------------------------------------------------------------------- /catch22.m: -------------------------------------------------------------------------------- 1 | function out = catch22(y) 2 | % catch22 Compute all 22 catch22 features 3 | 4 | % No combination of single functions 5 | coder.inline('never'); 6 | 7 | % First z-score: 8 | y = (y - mean(y))/std(y); 9 | 10 | out = zeros(22,1); 11 | 12 | out(1) = DN_HistogramMode_5(y); 13 | out(2) = DN_HistogramMode_10(y); 14 | out(3) = CO_f1ecac(y); 15 | out(4) = CO_FirstMin_ac(y); 16 | out(5) = CO_HistogramAMI_even_2_5(y); 17 | out(6) = CO_trev_1_num(y); 18 | out(7) = MD_hrv_classic_pnn40(y); 19 | out(8) = SB_BinaryStats_mean_longstretch1(y); 20 | out(9) = SB_TransitionMatrix_3ac_sumdiagcov(y); 21 | out(10) = PD_PeriodicityWang_th0_01(y); 22 | out(11) = CO_Embed2_Dist_tau_d_expfit_meandiff(y); 23 | out(12) = IN_AutoMutualInfoStats_40_gaussian_fmmi(y); 24 | out(13) = FC_LocalSimple_mean1_tauresrat(y); 25 | out(14) = DN_OutlierInclude_p_001_mdrmd(y); 26 | out(15) = DN_OutlierInclude_n_001_mdrmd(y); 27 | out(16) = SP_Summaries_welch_rect_area_5_1(y); 28 | out(17) = SB_BinaryStats_diff_longstretch0(y); 29 | out(18) = SB_MotifThree_quantile_hh(y); 30 | out(19) = SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(y); 31 | out(20) = SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(y); 32 | out(21) = SP_Summaries_welch_rect_centroid(y); 33 | out(22) = FC_LocalSimple_mean3_stderr(y); 34 | 35 | end 36 | -------------------------------------------------------------------------------- /featureList.txt: -------------------------------------------------------------------------------- 1 | # Full_feature_name_code short_feature_name 2 | # --------------------------------------------------------------- 3 | DN_HistogramMode_5 mode_5 4 | DN_HistogramMode_10 mode_10 5 | DN_OutlierInclude_p_001_mdrmd outlier_timing_pos 6 | DN_OutlierInclude_n_001_mdrmd outlier_timing_neg 7 | CO_f1ecac acf_timescale 8 | CO_FirstMin_ac acf_first_min 9 | SP_Summaries_welch_rect_area_5_1 low_freq_power 10 | SP_Summaries_welch_rect_centroid centroid_freq 11 | FC_LocalSimple_mean3_stderr forecast_error 12 | FC_LocalSimple_mean1_tauresrat whiten_timescale 13 | MD_hrv_classic_pnn40 high_fluctuation 14 | SB_BinaryStats_mean_longstretch1 stretch_high 15 | SB_BinaryStats_diff_longstretch0 stretch_decreasing 16 | SB_MotifThree_quantile_hh entropy_pairs 17 | CO_HistogramAMI_even_2_5 ami2 18 | CO_trev_1_num trev 19 | IN_AutoMutualInfoStats_40_gaussian_fmmi ami_timescale 20 | SB_TransitionMatrix_3ac_sumdiagcov transition_variance 21 | PD_PeriodicityWang_th0_01 periodicity 22 | CO_Embed2_Dist_tau_d_expfit_meandiff embedding_dist 23 | SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1 rs_range 24 | SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1 dfa 25 | DN_Mean mean 26 | DN_Spread_Std std 27 | -------------------------------------------------------------------------------- /img/PerformanceComparisonFig4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DynamicsAndNeuralSystems/catch22/d39af485c9fee310a25f2bb86ca6bdba5deef9cf/img/PerformanceComparisonFig4.png -------------------------------------------------------------------------------- /img/catch22_logo_square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DynamicsAndNeuralSystems/catch22/d39af485c9fee310a25f2bb86ca6bdba5deef9cf/img/catch22_logo_square.png -------------------------------------------------------------------------------- /testData/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | "$(dirname -- $0)/../C/runAllTS.sh" -i "$(dirname -- $0)" -o "$(dirname -- $0)" -a "_output" -s 1 -i "$(dirname -- $0)" -o "$(dirname -- $0)" -a "_output" -s 1 4 | -------------------------------------------------------------------------------- /testData/test.txt: -------------------------------------------------------------------------------- 1 | -0.89094 2 | -0.86099 3 | -0.82438 4 | -0.78214 5 | -0.73573 6 | -0.68691 7 | -0.63754 8 | -0.58937 9 | -0.54342 10 | -0.50044 11 | -0.46082 12 | -0.42469 13 | -0.3924 14 | -0.36389 15 | -0.33906 16 | -0.31795 17 | -0.30056 18 | -0.28692 19 | -0.27727 20 | -0.27105 21 | -0.26777 22 | -0.26678 23 | -0.26742 24 | -0.26927 25 | -0.27202 26 | -0.27529 27 | -0.27898 28 | -0.2832 29 | -0.28814 30 | -0.29431 31 | -0.30185 32 | -0.31086 33 | -0.32135 34 | -0.33326 35 | -0.3465 36 | -0.36103 37 | -0.37659 38 | -0.39297 39 | -0.40995 40 | -0.42731 41 | -0.44484 42 | -0.46226 43 | -0.47921 44 | -0.49534 45 | -0.51031 46 | -0.52382 47 | -0.53567 48 | -0.54568 49 | -0.55375 50 | -0.55984 51 | -0.56397 52 | -0.56617 53 | -0.56653 54 | -0.56511 55 | -0.56201 56 | -0.55736 57 | -0.55133 58 | -0.54419 59 | -0.53617 60 | -0.52758 61 | -0.51876 62 | -0.51004 63 | -0.50174 64 | -0.49418 65 | -0.48731 66 | -0.48128 67 | -0.47619 68 | -0.4721 69 | -0.46921 70 | -0.4674 71 | -0.46649 72 | -0.46659 73 | -0.46785 74 | -0.47045 75 | -0.4749 76 | -0.48081 77 | -0.48822 78 | -0.49726 79 | -0.50805 80 | -0.52086 81 | -0.53596 82 | -0.55266 83 | -0.57081 84 | -0.59021 85 | -0.61063 86 | -0.63238 87 | -0.65484 88 | -0.67722 89 | -0.69907 90 | -0.72004 91 | -0.73987 92 | -0.75965 93 | -0.77816 94 | -0.79527 95 | -0.8109 96 | -0.82509 97 | -0.83844 98 | -0.85159 99 | -0.86373 100 | -0.87474 101 | -0.88447 102 | -0.8929 103 | -0.90125 104 | -0.90911 105 | -0.91606 106 | -0.92197 107 | -0.92677 108 | -0.93071 109 | -0.93528 110 | -0.93931 111 | -0.9426 112 | -0.94494 113 | -0.94622 114 | -0.94735 115 | -0.94879 116 | -0.94965 117 | -0.94971 118 | -0.94878 119 | -0.94679 120 | -0.94571 121 | -0.94428 122 | -0.94176 123 | -0.93756 124 | -0.9311 125 | -0.92258 126 | -0.91342 127 | -0.90142 128 | -0.88573 129 | -0.86549 130 | -0.83998 131 | -0.81054 132 | -0.77682 133 | -0.73745 134 | -0.692 135 | -0.64033 136 | -0.58278 137 | -0.52295 138 | -0.45966 139 | -0.39357 140 | -0.32536 141 | -0.2557 142 | -0.18627 143 | -0.11888 144 | -0.052529 145 | 0.012911 146 | 0.077684 147 | 0.14195 148 | 0.2039 149 | 0.26391 150 | 0.3225 151 | 0.37976 152 | 0.43566 153 | 0.48977 154 | 0.53999 155 | 0.58745 156 | 0.63232 157 | 0.6749 158 | 0.71548 159 | 0.75342 160 | 0.78841 161 | 0.82157 162 | 0.85356 163 | 0.88519 164 | 0.91734 165 | 0.94972 166 | 0.98403 167 | 1.0219 168 | 1.0648 169 | 1.1143 170 | 1.1713 171 | 1.2359 172 | 1.3092 173 | 1.3911 174 | 1.4809 175 | 1.5776 176 | 1.6787 177 | 1.7819 178 | 1.8846 179 | 1.9842 180 | 2.0777 181 | 2.1627 182 | 2.2362 183 | 2.2969 184 | 2.3436 185 | 2.3759 186 | 2.3942 187 | 2.3994 188 | 2.3927 189 | 2.3763 190 | 2.3521 191 | 2.3222 192 | 2.2886 193 | 2.2524 194 | 2.2149 195 | 2.1772 196 | 2.1394 197 | 2.1018 198 | 2.0641 199 | 2.0259 200 | 1.9878 201 | 1.9494 202 | 1.9106 203 | 1.8711 204 | 1.8305 205 | 1.7886 206 | 1.7455 207 | 1.7008 208 | 1.6537 209 | 1.6036 210 | 1.5495 211 | 1.492 212 | 1.431 213 | 1.3664 214 | 1.2981 215 | 1.2262 216 | 1.1508 217 | 1.0736 218 | 0.99504 219 | 0.91575 220 | 0.83626 221 | 0.75657 222 | 0.67816 223 | 0.60206 224 | 0.52843 225 | 0.45712 226 | 0.38776 227 | 0.31881 228 | 0.2515 229 | 0.18511 230 | 0.11894 231 | 0.052471 232 | -0.01492 233 | -0.082568 234 | -0.14848 235 | -0.21193 236 | -0.27229 237 | -0.32905 238 | -0.38303 239 | -0.43222 240 | -0.47628 241 | -0.51587 242 | -0.55188 243 | -0.58534 244 | -0.61763 245 | -0.64653 246 | -0.67227 247 | -0.69521 248 | -0.71576 249 | -0.73517 250 | -0.75286 251 | -0.76798 252 | -0.7812 253 | -0.79326 254 | -0.80474 255 | -0.81719 256 | -0.82831 257 | -0.83768 258 | -0.84538 259 | -0.85165 260 | -0.85731 261 | -0.86309 262 | -0.86791 263 | -0.87271 264 | -0.87846 265 | -0.88592 266 | -0.89619 267 | -0.90783 268 | -0.91942 269 | -0.93018 270 | -0.93939 271 | -------------------------------------------------------------------------------- /testData/test2.txt: -------------------------------------------------------------------------------- 1 | -0.89094 -0.86099 -0.82438 -0.78214 -0.73573 -0.68691 -0.63754 -0.58937 -0.54342 -0.50044 -0.46082 -0.42469 -0.3924 -0.36389 -0.33906 -0.31795 -0.30056 -0.28692 -0.27727 -0.27105 -0.26777 -0.26678 -0.26742 -0.26927 -0.27202 -0.27529 -0.27898 -0.2832 -0.28814 -0.29431 -0.30185 -0.31086 -0.32135 -0.33326 -0.3465 -0.36103 -0.37659 -0.39297 -0.40995 -0.42731 -0.44484 -0.46226 -0.47921 -0.49534 -0.51031 -0.52382 -0.53567 -0.54568 -0.55375 -0.55984 -0.56397 -0.56617 -0.56653 -0.56511 -0.56201 -0.55736 -0.55133 -0.54419 -0.53617 -0.52758 -0.51876 -0.51004 -0.50174 -0.49418 -0.48731 -0.48128 -0.47619 -0.4721 -0.46921 -0.4674 -0.46649 -0.46659 -0.46785 -0.47045 -0.4749 -0.48081 -0.48822 -0.49726 -0.50805 -0.52086 -0.53596 -0.55266 -0.57081 -0.59021 -0.61063 -0.63238 -0.65484 -0.67722 -0.69907 -0.72004 -0.73987 -0.75965 -0.77816 -0.79527 -0.8109 -0.82509 -0.83844 -0.85159 -0.86373 -0.87474 -0.88447 -0.8929 -0.90125 -0.90911 -0.91606 -0.92197 -0.92677 -0.93071 -0.93528 -0.93931 -0.9426 -0.94494 -0.94622 -0.94735 -0.94879 -0.94965 -0.94971 -0.94878 -0.94679 -0.94571 -0.94428 -0.94176 -0.93756 -0.9311 -0.92258 -0.91342 -0.90142 -0.88573 -0.86549 -0.83998 -0.81054 -0.77682 -0.73745 -0.692 -0.64033 -0.58278 -0.52295 -0.45966 -0.39357 -0.32536 -0.2557 -0.18627 -0.11888 -0.052529 0.012911 0.077684 0.14195 0.2039 0.26391 0.3225 0.37976 0.43566 0.48977 0.53999 0.58745 0.63232 0.6749 0.71548 0.75342 0.78841 0.82157 0.85356 0.88519 0.91734 0.94972 0.98403 1.0219 1.0648 1.1143 1.1713 1.2359 1.3092 1.3911 1.4809 1.5776 1.6787 1.7819 1.8846 1.9842 2.0777 2.1627 2.2362 2.2969 2.3436 2.3759 2.3942 2.3994 2.3927 2.3763 2.3521 2.3222 2.2886 2.2524 2.2149 2.1772 2.1394 2.1018 2.0641 2.0259 1.9878 1.9494 1.9106 1.8711 1.8305 1.7886 1.7455 1.7008 1.6537 1.6036 1.5495 1.492 1.431 1.3664 1.2981 1.2262 1.1508 1.0736 0.99504 0.91575 0.83626 0.75657 0.67816 0.60206 0.52843 0.45712 0.38776 0.31881 0.2515 0.18511 0.11894 0.052471 -0.01492 -0.082568 -0.14848 -0.21193 -0.27229 -0.32905 -0.38303 -0.43222 -0.47628 -0.51587 -0.55188 -0.58534 -0.61763 -0.64653 -0.67227 -0.69521 -0.71576 -0.73517 -0.75286 -0.76798 -0.7812 -0.79326 -0.80474 -0.81719 -0.82831 -0.83768 -0.84538 -0.85165 -0.85731 -0.86309 -0.86791 -0.87271 -0.87846 -0.88592 -0.89619 -0.90783 -0.91942 -0.93018 -0.93939 -------------------------------------------------------------------------------- /testData/test2_output.txt: -------------------------------------------------------------------------------- 1 | -0.23703703703704, DN_OutlierInclude_n_001_mdrmd, 0.248000 2 | 0.40740740740741, DN_OutlierInclude_p_001_mdrmd, 0.342000 3 | -0.61479911484527, DN_HistogramMode_5, 0.005000 4 | -0.78225446555221, DN_HistogramMode_10, 0.003000 5 | 7.13507860878856, CO_Embed2_Dist_tau_d_expfit_meandiff, 0.283000 6 | 32.50260547693646, CO_f1ecac, 0.197000 7 | 77.00000000000000, CO_FirstMin_ac, 0.315000 8 | 1.00638907799376, CO_HistogramAMI_even_2_5, 0.017000 9 | 0.00001782472612, CO_trev_1_num, 0.008000 10 | 0.84782608695652, FC_LocalSimple_mean1_tauresrat, 0.522000 11 | 0.08029384289851, FC_LocalSimple_mean3_stderr, 0.010000 12 | 40.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 0.114000 13 | 0.31970260223048, MD_hrv_classic_pnn40, 0.002000 14 | 83.00000000000000, SB_BinaryStats_diff_longstretch0, 0.003000 15 | 88.00000000000000, SB_BinaryStats_mean_longstretch1, 0.003000 16 | 1.21058781724385, SB_MotifThree_quantile_hh, 0.047000 17 | 0.29545454545455, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 0.193000 18 | 0.75000000000000, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 0.075000 19 | 0.99313877887425, SP_Summaries_welch_rect_area_5_1, 0.077000 20 | 0.03681553890926, SP_Summaries_welch_rect_centroid, 0.074000 21 | 0.08000000000000, SB_TransitionMatrix_3ac_sumdiagcov, 0.309000 22 | 0.00000000000000, PD_PeriodicityWang_th0_01, 0.135000 23 | 24 | -------------------------------------------------------------------------------- /testData/testInf.txt: -------------------------------------------------------------------------------- 1 | inf 2 | -0.42469 3 | -0.3924 4 | -0.36389 5 | -0.33906 6 | -0.31795 7 | -0.30056 8 | -0.28692 9 | -0.27727 10 | -0.27105 11 | -0.26777 12 | -0.26678 13 | -0.26742 14 | -0.26927 15 | -0.27202 16 | -0.27529 17 | -0.27898 18 | -0.2832 19 | -0.28814 20 | -0.29431 21 | -0.30185 22 | -0.31086 23 | -0.32135 24 | -0.33326 25 | -0.3465 26 | -0.36103 27 | -0.37659 28 | -0.39297 29 | -0.40995 30 | -0.42731 31 | -0.44484 32 | -0.46226 33 | -0.47921 34 | -0.49534 35 | -0.51031 36 | -0.52382 37 | -0.53567 38 | -0.54568 39 | -0.55375 40 | -0.55984 41 | -0.56397 42 | -0.56617 43 | -0.56653 44 | -0.56511 45 | -0.56201 46 | -0.55736 47 | -0.55133 48 | -0.54419 49 | -0.53617 50 | -0.52758 51 | -0.51876 52 | -0.51004 53 | -0.50174 54 | -0.49418 55 | -0.48731 56 | -0.48128 57 | -0.47619 58 | -0.4721 59 | -0.46921 60 | -0.4674 61 | -0.46649 62 | -0.46659 63 | -0.46785 64 | -0.47045 65 | -0.4749 66 | -0.48081 67 | -0.48822 68 | -0.49726 69 | -0.50805 70 | -0.52086 71 | -0.53596 72 | -0.55266 73 | -0.57081 74 | -0.59021 75 | -0.61063 76 | -0.63238 77 | -0.65484 78 | -0.67722 79 | -0.69907 80 | -0.72004 81 | -0.73987 82 | -0.75965 83 | -0.77816 84 | -0.79527 85 | -0.8109 86 | -0.82509 87 | -0.83844 88 | -0.85159 89 | -0.86373 90 | -0.87474 91 | -0.88447 92 | -0.8929 93 | -0.90125 94 | -0.90911 95 | -0.91606 96 | -0.92197 97 | -0.92677 98 | -0.93071 99 | -0.93528 100 | -0.93931 101 | -0.9426 102 | -0.94494 103 | -0.94622 104 | -0.94735 105 | -0.94879 106 | -0.94965 107 | -0.94971 108 | -0.94878 109 | -0.94679 110 | -0.94571 111 | -0.94428 112 | -0.94176 113 | -0.93756 114 | -0.9311 115 | -0.92258 116 | -0.91342 117 | -0.90142 118 | -0.88573 119 | -0.86549 120 | -0.83998 121 | -0.81054 122 | -0.77682 123 | -0.73745 124 | -0.692 125 | -0.64033 126 | -0.58278 127 | -0.52295 128 | -0.45966 129 | -0.39357 130 | -0.32536 131 | -0.2557 132 | -0.18627 133 | -0.11888 134 | -0.052529 135 | 0.012911 136 | 0.077684 137 | 0.14195 138 | 0.2039 139 | 0.26391 140 | 0.3225 141 | 0.37976 142 | 0.43566 143 | 0.48977 144 | 0.53999 145 | 0.58745 146 | 0.63232 147 | 0.6749 148 | 0.71548 149 | 0.75342 150 | 0.78841 151 | 0.82157 152 | 0.85356 153 | 0.88519 154 | 0.91734 155 | 0.94972 156 | 0.98403 157 | 1.0219 158 | 1.0648 159 | 1.1143 160 | 1.1713 161 | 1.2359 162 | 1.3092 163 | 1.3911 164 | 1.4809 165 | 1.5776 166 | 1.6787 167 | 1.7819 168 | 1.8846 169 | 1.9842 170 | 2.0777 171 | 2.1627 172 | 2.2362 173 | 2.2969 174 | 2.3436 175 | 2.3759 176 | 2.3942 177 | 2.3994 178 | 2.3927 179 | 2.3763 180 | 2.3521 181 | 2.3222 182 | 2.2886 183 | 2.2524 184 | 2.2149 185 | 2.1772 186 | 2.1394 187 | 2.1018 188 | 2.0641 189 | 2.0259 190 | 1.9878 191 | 1.9494 192 | 1.9106 193 | 1.8711 194 | 1.8305 195 | 1.7886 196 | 1.7455 197 | 1.7008 198 | 1.6537 199 | 1.6036 200 | 1.5495 201 | 1.492 202 | 1.431 203 | 1.3664 204 | 1.2981 205 | 1.2262 206 | 1.1508 207 | 1.0736 208 | 0.99504 209 | 0.91575 210 | 0.83626 211 | 0.75657 212 | 0.67816 213 | 0.60206 214 | 0.52843 215 | 0.45712 216 | 0.38776 217 | 0.31881 218 | 0.2515 219 | 0.18511 220 | 0.11894 221 | 0.052471 222 | -0.01492 223 | -0.082568 224 | -0.14848 225 | -0.21193 226 | -0.27229 227 | -0.32905 228 | -0.38303 229 | -0.43222 230 | -0.47628 231 | -0.51587 232 | -0.55188 233 | -0.58534 234 | -0.61763 235 | -0.64653 236 | -0.67227 237 | -0.69521 238 | -0.71576 239 | -0.73517 240 | -0.75286 241 | -0.76798 242 | -0.7812 243 | -0.79326 244 | -0.80474 245 | -0.81719 246 | -0.82831 247 | -0.83768 248 | -0.84538 249 | -0.85165 250 | -0.85731 251 | -0.86309 252 | -0.86791 253 | -0.87271 254 | -0.87846 255 | -0.88592 256 | -0.89619 257 | -0.90783 258 | -0.91942 259 | -0.93018 260 | -0.93939 261 | -------------------------------------------------------------------------------- /testData/testInfMinus.txt: -------------------------------------------------------------------------------- 1 | -inf 2 | -0.42469 3 | -0.3924 4 | -0.36389 5 | -0.33906 6 | -0.31795 7 | -0.30056 8 | -0.28692 9 | -0.27727 10 | -0.27105 11 | -0.26777 12 | -0.26678 13 | -0.26742 14 | -0.26927 15 | -0.27202 16 | -0.27529 17 | -0.27898 18 | -0.2832 19 | -0.28814 20 | -0.29431 21 | -0.30185 22 | -0.31086 23 | -0.32135 24 | -0.33326 25 | -0.3465 26 | -0.36103 27 | -0.37659 28 | -0.39297 29 | -0.40995 30 | -0.42731 31 | -0.44484 32 | -0.46226 33 | -0.47921 34 | -0.49534 35 | -0.51031 36 | -0.52382 37 | -0.53567 38 | -0.54568 39 | -0.55375 40 | -0.55984 41 | -0.56397 42 | -0.56617 43 | -0.56653 44 | -0.56511 45 | -0.56201 46 | -0.55736 47 | -0.55133 48 | -0.54419 49 | -0.53617 50 | -0.52758 51 | -0.51876 52 | -0.51004 53 | -0.50174 54 | -0.49418 55 | -0.48731 56 | -0.48128 57 | -0.47619 58 | -0.4721 59 | -0.46921 60 | -0.4674 61 | -0.46649 62 | -0.46659 63 | -0.46785 64 | -0.47045 65 | -0.4749 66 | -0.48081 67 | -0.48822 68 | -0.49726 69 | -0.50805 70 | -0.52086 71 | -0.53596 72 | -0.55266 73 | -0.57081 74 | -0.59021 75 | -0.61063 76 | -0.63238 77 | -0.65484 78 | -0.67722 79 | -0.69907 80 | -0.72004 81 | -0.73987 82 | -0.75965 83 | -0.77816 84 | -0.79527 85 | -0.8109 86 | -0.82509 87 | -0.83844 88 | -0.85159 89 | -0.86373 90 | -0.87474 91 | -0.88447 92 | -0.8929 93 | -0.90125 94 | -0.90911 95 | -0.91606 96 | -0.92197 97 | -0.92677 98 | -0.93071 99 | -0.93528 100 | -0.93931 101 | -0.9426 102 | -0.94494 103 | -0.94622 104 | -0.94735 105 | -0.94879 106 | -0.94965 107 | -0.94971 108 | -0.94878 109 | -0.94679 110 | -0.94571 111 | -0.94428 112 | -0.94176 113 | -0.93756 114 | -0.9311 115 | -0.92258 116 | -0.91342 117 | -0.90142 118 | -0.88573 119 | -0.86549 120 | -0.83998 121 | -0.81054 122 | -0.77682 123 | -0.73745 124 | -0.692 125 | -0.64033 126 | -0.58278 127 | -0.52295 128 | -0.45966 129 | -0.39357 130 | -0.32536 131 | -0.2557 132 | -0.18627 133 | -0.11888 134 | -0.052529 135 | 0.012911 136 | 0.077684 137 | 0.14195 138 | 0.2039 139 | 0.26391 140 | 0.3225 141 | 0.37976 142 | 0.43566 143 | 0.48977 144 | 0.53999 145 | 0.58745 146 | 0.63232 147 | 0.6749 148 | 0.71548 149 | 0.75342 150 | 0.78841 151 | 0.82157 152 | 0.85356 153 | 0.88519 154 | 0.91734 155 | 0.94972 156 | 0.98403 157 | 1.0219 158 | 1.0648 159 | 1.1143 160 | 1.1713 161 | 1.2359 162 | 1.3092 163 | 1.3911 164 | 1.4809 165 | 1.5776 166 | 1.6787 167 | 1.7819 168 | 1.8846 169 | 1.9842 170 | 2.0777 171 | 2.1627 172 | 2.2362 173 | 2.2969 174 | 2.3436 175 | 2.3759 176 | 2.3942 177 | 2.3994 178 | 2.3927 179 | 2.3763 180 | 2.3521 181 | 2.3222 182 | 2.2886 183 | 2.2524 184 | 2.2149 185 | 2.1772 186 | 2.1394 187 | 2.1018 188 | 2.0641 189 | 2.0259 190 | 1.9878 191 | 1.9494 192 | 1.9106 193 | 1.8711 194 | 1.8305 195 | 1.7886 196 | 1.7455 197 | 1.7008 198 | 1.6537 199 | 1.6036 200 | 1.5495 201 | 1.492 202 | 1.431 203 | 1.3664 204 | 1.2981 205 | 1.2262 206 | 1.1508 207 | 1.0736 208 | 0.99504 209 | 0.91575 210 | 0.83626 211 | 0.75657 212 | 0.67816 213 | 0.60206 214 | 0.52843 215 | 0.45712 216 | 0.38776 217 | 0.31881 218 | 0.2515 219 | 0.18511 220 | 0.11894 221 | 0.052471 222 | -0.01492 223 | -0.082568 224 | -0.14848 225 | -0.21193 226 | -0.27229 227 | -0.32905 228 | -0.38303 229 | -0.43222 230 | -0.47628 231 | -0.51587 232 | -0.55188 233 | -0.58534 234 | -0.61763 235 | -0.64653 236 | -0.67227 237 | -0.69521 238 | -0.71576 239 | -0.73517 240 | -0.75286 241 | -0.76798 242 | -0.7812 243 | -0.79326 244 | -0.80474 245 | -0.81719 246 | -0.82831 247 | -0.83768 248 | -0.84538 249 | -0.85165 250 | -0.85731 251 | -0.86309 252 | -0.86791 253 | -0.87271 254 | -0.87846 255 | -0.88592 256 | -0.89619 257 | -0.90783 258 | -0.91942 259 | -0.93018 260 | -0.93939 261 | -------------------------------------------------------------------------------- /testData/testNaN.txt: -------------------------------------------------------------------------------- 1 | nan 2 | -0.42469 3 | -0.3924 4 | -0.36389 5 | -0.33906 6 | -0.31795 7 | -0.30056 8 | -0.28692 9 | -0.27727 10 | -0.27105 11 | -0.26777 12 | -0.26678 13 | -0.26742 14 | -0.26927 15 | -0.27202 16 | -0.27529 17 | -0.27898 18 | -0.2832 19 | -0.28814 20 | -0.29431 21 | -0.30185 22 | -0.31086 23 | -0.32135 24 | -0.33326 25 | -0.3465 26 | -0.36103 27 | -0.37659 28 | -0.39297 29 | -0.40995 30 | -0.42731 31 | -0.44484 32 | -0.46226 33 | -0.47921 34 | -0.49534 35 | -0.51031 36 | -0.52382 37 | -0.53567 38 | -0.54568 39 | -0.55375 40 | -0.55984 41 | -0.56397 42 | -0.56617 43 | -0.56653 44 | -0.56511 45 | -0.56201 46 | -0.55736 47 | -0.55133 48 | -0.54419 49 | -0.53617 50 | -0.52758 51 | -0.51876 52 | -0.51004 53 | -0.50174 54 | -0.49418 55 | -0.48731 56 | -0.48128 57 | -0.47619 58 | -0.4721 59 | -0.46921 60 | -0.4674 61 | -0.46649 62 | -0.46659 63 | -0.46785 64 | -0.47045 65 | -0.4749 66 | -0.48081 67 | -0.48822 68 | -0.49726 69 | -0.50805 70 | -0.52086 71 | -0.53596 72 | -0.55266 73 | -0.57081 74 | -0.59021 75 | -0.61063 76 | -0.63238 77 | -0.65484 78 | -0.67722 79 | -0.69907 80 | -0.72004 81 | -0.73987 82 | -0.75965 83 | -0.77816 84 | -0.79527 85 | -0.8109 86 | -0.82509 87 | -0.83844 88 | -0.85159 89 | -0.86373 90 | -0.87474 91 | -0.88447 92 | -0.8929 93 | -0.90125 94 | -0.90911 95 | -0.91606 96 | -0.92197 97 | -0.92677 98 | -0.93071 99 | -0.93528 100 | -0.93931 101 | -0.9426 102 | -0.94494 103 | -0.94622 104 | -0.94735 105 | -0.94879 106 | -0.94965 107 | -0.94971 108 | -0.94878 109 | -0.94679 110 | -0.94571 111 | -0.94428 112 | -0.94176 113 | -0.93756 114 | -0.9311 115 | -0.92258 116 | -0.91342 117 | -0.90142 118 | -0.88573 119 | -0.86549 120 | -0.83998 121 | -0.81054 122 | -0.77682 123 | -0.73745 124 | -0.692 125 | -0.64033 126 | -0.58278 127 | -0.52295 128 | -0.45966 129 | -0.39357 130 | -0.32536 131 | -0.2557 132 | -0.18627 133 | -0.11888 134 | -0.052529 135 | 0.012911 136 | 0.077684 137 | 0.14195 138 | 0.2039 139 | 0.26391 140 | 0.3225 141 | 0.37976 142 | 0.43566 143 | 0.48977 144 | 0.53999 145 | 0.58745 146 | 0.63232 147 | 0.6749 148 | 0.71548 149 | 0.75342 150 | 0.78841 151 | 0.82157 152 | 0.85356 153 | 0.88519 154 | 0.91734 155 | 0.94972 156 | 0.98403 157 | 1.0219 158 | 1.0648 159 | 1.1143 160 | 1.1713 161 | 1.2359 162 | 1.3092 163 | 1.3911 164 | 1.4809 165 | 1.5776 166 | 1.6787 167 | 1.7819 168 | 1.8846 169 | 1.9842 170 | 2.0777 171 | 2.1627 172 | 2.2362 173 | 2.2969 174 | 2.3436 175 | 2.3759 176 | 2.3942 177 | 2.3994 178 | 2.3927 179 | 2.3763 180 | 2.3521 181 | 2.3222 182 | 2.2886 183 | 2.2524 184 | 2.2149 185 | 2.1772 186 | 2.1394 187 | 2.1018 188 | 2.0641 189 | 2.0259 190 | 1.9878 191 | 1.9494 192 | 1.9106 193 | 1.8711 194 | 1.8305 195 | 1.7886 196 | 1.7455 197 | 1.7008 198 | 1.6537 199 | 1.6036 200 | 1.5495 201 | 1.492 202 | 1.431 203 | 1.3664 204 | 1.2981 205 | 1.2262 206 | 1.1508 207 | 1.0736 208 | 0.99504 209 | 0.91575 210 | 0.83626 211 | 0.75657 212 | 0.67816 213 | 0.60206 214 | 0.52843 215 | 0.45712 216 | 0.38776 217 | 0.31881 218 | 0.2515 219 | 0.18511 220 | 0.11894 221 | 0.052471 222 | -0.01492 223 | -0.082568 224 | -0.14848 225 | -0.21193 226 | -0.27229 227 | -0.32905 228 | -0.38303 229 | -0.43222 230 | -0.47628 231 | -0.51587 232 | -0.55188 233 | -0.58534 234 | -0.61763 235 | -0.64653 236 | -0.67227 237 | -0.69521 238 | -0.71576 239 | -0.73517 240 | -0.75286 241 | -0.76798 242 | -0.7812 243 | -0.79326 244 | -0.80474 245 | -0.81719 246 | -0.82831 247 | -0.83768 248 | -0.84538 249 | -0.85165 250 | -0.85731 251 | -0.86309 252 | -0.86791 253 | -0.87271 254 | -0.87846 255 | -0.88592 256 | -0.89619 257 | -0.90783 258 | -0.91942 259 | -0.93018 260 | -0.93939 261 | -------------------------------------------------------------------------------- /testData/testShort.txt: -------------------------------------------------------------------------------- 1 | -0.89094 2 | -0.86099 3 | -0.82438 4 | -0.78214 5 | -0.73573 6 | -0.68691 7 | -0.63754 8 | -0.58937 9 | -0.54342 10 | -0.50044 11 | -0.46082 12 | -0.42469 13 | -------------------------------------------------------------------------------- /testData/testShort_output.txt: -------------------------------------------------------------------------------- 1 | -0.58333333333333, DN_OutlierInclude_n_001_mdrmd, 0.019000 2 | 0.75000000000000, DN_OutlierInclude_p_001_mdrmd, 0.017000 3 | 0.02269949495805, DN_HistogramMode_5, 0.001000 4 | 0.02269949495805, DN_HistogramMode_10, 0.001000 5 | 0.51152503131790, CO_Embed2_Dist_tau_d_expfit_meandiff, 0.012000 6 | 2.67524184613158, CO_f1ecac, 0.004000 7 | 8.00000000000000, CO_FirstMin_ac, 0.004000 8 | 1.36615884756920, CO_HistogramAMI_even_2_5, 0.003000 9 | 0.01964378196445, CO_trev_1_num, 0.001000 10 | 0.60000000000000, FC_LocalSimple_mean1_tauresrat, 0.008000 11 | 0.05070841167817, FC_LocalSimple_mean3_stderr, 0.000000 12 | 6.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 0.002000 13 | 1.00000000000000, MD_hrv_classic_pnn40, 0.000000 14 | 1.00000000000000, SB_BinaryStats_diff_longstretch0, 0.001000 15 | 5.00000000000000, SB_BinaryStats_mean_longstretch1, 0.000000 16 | 1.49903067297901, SB_MotifThree_quantile_hh, 0.004000 17 | 0.00000000000000, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 0.007000 18 | 0.00000000000000, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 0.006000 19 | 0.00000000000000, SP_Summaries_welch_rect_area_5_1, 0.004000 20 | 0.39269908169875, SP_Summaries_welch_rect_centroid, 0.003000 21 | 0.16666666666667, SB_TransitionMatrix_3ac_sumdiagcov, 0.006000 22 | 0.00000000000000, PD_PeriodicityWang_th0_01, 0.013000 23 | 24 | -------------------------------------------------------------------------------- /testData/testSinusoid_output.txt: -------------------------------------------------------------------------------- 1 | 0.13687262547490, DN_OutlierInclude_n_001_mdrmd, 8.703000 2 | -0.13777244551090, DN_OutlierInclude_p_001_mdrmd, 6.593000 3 | 1.27292807660985, DN_HistogramMode_5, 0.041000 4 | -1.12758575737747, DN_HistogramMode_10, 0.039000 5 | 1.64629633438112, CO_Embed2_Dist_tau_d_expfit_meandiff, 8.099000 6 | 119.74079600337870, CO_f1ecac, 6.009000 7 | 2.00000000000000, CO_FirstMin_ac, 4.579000 8 | 1.07949995567938, CO_HistogramAMI_even_2_5, 0.320000 9 | -0.00017509308632, CO_trev_1_num, 0.110000 10 | 0.00625000000000, FC_LocalSimple_mean1_tauresrat, 13.819000 11 | 0.14051134209844, FC_LocalSimple_mean3_stderr, 0.190000 12 | 1.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 1.845000 13 | 0.82200000000000, MD_hrv_classic_pnn40, 0.041000 14 | 6.00000000000000, SB_BinaryStats_diff_longstretch0, 0.051000 15 | 301.00000000000000, SB_BinaryStats_mean_longstretch1, 0.046000 16 | 1.38225822030023, SB_MotifThree_quantile_hh, 1.417000 17 | 0.77551020408163, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 3.221000 18 | 0.69387755102041, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 1.645000 19 | 0.98817221358274, SP_Summaries_welch_rect_area_5_1, 2.410000 20 | 0.00997087512126, SP_Summaries_welch_rect_centroid, 2.218000 21 | 0.01005896635449, SB_TransitionMatrix_3ac_sumdiagcov, 6.992000 22 | 628.00000000000000, PD_PeriodicityWang_th0_01, 17.879000 23 | 24 | -------------------------------------------------------------------------------- /testData/test_output.txt: -------------------------------------------------------------------------------- 1 | -0.23703703703704, DN_OutlierInclude_n_001_mdrmd, 0.252000 2 | 0.40740740740741, DN_OutlierInclude_p_001_mdrmd, 0.302000 3 | -0.61479911484527, DN_HistogramMode_5, 0.003000 4 | -0.78225446555221, DN_HistogramMode_10, 0.003000 5 | 7.13507860878856, CO_Embed2_Dist_tau_d_expfit_meandiff, 0.234000 6 | 32.50260547693646, CO_f1ecac, 0.192000 7 | 77.00000000000000, CO_FirstMin_ac, 0.191000 8 | 1.00638907799376, CO_HistogramAMI_even_2_5, 0.014000 9 | 0.00001782472612, CO_trev_1_num, 0.006000 10 | 0.84782608695652, FC_LocalSimple_mean1_tauresrat, 0.388000 11 | 0.08029384289851, FC_LocalSimple_mean3_stderr, 0.007000 12 | 40.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 0.086000 13 | 0.31970260223048, MD_hrv_classic_pnn40, 0.002000 14 | 83.00000000000000, SB_BinaryStats_diff_longstretch0, 0.002000 15 | 88.00000000000000, SB_BinaryStats_mean_longstretch1, 0.003000 16 | 1.21058781724385, SB_MotifThree_quantile_hh, 0.034000 17 | 0.29545454545455, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 0.169000 18 | 0.75000000000000, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 0.073000 19 | 0.99313877887425, SP_Summaries_welch_rect_area_5_1, 0.075000 20 | 0.03681553890926, SP_Summaries_welch_rect_centroid, 0.069000 21 | 0.08000000000000, SB_TransitionMatrix_3ac_sumdiagcov, 0.198000 22 | 0.00000000000000, PD_PeriodicityWang_th0_01, 0.100000 23 | 24 | -------------------------------------------------------------------------------- /wrap_Matlab/GetAllFeatureNames.m: -------------------------------------------------------------------------------- 1 | function [featureNamesLong,featureNamesShort] = GetAllFeatureNames(doCatch24) 2 | % Retrieve all feature names from featureList.txt 3 | 4 | if nargin < 1 || isempty(doCatch24) 5 | doCatch24 = true; 6 | end 7 | %------------------------------------------------------------------------------- 8 | % Retrieve all (long) feature names from featureList.txt 9 | fid = fopen('../featureList.txt','r'); 10 | formatSpec = '%s%s'; 11 | dataIn = textscan(fid,formatSpec,'CommentStyle','#','EndOfLine','\r\n','CollectOutput',true); 12 | fclose(fid); 13 | dataIn = dataIn{1}; % Collect one big matrix of cells 14 | featureNamesLong = dataIn(:,1); 15 | featureNamesShort = dataIn(:,2); 16 | 17 | %------------------------------------------------------------------------------- 18 | % Filter out the two extra features: 'DN_Mean' and 'DN_Spread_Std' 19 | isMeanStd = strcmp(featureNamesLong,'DN_Mean') | strcmp(featureNamesLong,'DN_Spread_Std'); 20 | assert(sum(isMeanStd) == 2) 21 | if ~doCatch24 22 | keepMe = ~isMeanStd; 23 | featureNamesLong = featureNamesLong(keepMe); 24 | featureNamesShort = featureNamesShort(keepMe); 25 | fprintf(1,'Using catch22.\n'); 26 | else 27 | fprintf(1,'Using catch24.\n'); 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /wrap_Matlab/M_wrapper.c: -------------------------------------------------------------------------------- 1 | #include "mex.h" 2 | 3 | #include "CO_AutoCorr.h" 4 | #include "DN_HistogramMode_10.h" 5 | #include "DN_HistogramMode_5.h" 6 | #include "DN_Mean.h" 7 | #include "DN_Spread_Std.h" 8 | #include "DN_OutlierInclude.h" 9 | #include "FC_LocalSimple.h" 10 | #include "IN_AutoMutualInfoStats.h" 11 | #include "MD_hrv.h" 12 | #include "PD_PeriodicityWang.h" 13 | #include "SB_BinaryStats.h" 14 | #include "SB_CoarseGrain.h" 15 | #include "SB_MotifThree.h" 16 | #include "SB_TransitionMatrix.h" 17 | #include "SC_FluctAnal.h" 18 | #include "SP_Summaries.h" 19 | #include "butterworth.h" 20 | #include "fft.h" 21 | #include "helper_functions.h" 22 | #include "histcounts.h" 23 | #include "splinefit.h" 24 | #include "stats.h" 25 | 26 | void M_wrapper_double( int nlhs, mxArray *plhs[], 27 | int nrhs, const mxArray*prhs[], 28 | double (*f) (const double*, const int), int normalize ) 29 | 30 | { 31 | double *inMatrix; /* 1xN input matrix */ 32 | int ncols; 33 | double *outMatrix; /* output matrix */ 34 | 35 | // check inputs 36 | if(nrhs != 1) { 37 | mexErrMsgIdAndTxt("catch22:nrhs", 38 | "One input required."); 39 | } 40 | if(nlhs > 1) { 41 | mexErrMsgIdAndTxt("catch22:nlhs", 42 | "One output required."); 43 | } 44 | if( !mxIsDouble(prhs[0]) || 45 | mxIsComplex(prhs[0])) { 46 | mexErrMsgIdAndTxt("catch22:notDouble", 47 | "Input vector must be type double."); 48 | } 49 | if(mxGetM(prhs[0]) != 1) { 50 | mexErrMsgIdAndTxt("catch22:notRowVector", 51 | "Input must be a row vector."); 52 | } 53 | 54 | // get input 55 | inMatrix = mxGetPr(prhs[0]); 56 | ncols = mxGetN(prhs[0]); 57 | 58 | // set output 59 | plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); 60 | outMatrix = mxGetPr(plhs[0]); 61 | 62 | // calculate result 63 | if (normalize){ 64 | 65 | double * y_zscored = malloc(ncols * sizeof * y_zscored); 66 | zscore_norm2(inMatrix, ncols, y_zscored); 67 | 68 | outMatrix[0] = f(y_zscored, ncols); 69 | 70 | free(y_zscored); 71 | } 72 | else { 73 | outMatrix[0] = f(inMatrix, ncols); 74 | } 75 | 76 | return; 77 | 78 | } 79 | 80 | void M_wrapper_int( int nlhs, mxArray *plhs[], 81 | int nrhs, const mxArray*prhs[], 82 | int (*f) (const double*, const int), int normalize ) 83 | 84 | { 85 | double *inMatrix; /* 1xN input matrix */ 86 | int ncols; 87 | int *outMatrix; /* output matrix */ 88 | 89 | // check inputs 90 | if(nrhs != 1) { 91 | mexErrMsgIdAndTxt("catch22:nrhs", 92 | "One input required."); 93 | } 94 | if(nlhs > 1) { 95 | mexErrMsgIdAndTxt("catch22:nlhs", 96 | "One output required."); 97 | } 98 | if( !mxIsDouble(prhs[0]) || 99 | mxIsComplex(prhs[0])) { 100 | mexErrMsgIdAndTxt("catch22:notDouble", 101 | "Input vector must be type double."); 102 | } 103 | if(mxGetM(prhs[0]) != 1) { 104 | mexErrMsgIdAndTxt("catch22:notRowVector", 105 | "Input must be a row vector."); 106 | } 107 | 108 | // get input 109 | inMatrix = mxGetPr(prhs[0]); 110 | ncols = mxGetN(prhs[0]); 111 | 112 | // set output 113 | plhs[0] = mxCreateNumericMatrix(1,1, mxINT32_CLASS, mxREAL); 114 | outMatrix = (int*)mxGetData(plhs[0]); 115 | 116 | // calculate result 117 | if (normalize){ 118 | 119 | double * y_zscored = malloc(ncols * sizeof * y_zscored); 120 | zscore_norm2(inMatrix, ncols, y_zscored); 121 | 122 | outMatrix[0] = f(y_zscored, ncols); 123 | 124 | free(y_zscored); 125 | } 126 | else { 127 | outMatrix[0] = f(inMatrix, ncols); 128 | } 129 | 130 | return; 131 | 132 | } -------------------------------------------------------------------------------- /wrap_Matlab/M_wrapper.h: -------------------------------------------------------------------------------- 1 | #include "mex.h" 2 | 3 | extern void M_wrapper_double( int nlhs, mxArray *plhs[], 4 | int nrhs, const mxArray*prhs[], 5 | double (*f) (const double*, const int), int normalize ); 6 | 7 | extern void M_wrapper_int( int nlhs, mxArray *plhs[], 8 | int nrhs, const mxArray*prhs[], 9 | int (*f) (const double*, const int), int normalize ); -------------------------------------------------------------------------------- /wrap_Matlab/catch22_CO_Embed2_Dist_tau_d_expfit_meandiff.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_Embed2_Dist_tau_d_expfit_meandiff, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_CO_FirstMin_ac.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_int( nlhs, plhs, nrhs, prhs, &CO_FirstMin_ac, 1); 40 | 41 | return; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /wrap_Matlab/catch22_CO_HistogramAMI_even_2_5.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_HistogramAMI_even_2_5, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_CO_f1ecac.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_f1ecac, 1); 40 | 41 | return; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /wrap_Matlab/catch22_CO_trev_1_num.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_trev_1_num, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_DN_HistogramMode_10.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_HistogramMode_10, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_DN_HistogramMode_5.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_HistogramMode_5, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_DN_Mean.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_Mean, 0); 40 | 41 | return; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /wrap_Matlab/catch22_DN_OutlierInclude_n_001_mdrmd.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_OutlierInclude_n_001_mdrmd, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_DN_OutlierInclude_p_001_mdrmd.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_OutlierInclude_p_001_mdrmd, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_DN_Spread_Std.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_Spread_Std, 0); 40 | 41 | return; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /wrap_Matlab/catch22_FC_LocalSimple_mean1_tauresrat.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &FC_LocalSimple_mean1_tauresrat, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_FC_LocalSimple_mean3_stderr.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &FC_LocalSimple_mean3_stderr, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_IN_AutoMutualInfoStats_40_gaussian_fmmi.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &IN_AutoMutualInfoStats_40_gaussian_fmmi, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_MD_hrv_classic_pnn40.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &MD_hrv_classic_pnn40, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_PD_PeriodicityWang_th0_01.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_int( nlhs, plhs, nrhs, prhs, &PD_PeriodicityWang_th0_01, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SB_BinaryStats_diff_longstretch0.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_BinaryStats_diff_longstretch0, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SB_BinaryStats_mean_longstretch1.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_BinaryStats_mean_longstretch1, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SB_MotifThree_quantile_hh.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_MotifThree_quantile_hh, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SB_TransitionMatrix_3ac_sumdiagcov.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_TransitionMatrix_3ac_sumdiagcov, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SP_Summaries_welch_rect_area_5_1.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SP_Summaries_welch_rect_area_5_1, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_SP_Summaries_welch_rect_centroid.c: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * 3 | * 4 | *=================================================================*/ 5 | #include 6 | #include "mex.h" 7 | 8 | #include "M_wrapper.h" 9 | 10 | #include "CO_AutoCorr.h" 11 | #include "DN_HistogramMode_10.h" 12 | #include "DN_HistogramMode_5.h" 13 | #include "DN_Mean.h" 14 | #include "DN_Spread_Std.h" 15 | #include "DN_OutlierInclude.h" 16 | #include "FC_LocalSimple.h" 17 | #include "IN_AutoMutualInfoStats.h" 18 | #include "MD_hrv.h" 19 | #include "PD_PeriodicityWang.h" 20 | #include "SB_BinaryStats.h" 21 | #include "SB_CoarseGrain.h" 22 | #include "SB_MotifThree.h" 23 | #include "SB_TransitionMatrix.h" 24 | #include "SC_FluctAnal.h" 25 | #include "SP_Summaries.h" 26 | #include "butterworth.h" 27 | #include "fft.h" 28 | #include "helper_functions.h" 29 | #include "histcounts.h" 30 | #include "splinefit.h" 31 | #include "stats.h" 32 | 33 | void mexFunction( int nlhs, mxArray *plhs[], 34 | int nrhs, const mxArray*prhs[] ) 35 | 36 | { 37 | 38 | // check inputs and call feature C-function 39 | M_wrapper_double( nlhs, plhs, nrhs, prhs, &SP_Summaries_welch_rect_centroid, 1); 40 | 41 | return; 42 | 43 | } -------------------------------------------------------------------------------- /wrap_Matlab/catch22_all.m: -------------------------------------------------------------------------------- 1 | function [featureValues, featureNamesLong, featureNamesShort] = catch22_all(data, doCatch24) 2 | % catch22_all Calculate all catch22 (or catch24) features from an input time series 3 | % 4 | % ---INPUTS 5 | % data: a univariate time series (row vector) 6 | % catch24: set to true to also include mean and standard deviation (a total of 24 7 | % features) 8 | % ---OUTPUTS: 9 | % featureValues: computed feature values for the input data 10 | 11 | %------------------------------------------------------------------------------- 12 | %% Check inputs and set defaults 13 | %------------------------------------------------------------------------------- 14 | if nargin < 2 15 | doCatch24 = true; 16 | end 17 | 18 | %------------------------------------------------------------------------------- 19 | % Define the features: 20 | %------------------------------------------------------------------------------- 21 | [featureNamesLong,featureNamesShort] = GetAllFeatureNames(doCatch24); 22 | 23 | %------------------------------------------------------------------------------- 24 | % Compute all features from their local compiled implementations 25 | %------------------------------------------------------------------------------- 26 | numFeatures = length(featureNamesLong); 27 | featureValues = zeros(numFeatures,1); 28 | 29 | for featureInd = 1:numFeatures 30 | featureName = featureNamesLong{featureInd}; 31 | fh = str2func(['catch22_', featureName]); 32 | featureValues(featureInd) = fh(data'); 33 | end 34 | 35 | end 36 | -------------------------------------------------------------------------------- /wrap_Matlab/mexAll.m: -------------------------------------------------------------------------------- 1 | % mexAll Mex compile all .c files to be runnable from Matlab. 2 | 3 | % Path where the C implementation lives 4 | basePath = '../C'; 5 | ipath = {['-I', basePath], '-I.'}; 6 | 7 | % List all C files to include in the mex-call 8 | CFiles = dir(basePath); 9 | CFiles = CFiles(cellfun(@(x) contains(x, '.c'), {CFiles.name})); 10 | CFileNames = {CFiles.name}; 11 | 12 | % Add path to the c file names 13 | includeFiles = cellfun(@(x) fullfile(basePath, x), CFileNames, 'UniformOutput', false); 14 | 15 | % Get function names 16 | featureNames = GetAllFeatureNames(true); 17 | 18 | % mex all feature functions separately 19 | numFeatures = length(featureNames); 20 | for i = 1:numFeatures 21 | featureName = featureNames{i}; 22 | 23 | fprintf('[%u/%u]: Compiling %s...\n', i,numFeatures,featureName); 24 | mex(ipath{:}, ['catch22_', featureName,'.c'], 'M_wrapper.c', includeFiles{:}) 25 | fprintf('\n'); 26 | end 27 | 28 | fprintf(1,'All done!\n'); 29 | -------------------------------------------------------------------------------- /wrap_Matlab/testing.m: -------------------------------------------------------------------------------- 1 | %------------------------------------------------------------------------------- 2 | % Get the function names 3 | [featureNamesLong,featureNamesShort] = GetAllFeatureNames(); 4 | numFeatures = length(featureNamesLong); 5 | 6 | %------------------------------------------------------------------------------- 7 | % Get the data 8 | dataFileNames = {'../testData/test.txt', '../testData/test2.txt'}; 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 | 17 | dataFileName = dataFileNames{j}; 18 | fprintf('\n%s\n\n', dataFileName) 19 | 20 | fileID = fopen(dataFileName,'r'); 21 | data = fscanf(fileID,'%f'); 22 | 23 | for featureInd = 1:numFeatures 24 | 25 | featureName = featureNamesLong{featureInd}; 26 | fh = str2func(['catch22_', featureName]); 27 | out = fh(data'); 28 | 29 | fprintf("%s (%s): %1.6f\n", featureNamesShort{featureInd}, featureName, out); 30 | end 31 | 32 | fclose(fileID); 33 | end 34 | --------------------------------------------------------------------------------