[
  {
    "path": ".github/workflows/github-repo-stats.yml",
    "content": "name: github-repo-stats\n\non:\n  schedule:\n    # Run this once per day, towards the end of the day for keeping the most\n    # recent data point most meaningful (hours are interpreted in UTC).\n    - cron: \"0 23 * * *\"\n  workflow_dispatch: # Allow for running this manually.\n\njobs:\n  j1:\n    name: github-repo-stats\n    runs-on: ubuntu-latest\n    steps:\n      - name: run-ghrs\n        # Use latest release.\n        uses: jgehrcke/github-repo-stats@RELEASE\n        with:\n          ghtoken: ${{ secrets.ghrs_github_api_token }}\n\n\n"
  },
  {
    "path": ".gitignore",
    "content": "*.prj\n*.mexmaci64\n*.mexmaca64\n*.mat\n*.m~\n.DS_Store\n*.vscode\n*.code-workspace\n*/run_features\n"
  },
  {
    "path": "C/.gitignore",
    "content": "codegen\n*.prj\n*.mexmaci64\n*.o\nC_polished\ngenerated\nheader\ntimeSeries*\nfeatureOutputs"
  },
  {
    "path": "C/CO_AutoCorr.c",
    "content": "#if __cplusplus\n#   include <complex>\ntypedef std::complex< double > cplx;\n#else\n#   include <complex.h>\n#if defined(__GNUC__) || defined(__GNUG__)\ntypedef double complex cplx;\n#elif defined(_MSC_VER)\ntypedef _Dcomplex cplx;\n#endif\n#endif\n\n#include <math.h>\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n\n#include \"stats.h\"\n#include \"fft.h\"\n#include \"histcounts.h\"\n\n#include \"helper_functions.h\"\n\n#ifndef CMPLX\n#define CMPLX(x, y) ((cplx)((double)(x) + _Imaginary_I * (double)(y)))\n#endif\n#define pow2(x) (1 << x)\n\nint nextpow2(int n)\n{\n    n--;\n    n |= n >> 1;\n    n |= n >> 2;\n    n |= n >> 4;\n    n |= n >> 8;\n    n |= n >> 16;\n    n++;\n    return n;\n}\n\n/*\nstatic void apply_conj(cplx a[], int size, int normalize)\n{   \n    switch(normalize) {\n        case(1):\n            for (int i = 0; i < size; i++) {\n                a[i] = conj(a[i]) / size;\n            }\n            break;\n        default:\n            for (int i = 0; i < size; i++) {\n                a[i] = conj(a[i]);\n            }\n            break;\n    }\n}\n */\n\nvoid dot_multiply(cplx a[], cplx b[], int size)\n{\n    for (int i = 0; i < size; i++) {\n        a[i] = _Cmulcc(a[i], conj(b[i]));\n    }\n}\n\ndouble * CO_AutoCorr(const double y[], const int size, const int tau[], const int tau_size)\n{\n    double m, nFFT;\n    m = mean(y, size);\n    nFFT = nextpow2(size) << 1;\n\n    cplx * F = malloc(nFFT * sizeof *F);\n    cplx * tw = malloc(nFFT * sizeof *tw);\n    for (int i = 0; i < size; i++) {\n        \n        #if defined(__GNUC__) || defined(__GNUG__)\n                F[i] = CMPLX(y[i] - m, 0.0);\n        #elif defined(_MSC_VER)\n                cplx tmp = { y[i] - m, 0.0 };\n                F[i] = tmp;\n        #endif\n        \n    }\n    for (int i = size; i < nFFT; i++) {\n        #if defined(__GNUC__) || defined(__GNUG__)\n                F[i] = CMPLX(0.0, 0.0);\n        #elif defined(_MSC_VER)\n                cplx tmp = { 0.0, 0.0 };\n                F[i] = tmp; // CMPLX(0.0, 0.0);\n        #endif\n        \n    }\n    // size = nFFT;\n\n    twiddles(tw, nFFT);\n    fft(F, nFFT, tw);\n    dot_multiply(F, F, nFFT);\n    fft(F, nFFT, tw);\n    cplx divisor = F[0];\n    for (int i = 0; i < nFFT; i++) {\n        //F[i] = F[i] / divisor;\n        F[i] = _Cdivcc(F[i], divisor);\n    }\n    \n    double * out = malloc(tau_size * sizeof(out));\n    for (int i = 0; i < tau_size; i++) {\n        out[i] = creal(F[tau[i]]);\n    }\n    free(F);\n    free(tw);\n    return out;\n}\n\ndouble * co_autocorrs(const double y[], const int size)\n{\n    double m, nFFT;\n    m = mean(y, size);\n    nFFT = nextpow2(size) << 1;\n    \n    cplx * F = malloc(nFFT * 2 * sizeof *F);\n    cplx * tw = malloc(nFFT * 2 * sizeof *tw);\n    for (int i = 0; i < size; i++) {\n        \n        #if defined(__GNUC__) || defined(__GNUG__)\n                F[i] = CMPLX(y[i] - m, 0.0);\n        #elif defined(_MSC_VER)\n                cplx tmp = { y[i] - m, 0.0 };\n                F[i] = tmp;\n        #endif\n    }\n    for (int i = size; i < nFFT; i++) {\n        \n        #if defined(__GNUC__) || defined(__GNUG__)\n            F[i] = CMPLX(0.0, 0.0);\n        #elif defined(_MSC_VER)\n            cplx tmp = { 0.0, 0.0 };\n            F[i] = tmp;\n        #endif\n    }\n    //size = nFFT;\n    \n    twiddles(tw, nFFT);\n    fft(F, nFFT, tw);\n    dot_multiply(F, F, nFFT);\n    fft(F, nFFT, tw);\n    cplx divisor = F[0];\n    for (int i = 0; i < nFFT; i++) {\n        F[i] = _Cdivcc(F[i], divisor); // F[i] / divisor;\n    }\n    \n    double * out = malloc(nFFT * 2 * sizeof(out));\n    for (int i = 0; i < nFFT; i++) {\n        out[i] = creal(F[i]);\n    }\n    free(F);\n    free(tw);\n    return out;\n}\n\nint co_firstzero(const double y[], const int size, const int maxtau)\n{\n    \n    //double * autocorrs = malloc(size * sizeof * autocorrs);\n    //autocorrs = co_autocorrs(y, size);\n    \n    double * autocorrs = co_autocorrs(y, size);\n    \n    int zerocrossind = 0;\n    while(autocorrs[zerocrossind] > 0 && zerocrossind < maxtau)\n    {\n        zerocrossind += 1;\n    }\n    \n    free(autocorrs);\n    return zerocrossind;\n    \n}\n\ndouble CO_f1ecac(const double y[], const int size)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return 0;\n        }\n    }\n    \n    // compute autocorrelations\n    double * autocorrs = co_autocorrs(y, size);\n\n    // threshold to cross\n    double thresh = 1.0/exp(1);\n    \n    double out = (double)size;\n    for(int i = 0; i < size-2; i++){\n        // printf(\"i=%d autocorrs_i=%1.3f\\n\", i, autocorrs[i]);\n        if ( autocorrs[i+1] < thresh ){\n            double m = autocorrs[i+1] - autocorrs[i];\n            double dy = thresh - autocorrs[i];\n            double dx = dy/m;\n            out = ((double)i) + dx;\n            // printf(\"thresh=%1.3f AC(i)=%1.3f AC(i-1)=%1.3f m=%1.3f dy=%1.3f dx=%1.3f out=%1.3f\\n\", thresh, autocorrs[i], autocorrs[i-1], m, dy, dx, out);\n            free(autocorrs);\n            return out;\n        }\n    }\n    \n    free(autocorrs);\n    \n    return out;\n    \n}\n\ndouble CO_Embed2_Basic_tau_incircle(const double y[], const int size, const double radius, const int tau)\n{\n    int tauIntern = 0;\n    \n    if(tau < 0)\n    {\n        tauIntern = co_firstzero(y, size, size);\n    }\n    else{\n        tauIntern = tau;\n    }\n    \n    double insidecount = 0;\n    for(int i = 0; i < size-tauIntern; i++)\n    {\n        if(y[i]*y[i] + y[i+tauIntern]*y[i+tauIntern] < radius)\n        {\n            insidecount += 1;\n        }\n    }\n    \n    return insidecount/(size-tauIntern);\n}\n\ndouble CO_Embed2_Dist_tau_d_expfit_meandiff(const double y[], const int size)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    int tau = co_firstzero(y, size, size);\n    \n    //printf(\"co_firstzero ran\\n\");\n    \n    if (tau > (double)size/10){\n        tau = floor((double)size/10);\n    }\n    //printf(\"tau = %i\\n\", tau);\n    \n    double * d = malloc((size-tau) * sizeof(double));\n    for(int i = 0; i < size-tau-1; i++)\n    {\n        \n        d[i] = sqrt((y[i+1]-y[i])*(y[i+1]-y[i]) + (y[i+tau]-y[i+tau+1])*(y[i+tau]-y[i+tau+1]));\n        \n        //printf(\"d[%i]: %1.3f\\n\", i, d[i]);\n        if (isnan(d[i])){\n            free(d);\n            return NAN;\n        }\n        \n        /*\n        if(i<100)\n            printf(\"%i, y[i]=%1.3f, y[i+1]=%1.3f, y[i+tau]=%1.3f, y[i+tau+1]=%1.3f, d[i]: %1.3f\\n\", i, y[i], y[i+1], y[i+tau], y[i+tau+1], d[i]);\n         */\n    }\n    \n    //printf(\"embedding finished\\n\");\n    \n    // mean for exponential fit\n    double l = mean(d, size-tau-1);\n    \n    // count histogram bin contents\n    /*\n     int * histCounts;\n    double * binEdges;\n    int nBins = histcounts(d, size-tau-1, -1, &histCounts, &binEdges);\n     */\n    \n    int nBins = num_bins_auto(d, size-tau-1);\n    if (nBins == 0){\n        return 0;\n    }\n    int * histCounts = malloc(nBins * sizeof(double));\n    double * binEdges = malloc((nBins + 1) * sizeof(double));\n    histcounts_preallocated(d, size-tau-1, nBins, histCounts, binEdges);\n    \n    //printf(\"histcount ran\\n\");\n    \n    // normalise to probability\n    double * histCountsNorm = malloc(nBins * sizeof(double));\n    for(int i = 0; i < nBins; i++){\n        //printf(\"histCounts %i: %i\\n\", i, histCounts[i]);\n        histCountsNorm[i] = (double)histCounts[i]/(double)(size-tau-1);\n        //printf(\"histCounts norm %i: %1.3f\\n\", i, histCountsNorm[i]);\n    }\n    \n    /*\n    for(int i = 0; i < nBins; i++){\n        printf(\"histCounts[%i] = %i\\n\", i, histCounts[i]);\n    }\n    for(int i = 0; i < nBins; i++){\n        printf(\"histCountsNorm[%i] = %1.3f\\n\", i, histCountsNorm[i]);\n    }\n    for(int i = 0; i < nBins+1; i++){\n        printf(\"binEdges[%i] = %1.3f\\n\", i, binEdges[i]);\n    }\n    */\n     \n    \n    //printf(\"histcounts normed\\n\");\n    \n    double * d_expfit_diff = malloc(nBins * sizeof(double));\n    for(int i = 0; i < nBins; i++){\n        double expf = exp(-(binEdges[i] + binEdges[i+1])*0.5/l)/l;\n        if (expf < 0){\n            expf = 0;\n        }\n        d_expfit_diff[i] = fabs(histCountsNorm[i]-expf);\n        //printf(\"d_expfit_diff %i: %1.3f\\n\", i, d_expfit_diff[i]);\n    }\n    \n    double out = mean(d_expfit_diff, nBins);\n    \n    //printf(\"out = %1.6f\\n\", out);\n    //printf(\"reached free statements\\n\");\n    \n    // arrays created dynamically in function histcounts\n    free(d);\n    free(d_expfit_diff);\n    free(binEdges);\n    free(histCountsNorm);\n    free(histCounts);\n    \n    return out;\n    \n}\n\nint CO_FirstMin_ac(const double y[], const int size)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return 0;\n        }\n    }\n    \n    double * autocorrs = co_autocorrs(y, size);\n    \n    int minInd = size;\n    for(int i = 1; i < size-1; i++)\n    {\n        if(autocorrs[i] < autocorrs[i-1] && autocorrs[i] < autocorrs[i+1])\n        {\n            minInd = i;\n            break;\n        }\n    }\n    \n    free(autocorrs);\n    \n    return minInd;\n    \n}\n\ndouble CO_trev_1_num(const double y[], const int size)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    int tau = 1;\n    \n    double * diffTemp = malloc((size-1) * sizeof * diffTemp);\n    \n    for(int i = 0; i < size-tau; i++)\n    {\n        diffTemp[i] = pow(y[i+1] - y[i],3);\n    }\n    \n    double out;\n    \n    out = mean(diffTemp, size-tau);\n    \n    free(diffTemp);\n    \n    return out;\n}\n\n#define tau 2\n#define numBins 5\n\ndouble CO_HistogramAMI_even_2_5(const double y[], const int size)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    //const int tau = 2;\n    //const int numBins = 5;\n    \n    double * y1 = malloc((size-tau) * sizeof(double));\n    double * y2 = malloc((size-tau) * sizeof(double));\n    \n    for(int i = 0; i < size-tau; i++){\n        y1[i] = y[i];\n        y2[i] = y[i+tau];\n    }\n    \n    // set bin edges\n    const double maxValue = max_(y, size);\n    const double minValue = min_(y, size);\n    \n    double binStep = (maxValue - minValue + 0.2)/5;\n    //double binEdges[numBins+1] = {0};\n\tdouble binEdges[5+1] = {0};\n    for(int i = 0; i < numBins+1; i++){\n        binEdges[i] = minValue + binStep*i - 0.1;\n        // printf(\"binEdges[%i] = %1.3f\\n\", i, binEdges[i]);\n    }\n    \n    \n    // count histogram bin contents\n    int * bins1;\n    bins1 = histbinassign(y1, size-tau, binEdges, numBins+1);\n    \n    int * bins2;\n    bins2 = histbinassign(y2, size-tau, binEdges, numBins+1);\n    \n    /*\n    // debug\n    for(int i = 0; i < size-tau; i++){\n        printf(\"bins1[%i] = %i, bins2[%i] = %i\\n\", i, bins1[i], i, bins2[i]);\n    }\n    */\n    \n    // joint\n    double * bins12 = malloc((size-tau) * sizeof(double));\n    //double binEdges12[(numBins + 1) * (numBins + 1)] = {0};\n\tdouble binEdges12[(5 + 1) * (5 + 1)] = {0};    \n\n    for(int i = 0; i < size-tau; i++){\n        bins12[i] = (bins1[i]-1)*(numBins+1) + bins2[i];\n        // printf(\"bins12[%i] = %1.3f\\n\", i, bins12[i]);\n    }\n    \n    for(int i = 0; i < (numBins+1)*(numBins+1); i++){\n        binEdges12[i] = i+1;\n        // printf(\"binEdges12[%i] = %1.3f\\n\", i, binEdges12[i]);\n    }\n    \n    // fancy solution for joint histogram here\n    int * jointHistLinear;\n    jointHistLinear = histcount_edges(bins12, size-tau, binEdges12, (numBins + 1) * (numBins + 1));\n    \n    /*\n    // debug\n    for(int i = 0; i < (numBins+1)*(numBins+1); i++){\n        printf(\"jointHistLinear[%i] = %i\\n\", i, jointHistLinear[i]);\n    }\n    */\n    \n    // transfer to 2D histogram (no last bin, as in original implementation)\n    double pij[numBins][numBins];\n    int sumBins = 0;\n    for(int i = 0; i < numBins; i++){\n        for(int j = 0; j < numBins; j++){\n            pij[j][i] = jointHistLinear[i*(numBins+1)+j];\n            \n            // printf(\"pij[%i][%i]=%1.3f\\n\", i, j, pij[i][j]);\n            \n            sumBins += pij[j][i];\n        }\n    }\n    \n    // normalise\n    for(int i = 0; i < numBins; i++){\n        for(int j = 0; j < numBins; j++){\n            pij[j][i] /= sumBins;\n        }\n    }\n\n    // marginals\n    //double pi[numBins] = {0};\n\tdouble pi[5] = {0};\n    //double pj[numBins] = {0};\n\tdouble pj[5] = {0};\n    for(int i = 0; i < numBins; i++){\n        for(int j = 0; j < numBins; j++){\n            pi[i] += pij[i][j];\n            pj[j] += pij[i][j];\n            // printf(\"pij[%i][%i]=%1.3f, pi[%i]=%1.3f, pj[%i]=%1.3f\\n\", i, j, pij[i][j], i, pi[i], j, pj[j]);\n        }\n    }\n    \n    /*\n    // debug\n    for(int i = 0; i < numBins; i++){\n        printf(\"pi[%i]=%1.3f, pj[%i]=%1.3f\\n\", i, pi[i], i, pj[i]);\n    }\n    */\n    \n    // mutual information\n    double ami = 0;\n    for(int i = 0; i < numBins; i++){\n        for(int j = 0; j < numBins; j++){\n            if(pij[i][j] > 0){\n                //printf(\"pij[%i][%i]=%1.3f, pi[%i]=%1.3f, pj[%i]=%1.3f, logarg=, %1.3f, log(...)=%1.3f\\n\",\n                //       i, j, pij[i][j], i, pi[i], j, pj[j], pij[i][j]/(pi[i]*pj[j]), log(pij[i][j]/(pi[i]*pj[j])));\n                ami += pij[i][j] * log(pij[i][j]/(pj[j]*pi[i]));\n            }\n        }\n    }\n    \n    free(bins1);\n    free(bins2);\n    free(jointHistLinear);\n    \n    free(y1);\n    free(y2);\n    free(bins12);\n    \n    return ami;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "C/CO_AutoCorr.h",
    "content": "#ifndef CO_AUTOCORR_H\n#define CO_AUTOCORR_H\n\n#if __cplusplus\n#   include <complex>\ntypedef std::complex< double > cplx;\n#else\n#   include <complex.h>\n#if defined(__GNUC__) || defined(__GNUG__)\ntypedef double complex cplx;\n#elif defined(_MSC_VER)\ntypedef _Dcomplex cplx;\n#endif\n#endif\n\n#include <math.h>\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include \"stats.h\"\n#include \"fft.h\"\n\nextern int nextpow2(int n);\nextern void dot_multiply(cplx a[], cplx b[], int size);\nextern double * CO_AutoCorr(const double y[], const int size, const int tau[], const int tau_size);\nextern double * co_autocorrs(const double y[], const int size);\nextern int co_firstzero(const double y[], const int size, const int maxtau);\nextern double CO_Embed2_Basic_tau_incircle(const double y[], const int size, const double radius, const int tau);\nextern double CO_Embed2_Dist_tau_d_expfit_meandiff(const double y[], const int size);\nextern int CO_FirstMin_ac(const double y[], const int size);\nextern double CO_trev_1_num(const double y[], const int size);\nextern double CO_f1ecac(const double y[], const int size);\nextern double CO_HistogramAMI_even_2_5(const double y[], const int size);\n\n#endif\n"
  },
  {
    "path": "C/DN_HistogramMode_10.c",
    "content": "#include <math.h>\n#include <string.h>\n#include <time.h>\n#include <float.h>\n\n#include \"stats.h\"\n#include \"histcounts.h\"\n\ndouble DN_HistogramMode_10(const double y[], const int size)\n{\n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    const int nBins = 10;\n    \n    int * histCounts;\n    double * binEdges;\n    \n    histcounts(y, size, nBins, &histCounts, &binEdges);\n    \n    double maxCount = 0;\n    int numMaxs = 1;\n    double out = 0;;\n    for(int i = 0; i < nBins; i++)\n    {\n        // printf(\"binInd=%i, binCount=%i, binEdge=%1.3f \\n\", i, histCounts[i], binEdges[i]);\n        \n        if (histCounts[i] > maxCount)\n        {\n            maxCount = histCounts[i];\n            numMaxs = 1;\n            out = (binEdges[i] + binEdges[i+1])*0.5;\n        }\n        else if (histCounts[i] == maxCount){\n            \n            numMaxs += 1;\n            out += (binEdges[i] + binEdges[i+1])*0.5;\n        }\n    }\n    out = out/numMaxs;\n    \n    // arrays created dynamically in function histcounts\n    free(histCounts);\n    free(binEdges);\n    \n    return out;\n}\n\n/*\n double DN_HistogramMode_10(double y[], int size)\n {\n \n double min = DBL_MAX, max=-DBL_MAX;\n for(int i = 0; i < size; i++)\n {\n if (y[i] < min)\n {\n min = y[i];\n }\n if (y[i] > max)\n {\n max = y[i];\n }\n }\n \n double binStep = (max - min)/10;\n \n // fprintf(stdout, \"min=%f, max=%f, binStep=%f \\n\", min, max, binStep);\n \n int histCounts[10] = {0};\n for(int i = 0; i < size; i++)\n {\n int binsLeft = 10;\n int lowerInd = 0, upperInd = 10;\n while(binsLeft > 1)\n {\n int limitInd = (upperInd - lowerInd)/2 + lowerInd;\n double limit = limitInd * binStep + min;\n \n if (y[i] < limit)\n {\n upperInd = limitInd;\n }\n else\n {\n lowerInd = limitInd;\n }\n binsLeft = upperInd - lowerInd;\n }\n histCounts[lowerInd] += 1;\n }\n \n double maxCount = 0;\n int maxCountInd = 0;\n for(int i = 0; i < 10; i++)\n {\n // fprintf(stdout, \"binInd=%i, binCount=%i \\n\", i, histCounts[i]);\n \n if (histCounts[i] > maxCount)\n {\n maxCountInd = i;\n maxCount = histCounts[i];\n }\n }\n return binStep*(maxCountInd+0.5) + min;\n }\n */\n"
  },
  {
    "path": "C/DN_HistogramMode_10.h",
    "content": "#ifndef DN_HISTOGRAMMODE_10\n#define DN_HISTOGRAMMODE_10\n#include <math.h>\n#include <string.h>\n#include \"stats.h\"\n\nextern double DN_HistogramMode_10(const double y[], const int size);\n\n#endif\n"
  },
  {
    "path": "C/DN_HistogramMode_5.c",
    "content": "#include <math.h>\n#include <string.h>\n#include <time.h>\n#include <float.h>\n#include \"stats.h\"\n#include \"histcounts.h\"\n\ndouble DN_HistogramMode_5(const double y[], const int size)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    const int nBins = 5;\n    \n    int * histCounts;\n    double * binEdges;\n    \n    histcounts(y, size, nBins, &histCounts, &binEdges);\n    \n    /*\n    for(int i = 0; i < nBins; i++){\n        printf(\"histCounts[%i] = %i\\n\", i, histCounts[i]);\n    }\n    for(int i = 0; i < nBins+1; i++){\n        printf(\"binEdges[%i] = %1.3f\\n\", i, binEdges[i]);\n    }\n     */\n    \n    double maxCount = 0;\n    int numMaxs = 1;\n    double out = 0;;\n    for(int i = 0; i < nBins; i++)\n    {\n        // printf(\"binInd=%i, binCount=%i, binEdge=%1.3f \\n\", i, histCounts[i], binEdges[i]);\n        \n        if (histCounts[i] > maxCount)\n        {\n            maxCount = histCounts[i];\n            numMaxs = 1;\n            out = (binEdges[i] + binEdges[i+1])*0.5;\n        }\n        else if (histCounts[i] == maxCount){\n            \n            numMaxs += 1;\n            out += (binEdges[i] + binEdges[i+1])*0.5;\n        }\n    }\n    out = out/numMaxs;\n    \n    // arrays created dynamically in function histcounts\n    free(histCounts);\n    free(binEdges);\n    \n    return out;\n}\n\n/*\ndouble DN_HistogramMode_5(double y[], int size)\n{\n    \n    double min = DBL_MAX, max=-DBL_MAX;\n    for(int i = 0; i < size; i++)\n    {\n        if (y[i] < min)\n        {\n            min = y[i];\n        }\n        if (y[i] > max)\n        {\n            max = y[i];\n        }\n    }\n    \n    double binStep = (max - min)/5;\n    \n    // fprintf(stdout, \"min=%f, max=%f, binStep=%f \\n\", min, max, binStep);\n    \n    int histCounts[5] = {0};\n    for(int i = 0; i < size; i++)\n    {\n        int binsLeft = 5;\n        int lowerInd = 0, upperInd = 10;\n        while(binsLeft > 1)\n        {\n            int limitInd = (upperInd - lowerInd)/2 + lowerInd;\n            double limit = limitInd * binStep + min;\n            \n            if (y[i] < limit)\n            {\n                upperInd = limitInd;\n            }\n            else\n            {\n                lowerInd = limitInd;\n            }\n            binsLeft = upperInd - lowerInd;\n        }\n        histCounts[lowerInd] += 1;\n    }\n    \n    double maxCount = 0;\n    int maxCountInd = 0;\n    for(int i = 0; i < 5; i++)\n    {\n        // fprintf(stdout, \"binInd=%i, binCount=%i \\n\", i, histCounts[i]);\n        \n        if (histCounts[i] > maxCount)\n        {\n            maxCountInd = i;\n            maxCount = histCounts[i];\n        }\n    }\n    return binStep*(maxCountInd+0.5) + min;\n}\n \n */\n"
  },
  {
    "path": "C/DN_HistogramMode_5.h",
    "content": "#ifndef DN_HISTOGRAMMODE_5\n#define DN_HISTOGRAMMODE_5\n#include <math.h>\n#include <string.h>\n#include \"stats.h\"\n\nextern double DN_HistogramMode_5(const double y[], const int size);\n\n#endif\n"
  },
  {
    "path": "C/DN_Mean.c",
    "content": "#include <stdio.h>\n\ndouble DN_Mean(const double a[], const int size)\n{\n    double m = 0.0;\n    for (int i = 0; i < size; i++) {\n        m += a[i];\n    }\n    m /= size;\n    return m;\n}\n"
  },
  {
    "path": "C/DN_Mean.h",
    "content": "//\n//  Created by Trent Henderson 27 September 2021\n//\n\n#ifndef DN_MEAN\n#define DN_MEAN\n\n#include <stdio.h>\n\nextern double DN_Mean(const double a[], const int size);\n\n#endif /* DN_MEAN */"
  },
  {
    "path": "C/DN_OutlierInclude.c",
    "content": "#include <math.h>\n#include <string.h>\n#include <time.h>\n#include <float.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include \"stats.h\"\n\ndouble DN_OutlierInclude_np_001_mdrmd(const double y[], const int size, const int sign)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    double inc = 0.01;\n    int tot = 0;\n    double * yWork = malloc(size * sizeof(double));\n    \n    // apply sign and check constant time series\n    int constantFlag = 1;\n    for(int i = 0; i < size; i++)\n    {\n        if(y[i] != y[0])\n        {\n            constantFlag = 0;\n        }\n        \n        // apply sign, save in new variable\n        yWork[i] = sign*y[i];\n        \n        // count pos/ negs\n        if(yWork[i] >= 0){\n            tot += 1;\n        }\n        \n    }\n    if(constantFlag){\n        free(yWork);\n        return 0; // if constant, return 0\n    }\n    \n    // find maximum (or minimum, depending on sign)\n    double maxVal = max_(yWork, size);\n    \n    // maximum value too small? return 0\n    if(maxVal < inc){\n        free(yWork);\n        return 0;\n    }\n    \n    int nThresh = maxVal/inc + 1;\n    \n    // save the indices where y > threshold\n    double * r = malloc(size * sizeof * r);\n    \n    // save the median over indices with absolute value > threshold\n    double * msDti1 = malloc(nThresh * sizeof(double));\n    double * msDti3 = malloc(nThresh * sizeof(double));\n    double * msDti4 = malloc(nThresh * sizeof(double));\n    \n    for(int j = 0; j < nThresh; j++)\n    {\n        //printf(\"j=%i, thr=%1.3f\\n\", j, j*inc);\n        \n        int highSize = 0;\n        \n        for(int i = 0; i < size; i++)\n        {\n            if(yWork[i] >= j*inc)\n            {\n                r[highSize] = i+1;\n                //printf(\"r[%i]=%1.f \\n\", highSize, r[highSize]);\n                highSize += 1;\n            }\n        }\n        \n        // intervals between high-values\n        double * Dt_exc = malloc(highSize * sizeof(double));\n        \n        for(int i = 0; i < highSize-1; i++)\n        {\n            //printf(\"i=%i, r[i+1]=%1.f, r[i]=%1.f \\n\", i, r[i+1], r[i]);\n            Dt_exc[i] = r[i+1] - r[i];\n        }\n\n        /*\n        // median\n        double medianOut;\n        medianOut = median(r, highSize);\n        */\n         \n        msDti1[j] = mean(Dt_exc, highSize-1);\n        msDti3[j] = (highSize-1)*100.0/tot;\n        msDti4[j] = median(r, highSize) / ((double)size/2) - 1;\n        \n        //printf(\"msDti1[%i] = %1.3f, msDti13[%i] = %1.3f, msDti4[%i] = %1.3f\\n\",\n        //       j, msDti1[j], j, msDti3[j], j, msDti4[j]);\n        \n        free(Dt_exc);\n        \n    }\n    \n    int trimthr = 2;\n    int mj = 0;\n    int fbi = nThresh-1;\n    for(int i = 0; i < nThresh; i ++)\n    {\n        if (msDti3[i] > trimthr)\n        {\n            mj = i;\n        }\n        if (isnan(msDti1[nThresh-1-i]))\n        {\n            fbi = nThresh-1-i;\n        }\n    }\n    \n    double outputScalar;\n    int trimLimit = mj < fbi ? mj : fbi;\n    outputScalar = median(msDti4, trimLimit+1);\n    \n    free(r);\n    free(yWork);\n    free(msDti1);\n    free(msDti3);\n    free(msDti4);\n    \n    return outputScalar;\n}\n\ndouble DN_OutlierInclude_p_001_mdrmd(const double y[], const int size)\n{\n    return DN_OutlierInclude_np_001_mdrmd(y, size, 1.0);\n}\n\ndouble DN_OutlierInclude_n_001_mdrmd(const double y[], const int size)\n{\n    return DN_OutlierInclude_np_001_mdrmd(y, size, -1.0);\n}\n\ndouble DN_OutlierInclude_abs_001(const double y[], const int size)\n{\n    double inc = 0.01;\n    double maxAbs = 0;\n    double * yAbs = malloc(size * sizeof * yAbs);\n    \n    for(int i = 0; i < size; i++)\n    {\n        // yAbs[i] = (y[i] > 0) ? y[i] : -y[i];\n        yAbs[i] = (y[i] > 0) ? y[i] : -y[i];\n        \n        if(yAbs[i] > maxAbs)\n        {\n            maxAbs = yAbs[i];\n        }\n    }\n    \n    int nThresh = maxAbs/inc + 1;\n    \n    printf(\"nThresh = %i\\n\", nThresh);\n    \n    // save the indices where y > threshold\n    double * highInds = malloc(size * sizeof * highInds);\n    \n    // save the median over indices with absolute value > threshold\n    double * msDti3 = malloc(nThresh * sizeof * msDti3);\n    double * msDti4 = malloc(nThresh * sizeof * msDti4);\n\n    for(int j = 0; j < nThresh; j++)\n    {\n        int highSize = 0;\n        \n        for(int i = 0; i < size; i++)\n        {\n            if(yAbs[i] >= j*inc)\n            {\n                // fprintf(stdout, \"%i, \", i);\n                \n                highInds[highSize] = i;\n                highSize += 1;\n            }\n        }\n        \n        // median\n        double medianOut;\n        medianOut = median(highInds, highSize);\n        \n        msDti3[j] = (highSize-1)*100.0/size;\n        msDti4[j] = medianOut / (size/2) - 1;\n        \n    }\n    \n    int trimthr = 2;\n    int mj = 0;\n    for(int i = 0; i < nThresh; i ++)\n    {\n        if (msDti3[i] > trimthr)\n        {\n            mj = i;\n        }\n    }\n    \n    double outputScalar;\n    outputScalar = median(msDti4, mj);\n\n    free(highInds);\n    free(yAbs);\n    free(msDti4);\n    \n    return outputScalar;\n}\n"
  },
  {
    "path": "C/DN_OutlierInclude.h",
    "content": "#ifndef DN_OUTLIERINCLUDE_ABS_001\n#define DN_OUTLIERINCLUDE_ABS_001\n#include <math.h>\n#include <string.h>\n#include <time.h>\n#include <float.h>\n#include \"stats.h\"\n\nextern double DN_OutlierInclude_abs_001(const double y[], const int size);\nextern double DN_OutlierInclude_np_001_mdrmd(const double y[], const int size, const int sign);\nextern double DN_OutlierInclude_p_001_mdrmd(const double y[], const int size);\nextern double DN_OutlierInclude_n_001_mdrmd(const double y[], const int size);\n\n#endif\n"
  },
  {
    "path": "C/DN_Spread_Std.c",
    "content": "#include <stdio.h>\n#include \"stats.h\"\n\ndouble DN_Spread_Std(const double a[], const int size)\n{\n    double m = mean(a, size);\n    double sd = 0.0;\n    for (int i = 0; i < size; i++) {\n        sd += pow(a[i] - m, 2);\n    }\n    sd = sqrt(sd / (size - 1));\n    return sd;\n}\n"
  },
  {
    "path": "C/DN_Spread_Std.h",
    "content": "//\n//  Created by Trent Henderson 27 September 2021\n//\n\n#ifndef DN_SPREADSTD\n#define DN_SPREADSTD\n\n#include <stdio.h>\n\nextern double DN_Spread_Std(const double a[], const int size);\n\n#endif /* DN_SPREADSTD */"
  },
  {
    "path": "C/FC_LocalSimple.c",
    "content": "#include <math.h>\n#include <string.h>\n#include \"stats.h\"\n#include \"CO_AutoCorr.h\"\n\nstatic void abs_diff(const double a[], const int size, double b[])\n{\n    for (int i = 1; i < size; i++) {\n        b[i - 1] = fabs(a[i] - a[i - 1]);\n    }\n}\n\ndouble fc_local_simple(const double y[], const int size, const int train_length)\n{\n    double * y1 = malloc((size - 1) * sizeof *y1);\n    abs_diff(y, size, y1);\n    double m = mean(y1, size - 1);\n    free(y1);\n    return m;\n}\n\ndouble FC_LocalSimple_mean_tauresrat(const double y[], const int size, const int train_length)\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    double * res = malloc((size - train_length) * sizeof *res);\n    \n    for (int i = 0; i < size - train_length; i++)\n    {\n        double yest = 0;\n        for (int j = 0; j < train_length; j++)\n        {\n            yest += y[i+j];\n            \n        }\n        yest /= train_length;\n        \n        res[i] = y[i+train_length] - yest;\n    }\n    \n    double resAC1stZ = co_firstzero(res, size - train_length, size - train_length);\n    double yAC1stZ = co_firstzero(y, size, size);\n    double output = resAC1stZ/yAC1stZ;\n    \n    free(res);\n    return output;\n    \n}\n\ndouble FC_LocalSimple_mean_stderr(const double y[], const int size, const int train_length)\n{\n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    double * res = malloc((size - train_length) * sizeof *res);\n    \n    for (int i = 0; i < size - train_length; i++)\n    {\n        double yest = 0;\n        for (int j = 0; j < train_length; j++)\n        {\n            yest += y[i+j];\n            \n        }\n        yest /= train_length;\n        \n        res[i] = y[i+train_length] - yest;\n    }\n    \n    double output = stddev(res, size - train_length);\n    \n    free(res);\n    return output;\n    \n}\n\ndouble FC_LocalSimple_mean3_stderr(const double y[], const int size)\n{\n    return FC_LocalSimple_mean_stderr(y, size, 3);\n}\n\ndouble FC_LocalSimple_mean1_tauresrat(const double y[], const int size){\n    return FC_LocalSimple_mean_tauresrat(y, size, 1);\n}\n\ndouble FC_LocalSimple_mean_taures(const double y[], const int size, const int train_length)\n{\n    double * res = malloc((size - train_length) * sizeof *res);\n    \n    // first z-score\n    // no, assume ts is z-scored!!\n    //zscore_norm(y, size);\n    \n    for (int i = 0; i < size - train_length; i++)\n    {\n        double yest = 0;\n        for (int j = 0; j < train_length; j++)\n        {\n            yest += y[i+j];\n            \n        }\n        yest /= train_length;\n        \n        res[i] = y[i+train_length] - yest;\n    }\n    \n    int output = co_firstzero(res, size - train_length, size - train_length);\n    \n    free(res);\n    return output;\n    \n}\n\ndouble FC_LocalSimple_lfit_taures(const double y[], const int size)\n{\n    // set tau from first AC zero crossing\n    int train_length = co_firstzero(y, size, size);\n    \n    double * xReg = malloc(train_length * sizeof * xReg);\n    // double * yReg = malloc(train_length * sizeof * yReg);\n    for(int i = 1; i < train_length+1; i++)\n    {\n        xReg[i-1] = i;\n    }\n    \n    double * res = malloc((size - train_length) * sizeof *res);\n    \n    double m = 0.0, b = 0.0;\n    \n    for (int i = 0; i < size - train_length; i++)\n    {\n        linreg(train_length, xReg, y+i, &m, &b);\n        \n        // fprintf(stdout, \"i=%i, m=%f, b=%f\\n\", i, m, b);\n        \n        res[i] = y[i+train_length] - (m * (train_length+1) + b);\n    }\n    \n    int output = co_firstzero(res, size - train_length, size - train_length);\n    \n    free(res);\n    free(xReg);\n    // free(yReg);\n    \n    return output;\n    \n}\n\n\n"
  },
  {
    "path": "C/FC_LocalSimple.h",
    "content": "#ifndef FC_LOCALSIMPLE_H\n#define FC_LOCALSIMPLE_H\n#include <math.h>\n#include <string.h>\n#include \"stats.h\"\n#include \"CO_AutoCorr.h\"\n\nextern double fc_local_simple(const double y[], const int size, const int train_length);\nextern double FC_LocalSimple_mean_taures(const double y[], const int size, const int train_length);\nextern double FC_LocalSimple_lfit_taures(const double y[], const int size);\nextern double FC_LocalSimple_mean_tauresrat(const double y[], const int size, const int train_length);\nextern double FC_LocalSimple_mean1_tauresrat(const double y[], const int size);\nextern double FC_LocalSimple_mean_stderr(const double y[], const int size, const int train_length);\nextern double FC_LocalSimple_mean3_stderr(const double y[], const int size);\n\n#endif\n"
  },
  {
    "path": "C/IN_AutoMutualInfoStats.c",
    "content": "//\n//  IN_AutoMutualInfoStats.c\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 22/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n#include <math.h>\n\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"CO_AutoCorr.h\"\n#include \"stats.h\"\n\ndouble IN_AutoMutualInfoStats_40_gaussian_fmmi(const double y[], const int size)\n{\n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    // maximum time delay\n    int tau = 40;\n    \n    // don't go above half the signal length\n    if(tau > ceil((double)size/2)){\n        tau = ceil((double)size/2);\n    }\n    \n    // compute autocorrelations and compute automutual information\n    double * ami = malloc(size * sizeof(double));\n    for(int i = 0; i < tau; i++){\n        double ac = autocorr_lag(y,size, i+1);\n        ami[i] = -0.5 * log(1 - ac*ac);\n        // printf(\"ami[%i]=%1.7f\\n\", i, ami[i]);\n    }\n    \n    // find first minimum of automutual information\n    double fmmi = tau;\n    for(int i = 1; i < tau-1; i++){\n        if(ami[i] < ami[i-1] & ami[i] < ami[i+1]){\n            fmmi = i;\n            // printf(\"found minimum at %i\\n\", i);\n            break;\n        }\n    }\n    \n    free(ami);\n    \n    return fmmi;\n}\n"
  },
  {
    "path": "C/IN_AutoMutualInfoStats.h",
    "content": "//\n//  IN_AutoMutualInfoStats.h\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 22/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#ifndef IN_AutoMutualInfoStats_h\n#define IN_AutoMutualInfoStats_h\n\n#include <stdio.h>\n\nextern double IN_AutoMutualInfoStats_40_gaussian_fmmi(const double y[], const int size);\n\n#endif /* IN_AutoMutualInfoStats_h */\n"
  },
  {
    "path": "C/MD_hrv.c",
    "content": "//\n//  MD_hrv.c\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 22/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#include \"MD_hrv.h\"\n#include \"stats.h\"\n\ndouble MD_hrv_classic_pnn40(const double y[], const int size){\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    const int pNNx = 40;\n    \n    // compute diff\n    double * Dy = malloc((size-1) * sizeof(double));\n    diff(y, size, Dy);\n    \n    double pnn40 = 0;\n    for(int i = 0; i < size-1; i++){\n        if(fabs(Dy[i])*1000 > pNNx){\n            pnn40 += 1;\n        }\n    }\n    \n    free(Dy);\n    \n    return pnn40/(size-1);\n}\n\n"
  },
  {
    "path": "C/MD_hrv.h",
    "content": "//\n//  MD_hrv.h\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 22/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#ifndef MD_hrv_h\n#define MD_hrv_h\n\n#include <stdio.h>\n\nextern double MD_hrv_classic_pnn40(const double y[], const int size);\n\n#endif /* MD_hrv_h */\n"
  },
  {
    "path": "C/PD_PeriodicityWang.c",
    "content": "//\n//  PD_PeriodicityWang.c\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 28/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#include <stdlib.h>\n#include <math.h>\n\n#include \"PD_PeriodicityWang.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nint PD_PeriodicityWang_th0_01(const double * y, const int size){\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return 0;\n        }\n    }\n    \n    const double th = 0.01;\n    \n    double * ySpline = malloc(size * sizeof(double));\n    \n    // fit a spline with 3 nodes to the data\n    splinefit(y, size, ySpline);\n    \n    //printf(\"spline fit complete.\\n\");\n    \n    // subtract spline from data to remove trend\n    double * ySub = malloc(size * sizeof(double));\n    for(int i = 0; i < size; i++){\n        ySub[i] = y[i] - ySpline[i];\n        //printf(\"ySub[%i] = %1.5f\\n\", i, ySub[i]);\n    }\n    \n    // compute autocorrelations up to 1/3 of the length of the time series\n    int acmax = (int)ceil((double)size/3);\n    \n    double * acf = malloc(acmax*sizeof(double));\n    for(int tau = 1; tau <= acmax; tau++){\n        // correlation/ covariance the same, don't care for scaling (cov would be more efficient)\n        acf[tau-1] = autocov_lag(ySub, size, tau);\n        //printf(\"acf[%i] = %1.9f\\n\", tau-1, acf[tau-1]);\n    }\n    \n    //printf(\"ACF computed.\\n\");\n    \n    // find troughts and peaks\n    double * troughs = malloc(acmax * sizeof(double));\n    double * peaks = malloc(acmax * sizeof(double));\n    int nTroughs = 0;\n    int nPeaks = 0;\n    double slopeIn = 0;\n    double slopeOut = 0;\n    for(int i = 1; i < acmax-1; i ++){\n        slopeIn = acf[i] - acf[i-1];\n        slopeOut = acf[i+1] - acf[i];\n        \n        if(slopeIn < 0 & slopeOut > 0)\n        {\n            // printf(\"trough at %i\\n\", i);\n            troughs[nTroughs] = i;\n            nTroughs += 1;\n        }\n        else if(slopeIn > 0 & slopeOut < 0)\n        {\n            // printf(\"peak at %i\\n\", i);\n            peaks[nPeaks] = i;\n            nPeaks += 1;\n        }\n    }\n    \n    //printf(\"%i troughs and %i peaks found.\\n\", nTroughs, nPeaks);\n    \n    \n    // search through all peaks for one that meets the conditions:\n    // (a) a trough before it\n    // (b) difference between peak and trough is at least 0.01\n    // (c) peak corresponds to positive correlation\n    int iPeak = 0;\n    double thePeak = 0;\n    int iTrough = 0;\n    double theTrough = 0;\n    \n    int out = 0;\n    \n    for(int i = 0; i < nPeaks; i++){\n        iPeak = peaks[i];\n        thePeak = acf[iPeak];\n        \n        //printf(\"i=%i/%i, iPeak=%i, thePeak=%1.3f\\n\", i, nPeaks-1, iPeak, thePeak);\n        \n        // find trough before this peak\n        int j = -1;\n        while(troughs[j+1] < iPeak && j+1 < nTroughs){\n            // printf(\"j=%i/%i, iTrough=%i, theTrough=%1.3f\\n\", j+1, nTroughs-1, (int)troughs[j+1], acf[(int)troughs[j+1]]);\n            j++;\n        }\n        if(j == -1)\n            continue;\n        \n        iTrough = troughs[j];\n        theTrough = acf[iTrough];\n        \n        // (a) should be implicit\n        \n        // (b) different between peak and trough it as least 0.01\n        if(thePeak - theTrough < th)\n            continue;\n        \n        // (c) peak corresponds to positive correlation\n        if(thePeak < 0)\n            continue;\n        \n        // use this frequency that first fulfils all conditions.\n        out = iPeak;\n        break;\n    }\n    \n    //printf(\"Before freeing stuff.\\n\");\n    \n    free(ySpline);\n    free(ySub);\n    free(acf);\n    free(troughs);\n    free(peaks);\n    \n    return out;\n    \n}\n"
  },
  {
    "path": "C/PD_PeriodicityWang.h",
    "content": "//\n//  PD_PeriodicityWang.h\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 28/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#ifndef PD_PeriodicityWang_h\n#define PD_PeriodicityWang_h\n\n#include <stdio.h>\n\nextern int PD_PeriodicityWang_th0_01(const double * y, const int size);\n\n#endif /* PD_PeriodicityWang_h */\n"
  },
  {
    "path": "C/SB_BinaryStats.c",
    "content": "//\n//  SB_BinaryStats.c\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 22/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#include \"SB_BinaryStats.h\"\n#include \"stats.h\"\n\ndouble SB_BinaryStats_diff_longstretch0(const double y[], const int size){\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    // binarize\n    int * yBin = malloc((size-1) * sizeof(int));\n    for(int i = 0; i < size-1; i++){\n        \n        double diffTemp = y[i+1] - y[i];\n        yBin[i] = diffTemp < 0 ? 0 : 1;\n        \n        /*\n        if( i < 300)\n            printf(\"%i, y[i+1]=%1.3f, y[i]=%1.3f, yBin[i]=%i\\n\", i, y[i+1], y[i], yBin[i]);\n         */\n        \n    }\n    \n    int maxstretch0 = 0;\n    int last1 = 0;\n    for(int i = 0; i < size-1; i++){\n        if(yBin[i] == 1 | i == size-2){\n            double stretch0 = i - last1;\n            if(stretch0 > maxstretch0){\n                maxstretch0 = stretch0;\n            }\n            last1 = i;\n        }\n    }\n    \n    free(yBin);\n    \n    return maxstretch0;\n}\n\ndouble SB_BinaryStats_mean_longstretch1(const double y[], const int size){\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    // binarize\n    int * yBin = malloc((size-1) * sizeof(int));\n    double yMean = mean(y, size);\n    for(int i = 0; i < size-1; i++){\n        \n        yBin[i] = (y[i] - yMean <= 0) ? 0 : 1;\n        //printf(\"yBin[%i]=%i\\n\", i, yBin[i]);\n        \n    }\n    \n    int maxstretch1 = 0;\n    int last1 = 0;\n    for(int i = 0; i < size-1; i++){\n        if(yBin[i] == 0 | i == size-2){\n            double stretch1 = i - last1;\n            if(stretch1 > maxstretch1){\n                maxstretch1 = stretch1;\n            }\n            last1 = i;\n        }\n        \n    }\n    \n    free(yBin);\n    \n    return maxstretch1;\n}\n"
  },
  {
    "path": "C/SB_BinaryStats.h",
    "content": "//\n//  SB_BinaryStats.h\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 22/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#ifndef SB_BinaryStats_h\n#define SB_BinaryStats_h\n\n#include <stdio.h>\n\nextern double SB_BinaryStats_diff_longstretch0(const double y[], const int size);\nextern double SB_BinaryStats_mean_longstretch1(const double y[], const int size);\n\n#endif /* SB_BinaryStats_h */\n"
  },
  {
    "path": "C/SB_CoarseGrain.c",
    "content": "#include <math.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include \"stats.h\"\n#include \"helper_functions.h\"\n\nvoid sb_coarsegrain(const double y[], const int size, const char how[], const int num_groups, int labels[])\n{\n    int i, j;\n    if (strcmp(how, \"quantile\") == 1) {\n        fprintf(stdout, \"ERROR in sb_coarsegrain: unknown coarse-graining method\\n\");\n        exit(1);\n    }\n    \n    /*\n    for(int i = 0; i < size; i++){\n        printf(\"yin coarsegrain[%i]=%1.4f\\n\", i, y[i]);\n    }\n    */\n    \n    double * th = malloc((num_groups + 1) * 2 * sizeof(th));\n    double * ls = malloc((num_groups + 1) * 2 * sizeof(th));\n    linspace(0, 1, num_groups + 1, ls);\n    for (i = 0; i < num_groups + 1; i++) {\n        //double quant = quantile(y, size, ls[i]);\n        th[i] = quantile(y, size, ls[i]);\n    }\n    th[0] -= 1;\n    for (i = 0; i < num_groups; i++) {\n        for (j = 0; j < size; j++) {\n            if (y[j] > th[i] && y[j] <= th[i + 1]) {\n                labels[j] = i + 1;\n            }\n        }\n    }\n    \n    free(th);\n    free(ls);\n}\n"
  },
  {
    "path": "C/SB_CoarseGrain.h",
    "content": "#ifndef SB_COARSEGRAIN_H\n#define SB_COARSEGRAIN_H\n#include <math.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include \"stats.h\"\n#include \"helper_functions.h\"\n\nextern void sb_coarsegrain(const double y[], const int size, const char how[], const int num_groups, int labels[]);\n\n#endif\n"
  },
  {
    "path": "C/SB_MotifThree.c",
    "content": "#include <math.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include \"SB_CoarseGrain.h\"\n#include \"helper_functions.h\"\n\ndouble SB_MotifThree_quantile_hh(const double y[], const int size)\n{\n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    int tmp_idx, r_idx;\n    int dynamic_idx;\n    int alphabet_size = 3;\n    int array_size;\n    int * yt = malloc(size * sizeof(yt)); // alphabetized array\n    double hh; // output\n    double * out = malloc(124 * sizeof(out)); // output array\n    \n    // transfer to alphabet\n    sb_coarsegrain(y, size, \"quantile\", 3, yt);\n    \n    // words of length 1\n    array_size = alphabet_size;\n    int ** r1 = malloc(array_size * sizeof(*r1));\n    int * sizes_r1 = malloc(array_size * sizeof(sizes_r1));\n    double * out1 = malloc(array_size * sizeof(out1));\n    for (int i = 0; i < alphabet_size; i++) {\n        r1[i] = malloc(size * sizeof(r1[i])); // probably can be rewritten\n        // using selfresizing array for memory efficiency. Time complexity\n        // should be comparable due to ammotization.\n        r_idx = 0;\n        sizes_r1[i] = 0;\n        for (int j = 0; j < size; j++) {\n            if (yt[j] == i + 1) {\n                r1[i][r_idx++] = j;\n                sizes_r1[i]++;\n            }\n        }\n    }\n    \n    // words of length 2\n    array_size *= alphabet_size;\n    // removing last item if it is == max possible idx since later we are taking idx + 1\n    // from yt\n    for (int i = 0; i < alphabet_size; i++) {\n        if (sizes_r1[i] != 0 && r1[i][sizes_r1[i] - 1] == size - 1) {\n            //int * tmp_ar = malloc((sizes_r1[i] - 1) * sizeof(tmp_ar));\n            int* tmp_ar = malloc(sizes_r1[i] * sizeof(tmp_ar));\n            subset(r1[i], tmp_ar, 0, sizes_r1[i]);\n            memcpy(r1[i], tmp_ar, (sizes_r1[i] - 1) * sizeof(tmp_ar));\n            sizes_r1[i]--;\n            free(tmp_ar);\n        }\n    }\n    \n    /*\n    int *** r2 = malloc(array_size * sizeof(**r2));\n    int ** sizes_r2 = malloc(array_size * sizeof(*sizes_r2));\n    double ** out2 = malloc(array_size * sizeof(*out2));\n    */\n    int*** r2 = malloc(alphabet_size * sizeof(**r2));\n    int** sizes_r2 = malloc(alphabet_size * sizeof(*sizes_r2));\n    double** out2 = malloc(alphabet_size * sizeof(*out2));\n    \n\n    // allocate separately\n    for (int i = 0; i < alphabet_size; i++) {\n        r2[i] = malloc(alphabet_size * sizeof(*r2[i]));\n        sizes_r2[i] = malloc(alphabet_size * sizeof(*sizes_r2[i]));\n        //out2[i] = malloc(alphabet_size * sizeof(out2[i]));\n        out2[i] = malloc(alphabet_size * sizeof(**out2));\n        for (int j = 0; j < alphabet_size; j++) {\n            r2[i][j] = malloc(size * sizeof(*r2[i][j]));\n        }\n    }\n\n    // fill separately\n    for (int i = 0; i < alphabet_size; i++) {\n    // for (int i = 0; i < array_size; i++) {\n        //r2[i] = malloc(alphabet_size * sizeof(r2[i]));\n        //sizes_r2[i] = malloc(alphabet_size * sizeof(sizes_r2[i]));\n        //out2[i] = malloc(alphabet_size * sizeof(out2[i]));\n        for (int j = 0; j < alphabet_size; j++) {\n            //r2[i][j] = malloc(size * sizeof(r2[i][j]));\n            sizes_r2[i][j] = 0;\n            dynamic_idx = 0; //workaround as you can't just add elements to array\n            // like in python (list.append()) for example, so since for some k there will be no adding,\n            // you need to keep track of the idx at which elements will be inserted\n            for (int k = 0; k < sizes_r1[i]; k++) {\n                tmp_idx = yt[r1[i][k] + 1];\n                if (tmp_idx == (j + 1)) {\n                    r2[i][j][dynamic_idx++] = r1[i][k];\n                    sizes_r2[i][j]++;\n                    // printf(\"dynamic_idx=%i, size = %i\\n\", dynamic_idx, size);\n                }\n            }\n            double tmp = (double)sizes_r2[i][j] / ((double)(size) - (double)(1.0));\n            out2[i][j] =  tmp;\n        }\n    }\n\n    hh = 0.0;\n    for (int i = 0; i < alphabet_size; i++) {\n        hh += f_entropy(out2[i], alphabet_size);\n    }\n\n    free(yt);\n    free(out);\n    free(out1);\n\n    free(sizes_r1);\n\n    // free nested array\n    for (int i = 0; i < alphabet_size; i++) {\n        free(r1[i]);\n    }\n    free(r1);\n    // free(sizes_r1);\n    \n    for (int i = 0; i < alphabet_size; i++) {\n    //for (int i = alphabet_size - 1; i >= 0; i--) {\n\n        free(sizes_r2[i]);\n        free(out2[i]);\n    }\n\n    //for (int i = alphabet_size-1; i >= 0 ; i--) {\n    for(int i = 0; i < alphabet_size; i++) {\n        for (int j = 0; j < alphabet_size; j++) {\n            free(r2[i][j]);\n        }\n        free(r2[i]);\n    }\n    \n    free(r2);\n    free(sizes_r2);\n    free(out2);\n    \n    \n    return hh;\n    \n}\n\ndouble * sb_motifthree(const double y[], int size, const char how[])\n{\n    int tmp_idx, r_idx, i, j, k, l, m, array_size;\n    int dynamic_idx;\n    int * tmp_ar;\n    int alphabet_size = 3;\n    int out_idx = 0;\n    int * yt = malloc(size * sizeof(yt));\n    double tmp;\n    double * out = malloc(124 * sizeof(out)); // output array\n    if (strcmp(how, \"quantile\") == 0) {\n        sb_coarsegrain(y, size, how, alphabet_size, yt);\n    } else if (strcmp(how, \"diffquant\") == 0) {\n        double * diff_y = malloc((size - 1) * sizeof(diff_y));\n        diff(y, size, diff_y);\n        sb_coarsegrain(diff_y, size, how, alphabet_size, yt);\n        size--;\n    } else {\n        fprintf(stdout, \"ERROR in sb_motifthree: Unknown how method\");\n        exit(1);\n    }\n\n    // words of length 1\n    array_size = alphabet_size;\n    int ** r1 = malloc(array_size * sizeof(*r1));\n    int * sizes_r1 = malloc(array_size * sizeof(sizes_r1));\n    double * out1 = malloc(array_size * sizeof(out1));\n    for (i = 0; i < array_size; i++) {\n        r1[i] = malloc(size * sizeof(r1[i])); // probably can be rewritten\n        // using selfresizing array for memory efficiency. Time complexity\n        // should be comparable due to ammotization.\n        r_idx = 0;\n        sizes_r1[i] = 0;\n        for (j = 0; j < size; j++) {\n            if (yt[j] == i + 1) {\n                r1[i][r_idx++] = j;\n                sizes_r1[i]++;\n            }\n        }\n        tmp = (double)sizes_r1[i] / size;\n\n        out1[i] = tmp;\n        out[out_idx++] = tmp;\n    }\n    out[out_idx++] = f_entropy(out1, array_size);\n\n    // words of length 2\n    array_size *= alphabet_size;\n    // removing last item if it is == max possible idx since later we are taking idx + 1\n    // from yt\n    for (i = 0; i < alphabet_size; i++) {\n        if (sizes_r1[i] != 0 && r1[i][sizes_r1[i] - 1] == size - 1) {\n            tmp_ar = malloc((sizes_r1[i] - 1) * sizeof(tmp_ar));\n            subset(r1[i], tmp_ar, 0, sizes_r1[i]);\n            memcpy(r1[i], tmp_ar, (sizes_r1[i] - 1) * sizeof(tmp_ar));\n            sizes_r1[i]--;\n        }\n    }\n\n    int *** r2 = malloc(array_size * sizeof(**r2));\n    int ** sizes_r2 = malloc(array_size * sizeof(*sizes_r2));\n    double ** out2 = malloc(array_size * sizeof(*out2));\n    for (i = 0; i < alphabet_size; i++) {\n        r2[i] = malloc(alphabet_size * sizeof(r2[i]));\n        sizes_r2[i] = malloc(alphabet_size * sizeof(sizes_r2[i]));\n        out2[i] = malloc(alphabet_size * sizeof(out2[i]));\n        for (j = 0; j < alphabet_size; j++) {\n            r2[i][j] = malloc(size * sizeof(r2[i][j]));\n            sizes_r2[i][j] = 0;\n            dynamic_idx = 0; //workaround as you can't just add elements to array\n            // like in python (list.append()) for example, so since for some k there will be no adding,\n            // you need to keep track of the idx at which elements will be inserted\n            for (k = 0; k < sizes_r1[i]; k++) {\n                tmp_idx = yt[r1[i][k] + 1];\n                if (tmp_idx == (j + 1)) {\n                    r2[i][j][dynamic_idx++] = r1[i][k];\n                    sizes_r2[i][j]++;\n                }\n            }\n            tmp = (double)sizes_r2[i][j] / (size - 1);\n            out2[i][j] = tmp;\n            out[out_idx++] = tmp;\n        }\n    }\n    tmp = 0.0;\n    for (i = 0; i < alphabet_size; i++) {\n        tmp += f_entropy(out2[i], alphabet_size);\n    }\n    out[out_idx++] = tmp;\n\n    // words of length 3\n    array_size *= alphabet_size;\n    for (i = 0; i < alphabet_size; i++) {\n        for (j = 0; j < alphabet_size; j++) {\n            if (sizes_r2[i][j] != 0 && r2[i][j][sizes_r2[i][j] - 1] == size - 2) {\n                subset(r2[i][j], tmp_ar, 0, sizes_r2[i][j]);\n                memcpy(r2[i][j], tmp_ar, (sizes_r2[i][j] - 1) * sizeof(tmp_ar));\n                sizes_r2[i][j]--;\n            }\n        }\n    }\n\n    int **** r3 = malloc(array_size * sizeof(***r3));\n    int *** sizes_r3 = malloc(array_size * sizeof(**sizes_r3));\n    double *** out3 = malloc(array_size * sizeof(**out3));\n    for (i = 0; i < alphabet_size; i++) {\n        r3[i] = malloc(alphabet_size * sizeof(r3[i]));\n        sizes_r3[i] = malloc(alphabet_size * sizeof(sizes_r3[i]));\n        out3[i] = malloc(alphabet_size * sizeof(out3[i]));\n        for (j = 0; j < alphabet_size; j++) {\n            r3[i][j] = malloc(alphabet_size * sizeof(r3[i][j]));\n            sizes_r3[i][j] = malloc(alphabet_size * sizeof(sizes_r3[i][j]));\n            out3[i][j] = malloc(alphabet_size * sizeof(out3[i][j]));\n            for (k = 0; k < alphabet_size; k++) {\n                r3[i][j][k] = malloc(size * sizeof(r3[i][j][k]));\n                sizes_r3[i][j][k] = 0;\n                dynamic_idx = 0;\n                for (l = 0; l < sizes_r2[i][j]; l++) {\n                    tmp_idx = yt[r2[i][j][l] + 2];\n                    if (tmp_idx == (k + 1)) {\n                        r3[i][j][k][dynamic_idx++] = r2[i][j][l];\n                        sizes_r3[i][j][k]++;\n                    }\n                }\n                tmp = (double)sizes_r3[i][j][k] / (size - 2);\n                out3[i][j][k] = tmp;\n                out[out_idx++] = tmp;\n            }\n        }\n    }\n    tmp = 0.0;\n    for (i = 0; i < alphabet_size; i++) {\n        for (j = 0; j < alphabet_size; j++) {\n            tmp += f_entropy(out3[i][j], alphabet_size);\n        }\n    }\n    out[out_idx++] = tmp;\n\n    // words of length 4\n    array_size *= alphabet_size;\n    for (i = 0; i < alphabet_size; i++) {\n        for (j = 0; j < alphabet_size; j++) {\n            for (k = 0; k < alphabet_size; k++) {\n                if (sizes_r3[i][j][k] != 0 && r3[i][j][k][sizes_r3[i][j][k] - 1] == size - 3) {\n                    subset(r3[i][j][k], tmp_ar, 0, sizes_r3[i][j][k]);\n                    memcpy(r3[i][j][k], tmp_ar, (sizes_r3[i][j][k] - 1) * sizeof(tmp_ar));\n                    sizes_r3[i][j][k]--;\n                }\n            }\n        }\n    }\n\n    int ***** r4 = malloc(array_size * sizeof(****r4));\n    // just an array of pointers of array of pointers of array of pointers\n    // of array of pointers of array of ints... We need to go deeper (c)\n    int **** sizes_r4 = malloc(array_size * sizeof(***sizes_r3));\n    double **** out4 = malloc(array_size * sizeof(***out4));\n    for (i = 0; i < alphabet_size; i++) {\n        r4[i] = malloc(alphabet_size * sizeof(r4[i]));\n        sizes_r4[i] = malloc(alphabet_size * sizeof(sizes_r4[i]));\n        out4[i] = malloc(alphabet_size * sizeof(out4[i]));\n        for (j = 0; j < alphabet_size; j++) {\n            r4[i][j] = malloc(alphabet_size * sizeof(r4[i][j]));\n            sizes_r4[i][j] = malloc(alphabet_size * sizeof(sizes_r4[i][j]));\n            out4[i][j] = malloc(alphabet_size * sizeof(out4[i][j]));\n            for (k = 0; k < alphabet_size; k++) {\n                r4[i][j][k] = malloc(alphabet_size * sizeof(r4[i][j][k]));\n                sizes_r4[i][j][k] = malloc(alphabet_size * sizeof(sizes_r4[i][j][k]));\n                out4[i][j][k] = malloc(alphabet_size * sizeof(out4[i][j][k]));\n                for (l = 0; l < alphabet_size; l++) {\n                    r4[i][j][k][l] = malloc(size * sizeof(r4[i][j][k][l]));\n                    sizes_r4[i][j][k][l] = 0;\n                    dynamic_idx = 0;\n                    for (m = 0; m < sizes_r3[i][j][k]; m++) {\n                        tmp_idx = yt[r3[i][j][k][m] + 3];\n                        if (tmp_idx == l + 1) {\n                            r4[i][j][k][l][dynamic_idx++] = r3[i][j][k][m];\n                            sizes_r4[i][j][k][l]++;\n                        }\n                    }\n                    tmp = (double)sizes_r4[i][j][k][l] / (size - 3);\n                    out4[i][j][k][l] = tmp;\n                    out[out_idx++] = tmp;\n                }\n            }\n        }\n    }\n    tmp = 0.0;\n    for (i = 0; i < alphabet_size; i++) {\n        for (j = 0; j < alphabet_size; j++) {\n            for (k = 0; k < alphabet_size; k++) {\n                tmp += f_entropy(out4[i][j][k], alphabet_size);\n            }\n        }\n    }\n    out[out_idx++] = tmp;\n\n    return out;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "C/SB_MotifThree.h",
    "content": "#ifndef SB_MOTIFTHREE_H\n#define SB_MOTIFTHREE_H\n#include <math.h>\n#include <string.h>\n#include <stdlib.h>\n#include \"SB_CoarseGrain.h\"\n#include \"helper_functions.h\"\n\nextern double SB_MotifThree_quantile_hh(const double y[], const int size);\nextern double * sb_motifthree(const double y[], int size, const char how[]);\n\n#endif\n"
  },
  {
    "path": "C/SB_TransitionMatrix.c",
    "content": "//\n//  SB_TransitionMatrix.c\n//  \n//\n//  Created by Carl Henning Lubba on 23/09/2018.\n//\n\n#include \"SB_TransitionMatrix.h\"\n#include \"butterworth.h\"\n#include \"CO_AutoCorr.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"stats.h\"\n\ndouble SB_TransitionMatrix_3ac_sumdiagcov(const double y[], const int size)\n{\n    \n    // NaN and const check\n    int constant = 1;\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n        if(y[i] != y[0]){\n            constant = 0;\n        }\n    }\n    if (constant){\n        return NAN;\n    }\n    \n    const int numGroups = 3;\n    \n    int tau = co_firstzero(y, size, size);\n    \n    double * yFilt = malloc(size * sizeof(double));\n    \n    // sometimes causes problems in filt!!! needs fixing.\n    /*\n    if(tau > 1){\n        butterworthFilter(y, size, 4, 0.8/tau, yFilt);\n    }\n    */\n    \n    for(int i = 0; i < size; i++){\n        yFilt[i] = y[i];\n    }\n    \n    /*\n    for(int i = 0; i < size; i++){\n        printf(\"yFilt[%i]=%1.4f\\n\", i, yFilt[i]);\n    }\n     */\n    \n    int nDown = (size-1)/tau+1;\n    double * yDown = malloc(nDown * sizeof(double));\n    \n    for(int i = 0; i < nDown; i++){\n        yDown[i] = yFilt[i*tau];\n    }\n    \n    /*\n    for(int i = 0; i < nDown; i++){\n        printf(\"yDown[%i]=%1.4f\\n\", i, yDown[i]);\n    }\n     */\n    \n    \n    // transfer to alphabet\n    int * yCG = malloc(nDown * sizeof(double));\n    sb_coarsegrain(yDown, nDown, \"quantile\", numGroups, yCG);\n    \n    /*\n    for(int i = 0; i < nDown; i++){\n        printf(\"yCG[%i]=%i\\n\", i, yCG[i]);\n    }\n     */\n    \n    \n    double T[3][3];\n    for(int i = 0; i < numGroups; i++){\n        for(int j = 0; j < numGroups; j++){\n            T[i][j] = 0;\n        }\n    }\n    \n    // more efficient way of doing the below \n    for(int j = 0; j < nDown-1; j++){\n        T[yCG[j]-1][yCG[j+1]-1] += 1;\n    }\n    \n    /*\n    for(int i = 0; i < numGroups; i++){\n        for(int j = 0; j < numGroups; j++){\n            printf(\"%1.f, \", T[i][j]);\n        }\n        printf(\"\\n\");\n    }\n     */\n    \n    /*\n    for(int i = 0; i < numGroups; i++){\n        for(int j = 0; j < nDown-1; j++){\n            if(yCG[j] == i+1){\n                T[i][yCG[j+1]-1] += 1;\n            }\n        }\n    }\n     */\n    \n    for(int i = 0; i < numGroups; i++){\n        for(int j = 0; j < numGroups; j++){\n            T[i][j] /= (nDown-1);\n            // printf(\"T(%i, %i) = %1.3f\\n\", i, j, T[i][j]);\n            \n        }\n    }\n    \n    double column1[3] = {0};\n    double column2[3] = {0};\n    double column3[3] = {0};\n    \n    for(int i = 0; i < numGroups; i++){\n        column1[i] = T[i][0];\n        column2[i] = T[i][1];\n        column3[i] = T[i][2];\n        // printf(\"column3(%i) = %1.3f\\n\", i, column3[i]);\n    }\n    \n    double *columns[3];\n    columns[0] = &(column1[0]);\n    columns[1] = &(column2[0]);\n    columns[2] = &(column3[0]);\n    \n    \n    double COV[3][3];\n    double covTemp = 0;\n    for(int i = 0; i < numGroups; i++){\n        for(int j = i; j < numGroups; j++){\n            \n            covTemp = cov(columns[i], columns[j], 3);\n            \n            COV[i][j] = covTemp;\n            COV[j][i] = covTemp;\n            \n            // printf(\"COV(%i , %i) = %1.3f\\n\", i, j, COV[i][j]);\n        }\n    }\n    \n    double sumdiagcov = 0;\n    for(int i = 0; i < numGroups; i++){\n        sumdiagcov += COV[i][i];\n    }\n    \n    free(yFilt);\n    free(yDown);\n    free(yCG);\n    \n    return sumdiagcov;\n    \n    \n}\n"
  },
  {
    "path": "C/SB_TransitionMatrix.h",
    "content": "//\n//  SB_TransitionMatrix.h\n//  \n//\n//  Created by Carl Henning Lubba on 23/09/2018.\n//\n\n#ifndef SB_TransitionMatrix_h\n#define SB_TransitionMatrix_h\n\n#include <stdio.h>\n\nextern double SB_TransitionMatrix_3ac_sumdiagcov(const double y[], const int size);\n\n#endif /* SB_TransitionMatrix_h */\n"
  },
  {
    "path": "C/SC_FluctAnal.c",
    "content": "#include <math.h>\n#include <string.h>\n#include <time.h>\n#include <float.h>\n#include <stdio.h>\n#include \"stats.h\"\n#include \"CO_AutoCorr.h\"\n\ndouble SC_FluctAnal_2_50_1_logi_prop_r1(const double y[], const int size, const int lag, const char how[])\n{\n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    // generate log spaced tau vector\n    double linLow = log(5);\n    double linHigh = log(size/2);\n    \n    int nTauSteps = 50;\n    double tauStep = (linHigh - linLow) / (nTauSteps-1);\n    \n    int tau[50];\n    for(int i = 0; i < nTauSteps; i++)\n    {\n        tau[i] = round(exp(linLow + i*tauStep));\n    }\n    \n    // check for uniqueness, use ascending order\n    int nTau = nTauSteps;\n    for(int i = 0; i < nTauSteps-1; i++)\n    {\n        \n        while (tau[i] == tau[i+1] && i < nTau-1)\n        {\n            for(int j = i+1; j < nTauSteps-1; j++)\n            {\n                tau[j] = tau[j+1];\n            }\n            // lost one\n            nTau -= 1;\n        }\n    }\n    \n    // fewer than 12 points -> leave.\n    if(nTau < 12){\n        return 0;\n    }\n    \n    int sizeCS = size/lag;\n    double * yCS = malloc(sizeCS * sizeof(double));\n    \n    /*\n    for(int i = 0; i < 50; i++)\n    {\n        printf(\"y[%i]=%1.3f\\n\", i, y[i]);\n    }\n     */\n    \n    // transform input vector to cumsum\n    yCS[0] = y[0];\n    for(int i = 0; i < sizeCS-1; i++)\n    {\n        yCS[i+1] = yCS[i] + y[(i+1)*lag];\n        \n        /*\n        if(i<300)\n            printf(\"yCS[%i]=%1.3f\\n\", i, yCS[i]);\n         */\n    }\n    \n    //for each value of tau, cut signal into snippets of length tau, detrend and\n    \n    // first generate a support for regression (detrending)\n    double * xReg = malloc(tau[nTau-1] * sizeof * xReg);\n    for(int i = 0; i < tau[nTau-1]; i++)\n    {\n        xReg[i] = i+1;\n    }\n    \n    // iterate over taus, cut signal, detrend and save amplitude of remaining signal\n    double * F = malloc(nTau * sizeof * F);\n    for(int i = 0; i < nTau; i++)\n    {\n        int nBuffer = sizeCS/tau[i];\n        double * buffer = malloc(tau[i] * sizeof * buffer);\n        double m = 0.0, b = 0.0;\n        \n        //printf(\"tau[%i]=%i\\n\", i, tau[i]);\n        \n        F[i] = 0;\n        for(int j = 0; j < nBuffer; j++)\n        {\n            \n            //printf(\"%i th buffer\\n\", j);\n            \n            linreg(tau[i], xReg, yCS+j*tau[i], &m, &b);\n            \n            \n            for(int k = 0; k < tau[i]; k++)\n            {\n                buffer[k] = yCS[j*tau[i]+k] - (m * (k+1) + b);\n                //printf(\"buffer[%i]=%1.3f\\n\", k, buffer[k]);\n            }\n            \n            if (strcmp(how, \"rsrangefit\") == 0) {\n                F[i] += pow(max_(buffer, tau[i]) - min_(buffer, tau[i]), 2);\n            }\n            else if (strcmp(how, \"dfa\") == 0) {\n                for(int k = 0; k<tau[i]; k++){\n                    F[i] += buffer[k]*buffer[k];\n                }\n            }\n            else{\n                return 0.0;\n            }\n        }\n        \n        if (strcmp(how, \"rsrangefit\") == 0) {\n            F[i] = sqrt(F[i]/nBuffer);\n        }\n        else if (strcmp(how, \"dfa\") == 0) {\n            F[i] = sqrt(F[i]/(nBuffer*tau[i]));\n        }\n        //printf(\"F[%i]=%1.3f\\n\", i, F[i]);\n        \n        free(buffer);\n        \n    }\n    \n    double * logtt = malloc(nTau * sizeof * logtt);\n    double * logFF = malloc(nTau * sizeof * logFF);\n    int ntt = nTau;\n    \n    for (int i = 0; i < nTau; i++)\n    {\n        logtt[i] = log(tau[i]);\n        logFF[i] = log(F[i]);\n    }\n    \n    int minPoints = 6;\n    int nsserr = (ntt - 2*minPoints + 1);\n    double * sserr = malloc(nsserr * sizeof * sserr);\n    double * buffer = malloc((ntt - minPoints + 1) * sizeof * buffer);\n    for (int i = minPoints; i < ntt - minPoints + 1; i++)\n    {\n        // this could be done with less variables of course\n        double m1 = 0.0, b1 = 0.0;\n        double m2 = 0.0, b2 = 0.0;\n        \n        sserr[i - minPoints] = 0.0;\n        \n        linreg(i, logtt, logFF, &m1, &b1);\n        linreg(ntt-i+1, logtt+i-1, logFF+i-1, &m2, &b2);\n        \n        for(int j = 0; j < i; j ++)\n        {\n            buffer[j] = logtt[j] * m1 + b1 - logFF[j];\n        }\n        \n        sserr[i - minPoints] += norm_(buffer, i);\n        \n        for(int j = 0; j < ntt-i+1; j++)\n        {\n            buffer[j] = logtt[j+i-1] * m2 + b2 - logFF[j+i-1];\n        }\n        \n        sserr[i - minPoints] += norm_(buffer, ntt-i+1);\n        \n    }\n    \n    double firstMinInd = 0.0;\n    double minimum = min_(sserr, nsserr);\n    for(int i = 0; i < nsserr; i++)\n    {\n        if(sserr[i] == minimum)\n        {\n            firstMinInd = i + minPoints - 1;\n            break;\n        }\n    }\n    \n    free(yCS); // new\n    \n    free(xReg);\n    free(F);\n    free(logtt);\n    free(logFF);\n    free(sserr);\n    free(buffer);\n    \n    return (firstMinInd+1)/ntt;\n    \n}\n\ndouble SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(const double y[], const int size){\n    return SC_FluctAnal_2_50_1_logi_prop_r1(y, size, 2, \"dfa\");\n}\n\ndouble SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(const double y[], const int size){\n    return SC_FluctAnal_2_50_1_logi_prop_r1(y, size, 1, \"rsrangefit\");\n}\n\n/*\ndouble SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(double y[], int size)\n{\n    // generate log spaced tau vector\n    double linLow = log(5);\n    double linHigh = log(size/2);\n    \n    int nTauSteps = 50;\n    double tauStep = (linHigh - linLow) / (nTauSteps-1);\n    \n    int tau[50];\n    for(int i = 0; i < nTauSteps; i++)\n    {\n        tau[i] = round(exp(linLow + i*tauStep));\n    }\n    \n   // check for uniqueness, use ascending order\n    int nTau = nTauSteps;\n    for(int i = 0; i < nTauSteps; i++)\n    {\n        \n        while (tau[i] == tau[i+1] && i < nTau-1)\n        {\n            for(int j = i+1; j < nTauSteps-1; j++)\n            {\n                tau[j] = tau[j+1];\n            }\n            // lost one\n            nTau -= 1;\n        }\n    }\n    \n    // fewer than 8 points -> leave.\n    if(nTau < 8){\n        return 0;\n    }\n    \n    // transform input vector to cumsum\n    for(int i = 0; i < size-1; i++)\n    {\n        y[i+1] = y[i] + y[i+1];\n    }\n    \n    //for each value of tau, cut signal into snippets of length tau, detrend and\n    \n    // first generate a support for regression (detrending)\n    double * xReg = malloc(tau[nTau-1] * sizeof * xReg);\n    for(int i = 0; i < tau[nTau-1]; i++)\n    {\n        xReg[i] = i+1;\n    }\n    \n    // iterate over taus, cut signal, detrend and save amplitude of remaining signal\n    double * F = malloc(nTau * sizeof * F);\n    for(int i = 0; i < nTau; i++)\n    {\n        int nBuffer = size/tau[i];\n        double * buffer = malloc(tau[i] * sizeof * buffer);\n        double m = 0.0, b = 0.0;\n        \n        F[i] = 0;\n        for(int j = 0; j < nBuffer; j++)\n        {\n            \n            linreg(tau[i], xReg, y+j*tau[i], &m, &b);\n            \n            for(int k = 0; k < tau[i]; k++)\n            {\n                buffer[k] = y[j*tau[i]+k] - (m * (k+1) + b);\n            }\n            \n            F[i] += pow(max(buffer, tau[i]) - min(buffer, tau[i]), 2);\n        }\n        \n        F[i] = sqrt(F[i]/nBuffer);\n        \n        free(buffer);\n        \n    }\n    \n    double * logtt = malloc(nTau * sizeof * logtt);\n    double * logFF = malloc(nTau * sizeof * logFF);\n    int ntt = nTau;\n    \n    for (int i = 0; i < nTau; i++)\n    {\n        logtt[i] = log(tau[i]);\n        logFF[i] = log(F[i]);\n    }\n    \n    int minPoints = 6;\n    int nsserr = (ntt - 2*minPoints + 1);\n    double * sserr = malloc(nsserr * sizeof * sserr);\n    double * buffer = malloc((ntt - minPoints + 1) * sizeof * buffer);\n    for (int i = minPoints; i < ntt - minPoints + 1; i++)\n    {\n        // this could be done with less variables of course\n        double m1 = 0.0, b1 = 0.0;\n        double m2 = 0.0, b2 = 0.0;\n        \n        sserr[i - minPoints] = 0.0;\n        \n        linreg(i, logtt, logFF, &m1, &b1);\n        linreg(ntt-i+1, logtt+i-1, logFF+i-1, &m2, &b2);\n        \n        for(int j = 0; j < i; j ++)\n        {\n            buffer[j] = logtt[j] * m1 + b1 - logFF[j];\n        }\n        \n        sserr[i - minPoints] += norm(buffer, i);\n        \n        for(int j = 0; j < ntt-i+1; j++)\n        {\n            buffer[j] = logtt[j+i-1] * m2 + b2 - logFF[j+i-1];\n        }\n        \n        sserr[i - minPoints] += norm(buffer, ntt-i+1);\n        \n    }\n    \n    double firstMinInd = 0.0;\n    double minimum = min(sserr, nsserr);\n    for(int i = 0; i < nsserr; i++)\n    {\n        if(sserr[i] == minimum)\n        {\n            firstMinInd = i + minPoints - 1;\n            break;\n        }\n    }\n    \n    free(xReg);\n    free(F);\n    free(logtt);\n    free(logFF);\n    free(sserr);\n    free(buffer);\n    \n    return (firstMinInd+1)/ntt;\n    \n}\n */\n"
  },
  {
    "path": "C/SC_FluctAnal.h",
    "content": "#ifndef SC_FLUCTANAL\n#define SC_FLUCTANAL\n#include <math.h>\n#include <string.h>\n#include \"stats.h\"\n#include \"CO_AutoCorr.h\"\n\nextern double SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(const double y[], const int size);\nextern double SC_FluctAnal_2_50_1_logi_prop_r1(const double y[], const int size, const char how[]);\nextern double SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(const double y[], const int size);\n#endif\n"
  },
  {
    "path": "C/SP_Summaries.c",
    "content": "//\n//  SP_Summaries.c\n//  \n//\n//  Created by Carl Henning Lubba on 23/09/2018.\n//\n\n#include \"SP_Summaries.h\"\n#include \"CO_AutoCorr.h\"\n\nint welch(const double y[], const int size, const int NFFT, const double Fs, const double window[], const int windowWidth, double ** Pxx, double ** f){\n    \n    double dt = 1.0/Fs;\n    double df = 1.0/(nextpow2(windowWidth))/dt;\n    double m = mean(y, size);\n    \n    // number of windows, should be 1\n    int k = floor((double)size/((double)windowWidth/2.0))-1;\n    \n    // normalising scale factor\n    double KMU = k * pow(norm_(window, windowWidth),2);\n    \n    double * P = malloc(NFFT * sizeof(double));\n    for(int i = 0; i < NFFT; i++){\n        P[i] = 0;\n    }\n    \n    // fft variables\n    cplx * F = malloc(NFFT * sizeof *F);\n    cplx * tw = malloc(NFFT * sizeof *tw);\n    twiddles(tw, NFFT);\n    \n    double * xw = malloc(windowWidth * sizeof(double));\n    for(int i = 0; i<k; i++){\n        \n        // apply window\n        for(int j = 0; j<windowWidth; j++){\n            xw[j] = window[j]*y[j + (int)(i*(double)windowWidth/2.0)];\n        }\n        \n        // initialise F (\n        for (int i = 0; i < windowWidth; i++) {\n            \n\t    #if defined(__GNUC__) || defined(__GNUG__)\n\t\tcplx tmp = xw[i] - m + 0.0 * I;\n\t    #elif defined(_MSC_VER)\n\t\tcplx tmp = { xw[i] - m, 0.0 };\n\t    #endif\n            \n            \n            F[i] = tmp; // CMPLX(xw[i] - m, 0.0);\n        }\n        for (int i = windowWidth; i < NFFT; i++) {\n            // F[i] = CMPLX(0.0, 0.0);\n            //cplx tmp = { 0.0, 0.0 };\n            #if defined(__GNUC__) || defined(__GNUG__)\n\t\tcplx tmp = 0.0 + 0.0 * I;\n\t    #elif defined(_MSC_VER)\n\t\tcplx tmp = { 0.0 , 0.0 };\n\t    #endif\n            F[i] = tmp;\n        }\n        \n        fft(F, NFFT, tw);\n        /*\n        for(int i = 0; i < NFFT; i++){\n            printf(\"F1[%i] real: %1.3f, imag: %1.3f\\n\", i, creal(F[i]), cimag(F[i]));\n        }\n         */\n        \n        for(int l = 0; l < NFFT; l++){\n            P[l] += pow(cabs(F[l]),2);\n        }\n        /*\n        for(int i = 0; i < NFFT; i++){\n            printf(\"P[%i]: %1.3f\\n\", i, P[i]);\n        }\n         */\n        \n    }\n    \n    int Nout = (NFFT/2+1);\n    *Pxx = malloc(Nout * sizeof(double));\n    for(int i = 0; i < Nout; i++){\n        (*Pxx)[i] = P[i]/KMU*dt;\n        if(i>0 & i < Nout-1){\n            (*Pxx)[i] *= 2;\n        }\n    }\n    /*\n    for(int i = 0; i < Nout; i++){\n        printf(\"Pxx[%i]: %1.3f\\n\", i, Pxx[i]);\n    }\n     */\n    \n    *f = malloc(Nout * sizeof(double));\n    for(int i = 0; i < Nout; i++){\n        (*f)[i] = (double)i*df;\n    }\n    /*\n    for(int i = 0; i < Nout; i++){\n        printf(\"f[%i]: %1.3f\\n\", i, (*f)[i]);\n    }\n     */\n    \n    free(P);\n    free(F);\n    free(tw);\n    free(xw);\n    \n    return Nout;\n}\n\ndouble SP_Summaries_welch_rect(const double y[], const int size, const char what[])\n{\n    \n    // NaN check\n    for(int i = 0; i < size; i++)\n    {\n        if(isnan(y[i]))\n        {\n            return NAN;\n        }\n    }\n    \n    // rectangular window for Welch-spectrum\n    double * window = malloc(size * sizeof(double));\n    for(int i = 0; i < size; i++){\n        window[i] = 1;\n    }\n    \n    double Fs = 1.0; // sampling frequency\n    int N = nextpow2(size);\n    \n    double * S;\n    double * f;\n    \n    // compute Welch-power\n    int nWelch = welch(y, size, N, Fs, window, size, &S, &f);\n    free(window);\n    \n    // angualr frequency and spectrum on that\n    double * w = malloc(nWelch * sizeof(double));\n    double * Sw = malloc(nWelch * sizeof(double));\n    \n    double PI = 3.14159265359;\n    for(int i = 0; i < nWelch; i++){\n        w[i] = 2*PI*f[i];\n        Sw[i] = S[i]/(2*PI);\n        //printf(\"w[%i]=%1.3f, Sw[%i]=%1.3f\\n\", i, w[i], i, Sw[i]);\n        if(isinf(Sw[i]) | isinf(-Sw[i])){\n            return 0;\n        }\n    }\n    \n    double dw = w[1] - w[0];\n    \n    double * csS = malloc(nWelch * sizeof(double));\n    cumsum(Sw, nWelch, csS);\n    /*\n    for(int i=0; i<nWelch; i++)\n    {\n        printf(\"csS[%i]=%1.3f\\n\", i, csS[i]);\n    }\n     */\n    \n    double output = 0;\n    \n    if(strcmp(what, \"centroid\") == 0){\n        \n        double csSThres = csS[nWelch-1]*0.5;\n        double centroid = 0;\n        for(int i = 0; i < nWelch; i ++){\n            if(csS[i] > csSThres){\n                centroid = w[i];\n                break;\n            }\n        }\n        \n        output = centroid;\n        \n    }\n    else if(strcmp(what, \"area_5_1\") == 0){\n        double area_5_1 = 0;;\n        for(int i=0; i<nWelch/5; i++){\n            area_5_1 += Sw[i];\n        }\n        area_5_1 *= dw;\n        \n        output = area_5_1;\n    }\n    \n    free(w);\n    free(Sw);\n    free(csS);\n    free(f);\n    free(S);\n    \n    return output;\n    \n    \n}\n\n\ndouble SP_Summaries_welch_rect_area_5_1(const double y[], const int size)\n{\n    return SP_Summaries_welch_rect(y, size, \"area_5_1\");\n}\ndouble SP_Summaries_welch_rect_centroid(const double y[], const int size)\n{\n    return SP_Summaries_welch_rect(y, size, \"centroid\");\n    \n}\n"
  },
  {
    "path": "C/SP_Summaries.h",
    "content": "//\n//  SP_Summaries.h\n//  \n//\n//  Created by Carl Henning Lubba on 23/09/2018.\n//\n\n#ifndef SP_Summaries_h\n#define SP_Summaries_h\n\n#include <stdio.h>\n\nextern double SP_Summaries_welch_rect(const double y[], const int size, const char what[]);\nextern double SP_Summaries_welch_rect_area_5_1(const double y[], const int size);\nextern double SP_Summaries_welch_rect_centroid(const double y[], const int size);\n\n#endif /* SP_Summaries_h */\n"
  },
  {
    "path": "C/butterworth.c",
    "content": "//\n//  butterworth.c\n//  \n//\n//  Created by Carl Henning Lubba on 23/09/2018.\n//\n\n#include <stdlib.h>\n#include <math.h>\n\n#if __cplusplus\n#   include <complex>\ntypedef std::complex< double > cplx;\n#else\n#   include <complex.h>\n#if defined(__GNUC__) || defined(__GNUG__)\n    typedef double complex cplx;\n#elif defined(_MSC_VER)\n    typedef _Dcomplex cplx;\n#endif\n#endif\n\n#include \"helper_functions.h\"\n#include \"butterworth.h\"\n\n#ifndef CMPLX\n#define CMPLX(x, y) ((cplx)((double)(x) + _Imaginary_I * (double)(y)))\n#endif\n\nvoid poly(cplx x[], int size, cplx out[])\n{\n    /* Convert roots x to polynomial coefficients */\n    \n    // initialise\n    #if defined(__GNUC__) || defined(__GNUG__)\n        out[0] = 1;\n        for(int i=1; i<size+1; i++){\n            out[i] = 0;\n        }\n    #elif defined(_MSC_VER)\n        cplx c1 = { 1, 0 };\n        out[0] = c1;//1;\n        for(int i=1; i<size+1; i++){\n            c1._Val[0] = 0;\n            out[i] = c1;\n        }\n    #endif\n    \n    \n    cplx * outTemp = malloc((size+1)* sizeof(cplx));\n    \n    for(int i=1; i<size+1; i++){\n        \n        // save old out to not reuse some already changed values\n        //(can be done more efficiently by only saving one old value, but who cares, pole number is usually ~4)\n        for(int j=0; j<size+1; j++){\n            outTemp[j] = out[j];\n        }\n        \n        for(int j=1; j<i+1; j++){\n            \n            cplx temp1 = _Cmulcc(x[i - 1], outTemp[j - 1]);//x[i - 1] * outTemp[j - 1];\n            cplx temp2 = out[j];\n            out[j] = _Cminuscc(temp2, temp1);//x[i - 1] * outTemp[j - 1];\n            \n        }\n        \n    }\n    \n}\n\nvoid filt(double y[], int size, double a[], double b[], int nCoeffs, double out[]){\n    \n    /* Filter a signal y with the filter coefficients a and b, output to array out.*/\n    \n    double offset = y[0];\n    \n    for(int i = 0; i < size; i++){\n        out[i] = 0;\n        for(int j = 0; j < nCoeffs; j++){\n            if(i - j >= 0)\n            {\n                out[i] += b[j]*(y[i-j]-offset);\n                out[i] -= a[j]*out[i-j];\n            }\n            else{\n                out[i] += 0; //b[j]*offset; // 'padding'\n                out[i] -= 0; //a[j]*offset;\n            }\n        }\n    }\n    \n    for(int i = 0; i < size; i++){\n        out[i] += offset;\n    }\n}\n\nvoid reverse_array(double a[], int size){\n    \n    /* Reverse the order of the elements in an array. Write back into the input array.*/\n    \n    double temp;\n    for(int i = 0; i < size/2; i++){\n        temp = a[i];\n        a[i] = a[size-i-1];\n        a[size-1-i] = temp;\n        /*\n        printf(\"indFrom = %i, indTo = %i\\n\", i, size-1-i);\n        for(int i=0; i < size; i++){\n            printf(\"reversed[%i]=%1.3f\\n\", i, a[i]);\n        }\n         */\n    }\n}\n\nvoid filt_reverse(double y[], int size, double a[], double b[], int nCoeffs, double out[]){\n    \n    /* Filter a signal y with the filter coefficients a and b _in reverse order_, output to array out.*/\n    \n    double * yTemp = malloc(size * sizeof(double));\n    for(int i = 0; i < size; i++){\n        yTemp[i] = y[i];\n    }\n    \n    /*\n    for(int i=0; i < size; i++){\n        printf(\"yTemp[%i]=%1.3f\\n\", i, yTemp[i]);\n    }\n     */\n    \n    reverse_array(yTemp, size);\n    \n    /*\n    for(int i=0; i < size; i++){\n        printf(\"reversed[%i]=%1.3f\\n\", i, yTemp[i]);\n    }\n     */\n    \n    double offset = yTemp[0];\n    \n    for(int i = 0; i < size; i++){\n        out[i] = 0;\n        for(int j = 0; j < nCoeffs; j++){\n            if(i - j >= 0)\n            {\n                out[i] += b[j]*(yTemp[i-j]-offset);\n                out[i] -= a[j]*out[i-j];\n            }\n            else{\n                out[i] += 0; //b[j]*offset; // 'padding'\n                out[i] -= 0; //a[j]*offset;\n            }\n        }\n    }\n    \n    for(int i = 0; i < size; i++){\n        out[i] += offset;\n    }\n    \n    reverse_array(out, size);\n    \n    free(yTemp);\n    \n}\n\n/*\nvoid butterworthFilter(const double y[], int size, const int nPoles, const double W, double out[]){\n    \n    double PI = 3.14159265359;\n\n    double V = tan(W * PI/2);\n    cplx * Q = malloc(nPoles * sizeof(cplx));\n    \n    for(int i = 0; i<nPoles; i++){\n        cplx tmp1 = { 0, PI / 2 };\n        cplx tmp2 = { nPoles, 0 };\n        Q[i] =  conj(cexp((_Cdivcc(tmp1, tmp2)) * ((2 + nPoles - 1) + 2*i)));\n        //printf(\"Q[%i]= real %1.3f imag %1.3f\\n\", i, creal(Q[i]), cimag(Q[i]));\n        \n    }\n    \n    double Sg = pow(V,nPoles);\n    cplx * Sp = malloc(nPoles * sizeof(cplx));\n    \n    for(int i = 0; i<nPoles; i++){\n        Sp[i] = V * Q[i];\n        //printf(\"Sp[%i]= real %1.3f imag %1.3f\\n\", i, creal(Sp[i]), cimag(Sp[i]));\n    }\n    \n    cplx * P = malloc(nPoles * sizeof(cplx));\n    cplx * Z = malloc(nPoles * sizeof(cplx));\n    \n    cplx prod1mSp = 1; // %1 - Sp[0];\n    \n    // Bilinear transform for poles, fill zeros, compute products\n    for(int i = 0; i<nPoles; i++){\n        P[i] = (1 + Sp[i]) / (1 - Sp[i]);\n        Z[i] = -1;\n        \n        // printf(\"P[%i]= real %1.3f imag %1.3f\\n\", i, creal(P[i]), cimag(P[i]));\n        // printf(\"Z[%i]= real %1.3f imag %1.3f\\n\", i, creal(Z[i]), cimag(Z[i]));\n        \n        prod1mSp *= (1 - Sp[i]);\n        \n        //if(i > 0){\n        //    prod1mSp *= (1 - Sp[i]);\n        //}\n         \n    }\n\n    double G = creal(Sg / prod1mSp);\n    \n    cplx * Zpoly = malloc((nPoles+1) * sizeof(cplx));\n    cplx * Ppoly = malloc((nPoles+1) * sizeof(cplx));\n    \n    // polynomial coefficients from poles and zeros for filtering\n    poly(Z, nPoles, Zpoly);\n    \n    //for(int i = 0; i < nPoles+1; i++){\n    //    printf(\"Zpoly[%i]= %1.3f + %1.3f i\\n\", i, creal(Zpoly[i]), cimag(Zpoly[i]));\n    //}\n    \n    poly(P, nPoles, Ppoly);\n    \n    //for(int i = 0; i < nPoles+1; i++){\n    //    printf(\"Ppoly[%i]= %1.3f + %1.3f i\\n\", i, creal(Ppoly[i]), cimag(Ppoly[i]));\n    //}\n    \n    \n    // coeffs for filtering\n    double * b = malloc((nPoles+1) * sizeof(double)); // zeros\n    double * a = malloc((nPoles+1) * sizeof(double)); // poles\n    \n    for(int i = 0; i<nPoles+1; i++){\n        b[i] = G * creal(Zpoly[i]);\n        a[i] = creal(Ppoly[i]);\n        //printf(\"a[%i]=%1.8f, b[%i]=\u0010%1.8f\\n\", i, a[i], i, b[i]);\n    }\n    \n    \n    // this is the simple solution, one forward filtering, phase not preserved.\n    //filt(y, size, a, b, nPoles, out);\n    \n    // from here, better way of filtering. Forward and backward.\n    // pad to both sides to avoid end-transients\n    int nfact = 3*nPoles;\n    double * yPadded = malloc((size + 2*nfact) * sizeof(double));\n    \n    for(int i = 0; i < nfact; i ++)\n    {\n        yPadded[i] = 2*y[0] - y[nfact-i];\n        yPadded[nfact + size + i] = 2*y[size-1] - y[size-2-i];\n        \n    }\n    for(int i = 0; i < size; i ++)\n    {\n        yPadded[nfact+i] = y[i];\n    }\n    \n    // filter in both directions\n    double * outPadded = malloc((size + 2*nfact) * sizeof(double));\n    filt(yPadded, (size + 2*nfact), a, b, nPoles, outPadded);\n    \n    //for(int i=0; i < (size + 2*nfact); i++){\n    //    printf(\"filtPadded[%i]=%1.3f\\n\", i, outPadded[i]);\n    //}\n     \n    filt_reverse(outPadded, (size + 2*nfact), a, b, nPoles, outPadded);\n    \n    \n    // for(int i=0; i < (size + 2*nfact); i++){\n    //    printf(\"filtfiltPadded[%i]=%1.3f\\n\", i, outPadded[i]);\n    //}\n     \n     \n    for(int i = 0; i < size; i ++){\n        out[i] = outPadded[nfact + i];\n    }\n    \n    \n    //for(int i=0; i < size; i++){\n    //    printf(\"out[%i]=%1.3f\\n\", i, out[i]);\n    //}\n     \n    \n    free(Q);\n    free(Sp);\n    free(P);\n    free(Z);\n    free(a);\n    free(b);\n    free(Zpoly);\n    free(Ppoly);\n    free(outPadded);\n    \n}\n\n*/"
  },
  {
    "path": "C/butterworth.h",
    "content": "//\n//  butterworth.h\n//  \n//\n//  Created by Carl Henning Lubba on 23/09/2018.\n//\n\n#ifndef butterworth_h\n#define butterworth_h\n\n#include <stdio.h>\n\nextern void butterworthFilter(const double y[], const int size, const int nPoles, const double W, double out[]);\n\n#endif /* butterworth_h */\n"
  },
  {
    "path": "C/fft.c",
    "content": "#include <stdlib.h>\n#include <string.h>\n#include <math.h>\n\n#if __cplusplus\n#   include <complex>\ntypedef std::complex< double > cplx;\n#else\n#   include <complex.h>\n#if defined(__GNUC__) || defined(__GNUG__)\ntypedef double complex cplx;\n#elif defined(_MSC_VER)\ntypedef _Dcomplex cplx;\n#endif\n#endif\n\n#ifndef CMPLX\n#define CMPLX(x, y) ((cplx)((double)(x) + _Imaginary_I * (double)(y)))\n#endif\n\n#include \"helper_functions.h\"\n\nvoid twiddles(cplx a[], int size)\n{\n\n    double PI = 3.14159265359;\n\n    for (int i = 0; i < size; i++) {\n        // cplx tmp = { 0, -PI * i / size };\n        #if defined(__GNUC__) || defined(__GNUG__)\n\t    cplx tmp = 0.0  - PI * i / size * I;\n        #elif defined(_MSC_VER)\n\t    cplx tmp = {0.0, -PI * i / size };\n        #endif\n        a[i] = cexp(tmp);\n        //a[i] = cexp(-I * M_PI * i / size);\n    }\n}\n\nstatic void _fft(cplx a[], cplx out[], int size, int step, cplx tw[])\n{   \n    if (step < size) {\n        _fft(out, a, size, step * 2, tw);\n        _fft(out + step, a + step, size, step * 2, tw);\n\n        for (int i = 0; i < size; i += 2 * step) {\n            //cplx t = tw[i] * out[i + step];\n            cplx t = _Cmulcc(tw[i], out[i + step]);\n            a[i / 2] = _Caddcc(out[i], t);\n            a[(i + size) / 2] = _Cminuscc(out[i], t);\n        }\n    }\n}\n\nvoid fft(cplx a[], int size, cplx tw[])\n{\n    cplx * out = malloc(size * sizeof(cplx));\n    memcpy(out, a, size * sizeof(cplx));\n    _fft(a, out, size, 1, tw);\n    free(out);\n}\n"
  },
  {
    "path": "C/fft.h",
    "content": "#ifndef FFT_H\n#define FFT_H\n//#include <complex.h>\n\n#if __cplusplus\n#   include <complex>\n    typedef std::complex< double > cplx;\n#else\n#   include <complex.h>\n#if defined(__GNUC__) || defined(__GNUG__)\ntypedef double complex cplx;\n#elif defined(_MSC_VER)\ntypedef _Dcomplex cplx;\n#endif\n#endif\n\n#include <stdlib.h>\n#include <string.h>\n#ifndef CMPLX\n#define CMPLX(x, y) ((cplx)((double)(x) + _Complex_I * (double)(y)))\n#endif\nextern void twiddles(cplx a[], int size);\n// extern void _fft(cplx a[], cplx out[], int size, int step, cplx tw[]);\nextern void fft(cplx a[], int size, cplx tw[]);\nextern void ifft(cplx a[], int size, cplx tw[]);\n#endif\n"
  },
  {
    "path": "C/helper_functions.c",
    "content": "#if __cplusplus\n#   include <complex>\ntypedef std::complex< double > cplx;\n#else\n#   include <complex.h>\n#if defined(__GNUC__) || defined(__GNUG__)\ntypedef double complex cplx;\n#elif defined(_MSC_VER)\ntypedef _Dcomplex cplx;\n#endif\n#endif\n\n#include <math.h>\n#include <string.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include \"stats.h\"\n\n// compare function for qsort, for array of doubles\nstatic int compare (const void * a, const void * b)\n{\n    if (*(double*)a < *(double*)b) {\n        return -1;\n    } else if (*(double*)a > *(double*)b) {\n        return 1;\n    } else {\n        return 0;\n    }\n}\n\n// wrapper for qsort for array of doubles. Sorts in-place\nvoid sort(double y[], int size)\n{\n    qsort(y, size, sizeof(*y), compare);\n}\n\n// linearly spaced vector\nvoid linspace(double start, double end, int num_groups, double out[])\n{\n    double step_size = (end - start) / (num_groups - 1);\n    for (int i = 0; i < num_groups; i++) {\n        out[i] = start;\n        start += step_size;\n    }\n    return;\n}\n\ndouble quantile(const double y[], const int size, const double quant)\n{   \n    double quant_idx, q, value;\n    int idx_left, idx_right;\n    double * tmp = malloc(size * sizeof(*y));\n    memcpy(tmp, y, size * sizeof(*y));\n    sort(tmp, size);\n    \n    /*\n    for(int i=0; i < size; i++){\n        printf(\"y[%i]=%1.4f\\n\", i, y[i]);\n    }\n    for(int i=0; i < size; i++){\n        printf(\"sorted[%i]=%1.4f\\n\", i, tmp[i]);\n    }\n     */\n    \n    // out of range limit?\n    q = 0.5 / size;\n    if (quant < q) {\n        value = tmp[0]; // min value\n        free(tmp);\n        return value; \n    } else if (quant > (1 - q)) {\n        value = tmp[size - 1]; // max value\n        free(tmp);\n        return value; \n    }\n    \n    quant_idx = size * quant - 0.5;\n    idx_left = (int)floor(quant_idx);\n    idx_right = (int)ceil(quant_idx);\n    value = tmp[idx_left] + (quant_idx - idx_left) * (tmp[idx_right] - tmp[idx_left]) / (idx_right - idx_left);\n    free(tmp);\n    return value;\n}\n\nvoid binarize(const double a[], const int size, int b[], const char how[])\n{   \n    double m = 0.0;\n    if (strcmp(how, \"mean\") == 0) {\n        m = mean(a, size);\n    } else if (strcmp(how, \"median\") == 0) {\n        m = median(a, size);\n    }\n    for (int i = 0; i < size; i++) {\n        b[i] = (a[i] > m) ? 1 : 0;\n    }  \n    return;\n}\n\ndouble f_entropy(const double a[], const int size)\n{\n    double f = 0.0;\n    for (int i = 0; i < size; i++) {\n        if (a[i] > 0) {\n            f += a[i] * log(a[i]);\n        }\n    }\n    return -1 * f;\n}\n\nvoid subset(const int a[], int b[], const int start, const int end)\n{\n    int j = 0;\n    for (int i = start; i < end; i++) {\n        b[j++] = a[i];\n    }\n    return;\n}\n\n#if defined(__GNUC__) || defined(__GNUG__)\n    cplx _Cmulcc(const cplx x, const cplx y) {\n        /*double a = x._Val[0];\n        double b = x._Val[1];\n\n        double c = y._Val[0];\n        double d = y._Val[1];\n\n        cplx result = { (a * c - b * d), (a * d + c * b) };\n         */\n        return x*y;\n    }\n\n    cplx _Cminuscc(const cplx x, const cplx y) {\n        //cplx result = { x._Val[0] - y._Val[0], x._Val[1] - y._Val[1] };\n        return x - y;\n    }\n\n    cplx _Caddcc(const cplx x, const cplx y) {\n        // cplx result = { x._Val[0] + y._Val[0], x._Val[1] + y._Val[1] };\n        return x + y;\n    }\n\n    cplx _Cdivcc(const cplx x, const cplx y) {\n        \n        double a = creal(x);\n        double b = cimag(x);\n\n        double c = creal(y);\n        double d = cimag(y);\n\n        cplx result = (a*c + b*d) / (c*c + d*d) + (b*c - a*d)/(c*c + d*d) * I;\n        \n        return result;\n         \n        // return x / y;\n    }\n\n#elif defined(_MSC_VER)\n    cplx _Cminuscc(const cplx x, const cplx y) {\n        cplx result = { x._Val[0] - y._Val[0], x._Val[1] - y._Val[1] };\n        return result;\n    }\n\n    cplx _Caddcc(const cplx x, const cplx y) {\n        cplx result = { x._Val[0] + y._Val[0], x._Val[1] + y._Val[1] };\n        return result;\n    }\n\n    cplx _Cdivcc(const cplx x, const cplx y) {\n        double a = x._Val[0];\n        double b = x._Val[1];\n\n        double c = y._Val[0];\n        double d = y._Val[1];\n\n        cplx result = { (a*c + b*d) / (c*c + d*d), (b*c - a*d)/(c*c + d*d)};\n\n        return result;\n    }\n#endif\n"
  },
  {
    "path": "C/helper_functions.h",
    "content": "#ifndef HELPER_FUNCTIONS_H\n#define HELPER_FUNCTIONS_H\n#include <string.h>\n#include <stdlib.h>\n#include <stdio.h>\n#include \"stats.h\"\n\n#if __cplusplus\n#   include <complex>\ntypedef std::complex< double > cplx;\n#else\n#   include <complex.h>\n#if defined(__GNUC__) || defined(__GNUG__)\ntypedef double complex cplx;\n#elif defined(_MSC_VER)\ntypedef _Dcomplex cplx;\n#endif\n#endif\n\nextern void linspace(double start, double end, int num_groups, double out[]);\nextern double quantile(const double y[], const int size, const double quant);\nextern void sort(double y[], int size);\nextern void binarize(const double a[], const int size, int b[], const char how[]);\nextern double f_entropy(const double a[], const int size);\nextern void subset(const int a[], int b[], const int start, const int end);\n\nextern cplx _Cminuscc(const cplx x, const cplx y);\nextern cplx _Caddcc(const cplx x, const cplx y);\nextern cplx _Cdivcc(const cplx x, const cplx y);\n#if defined(__GNUC__) || defined(__GNUG__)\nextern cplx _Cmulcc(const cplx x, const cplx y);\n#endif\n\n#endif\n"
  },
  {
    "path": "C/histcounts.c",
    "content": "//\n//  histcounts.c\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 19/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#include <stdlib.h>\n#include <float.h>\n\n#include \"stats.h\"\n#include \"histcounts.h\"\n\nint num_bins_auto(const double y[], const int size){\n    \n    double maxVal = max_(y, size);\n    double minVal = min_(y, size);\n    \n    if (stddev(y, size) < 0.001){\n        return 0;\n    }\n    \n    return ceil((maxVal-minVal)/(3.5*stddev(y, size)/pow(size, 1/3.)));\n    \n}\n\nint histcounts_preallocated(const double y[], const int size, int nBins, int * binCounts, double * binEdges)\n{\n    \n    int i = 0;\n    \n    // check min and max of input array\n    double minVal = DBL_MAX, maxVal=-DBL_MAX;\n    for(int i = 0; i < size; i++)\n    {\n        // printf(\"histcountInput %i: %1.3f\\n\", i, y[i]);\n        \n        if (y[i] < minVal)\n        {\n            minVal = y[i];\n        }\n        if (y[i] > maxVal)\n        {\n            maxVal = y[i];\n        }\n    }\n    \n    // and derive bin width from it\n    double binStep = (maxVal - minVal)/nBins;\n    \n    // variable to store counted occurances in\n    for(i = 0; i < nBins; i++)\n    {\n        binCounts[i] = 0;\n    }\n    \n    for(i = 0; i < size; i++)\n    {\n        \n        int binInd = (y[i]-minVal)/binStep;\n        if(binInd < 0)\n            binInd = 0;\n        if(binInd >= nBins)\n            binInd = nBins-1;\n        //printf(\"histcounts, i=%i, binInd=%i, nBins=%i\\n\", i, binInd, nBins);\n        binCounts[binInd] += 1;\n        \n    }\n    \n    for(i = 0; i < nBins+1; i++)\n    {\n        binEdges[i] = i * binStep + minVal;\n    }\n    \n    /*\n     // debug\n     for(i=0;i<nBins;i++)\n     {\n     printf(\"%i: count %i, edge %1.3f\\n\", i, binCounts[i], binEdges[i]);\n     }\n     */\n    \n    return 0;\n    \n}\n\nint histcounts(const double y[], const int size, int nBins, int ** binCounts, double ** binEdges)\n{\n\n    int i = 0;\n    \n    // check min and max of input array\n    double minVal = DBL_MAX, maxVal=-DBL_MAX;\n    for(int i = 0; i < size; i++)\n    {\n        // printf(\"histcountInput %i: %1.3f\\n\", i, y[i]);\n        \n        if (y[i] < minVal)\n        {\n            minVal = y[i];\n        }\n        if (y[i] > maxVal)\n        {\n            maxVal = y[i];\n        }\n    }\n    \n    // if no number of bins given, choose spaces automatically\n    if (nBins <= 0){\n        nBins = ceil((maxVal-minVal)/(3.5*stddev(y, size)/pow(size, 1/3.)));\n    }\n    \n    // and derive bin width from it\n    double binStep = (maxVal - minVal)/nBins;\n    \n    // variable to store counted occurances in\n    *binCounts = malloc(nBins * sizeof(int));\n    for(i = 0; i < nBins; i++)\n    {\n        (*binCounts)[i] = 0;\n    }\n    \n    for(i = 0; i < size; i++)\n    {\n        \n        int binInd = (y[i]-minVal)/binStep;\n        if(binInd < 0)\n            binInd = 0;\n        if(binInd >= nBins)\n            binInd = nBins-1;\n        (*binCounts)[binInd] += 1;\n        \n    }\n    \n    *binEdges = malloc((nBins+1) * sizeof(double));\n    for(i = 0; i < nBins+1; i++)\n    {\n        (*binEdges)[i] = i * binStep + minVal;\n    }\n   \n    /*\n    // debug\n    for(i=0;i<nBins;i++)\n    {\n        printf(\"%i: count %i, edge %1.3f\\n\", i, binCounts[i], binEdges[i]);\n    }\n    */\n    \n    return nBins;\n    \n}\n\nint * histbinassign(const double y[], const int size, const double binEdges[], const int nEdges)\n{\n    \n    \n    // variable to store counted occurances in\n    int * binIdentity = malloc(size * sizeof(int));\n    for(int i = 0; i < size; i++)\n    {\n        // if not in any bin -> 0\n        binIdentity[i] = 0;\n        \n        // go through bin edges\n        for(int j = 0; j < nEdges; j++){\n            if(y[i] < binEdges[j]){\n                binIdentity[i] = j;\n                break;\n            }\n        }\n    }\n    \n    return binIdentity;\n    \n}\n\nint * histcount_edges(const double y[], const int size, const double binEdges[], const int nEdges)\n{\n    \n    \n    int * histcounts = malloc(nEdges * sizeof(int));\n    for(int i = 0; i < nEdges; i++){\n        histcounts[i] = 0;\n    }\n    \n    for(int i = 0; i < size; i++)\n    {\n        // go through bin edges\n        for(int j = 0; j < nEdges; j++){\n            if(y[i] <= binEdges[j]){\n                histcounts[j] += 1;\n                break;\n            }\n        }\n    }\n    \n    return histcounts;\n    \n}\n"
  },
  {
    "path": "C/histcounts.h",
    "content": "//\n//  histcounts.h\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 19/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#ifndef histcounts_h\n#define histcounts_h\n\n#include <stdlib.h>\n#include <float.h>\n#include <stdio.h>\n\nextern int num_bins_auto(const double y[], const int size);\nextern int histcounts(const double y[], const int size, int nBins, int ** binCounts, double ** binEdges);\nextern int histcounts_preallocated(const double y[], const int size, int nBins, int * binCounts, double * binEdges);\nextern int * histcount_edges(const double y[], const int size, const double binEdges[], const int nEdges);\nextern int * histbinassign(const double y[], const int size, const double binEdges[], const int nEdges);\n\n#endif /* histcounts_h */\n"
  },
  {
    "path": "C/main.c",
    "content": "/* Include files */\n#include \"main.h\"\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdbool.h>\n//#include <dirent.h>\n\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"CO_AutoCorr.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_MotifThree.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"PD_PeriodicityWang.h\"\n\n#include \"stats.h\"\n\n// check if data qualifies to be caught22\nint quality_check(const double y[], const int size)\n{\n    int minSize = 10;\n\n    if(size < minSize)\n    {\n        return 1;\n    }\n    for(int i = 0; i < size; i++)\n    {\n        double val = y[i];\n        if(val == INFINITY || -val == INFINITY)\n        {\n            return 2;\n        }\n        if(isnan(val))\n        {\n            return 3;\n        }\n    }\n    return 0;\n}\n\nvoid run_features(double y[], int size, FILE * outfile, bool catch24)\n{\n    int quality = quality_check(y, size);\n    if(quality != 0)\n    {\n        fprintf(stdout, \"Time series quality test not passed (code %i).\\n\", quality);\n        return;\n    }\n\n    double * y_zscored = malloc(size * sizeof * y_zscored);\n\n    // variables to keep time\n    clock_t begin;\n    double timeTaken;\n\n    // output\n    double result;\n\n    // z-score first for all.\n    zscore_norm2(y, size, y_zscored);\n\n    // GOOD\n    begin = clock();\n    result = DN_OutlierInclude_n_001_mdrmd(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"DN_OutlierInclude_n_001_mdrmd\", timeTaken);\n\n    // GOOD\n    begin = clock();\n    result = DN_OutlierInclude_p_001_mdrmd(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"DN_OutlierInclude_p_001_mdrmd\", timeTaken);\n  \n    // GOOD\n    begin = clock();\n    result = DN_HistogramMode_5(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"DN_HistogramMode_5\", timeTaken);\n\n    // GOOD\n    begin = clock();\n    result = DN_HistogramMode_10(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"DN_HistogramMode_10\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = CO_Embed2_Dist_tau_d_expfit_meandiff(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"CO_Embed2_Dist_tau_d_expfit_meandiff\", timeTaken);\n\n    //GOOD (memory leak?)\n    begin = clock();\n    result = CO_f1ecac(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"CO_f1ecac\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = CO_FirstMin_ac(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"CO_FirstMin_ac\", timeTaken);\n\n    // GOOD (memory leak?)\n    begin = clock();\n    result = CO_HistogramAMI_even_2_5(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"CO_HistogramAMI_even_2_5\", timeTaken);\n\n    // GOOD\n    begin = clock();\n    result = CO_trev_1_num(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"CO_trev_1_num\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = FC_LocalSimple_mean1_tauresrat(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"FC_LocalSimple_mean1_tauresrat\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = FC_LocalSimple_mean3_stderr(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"FC_LocalSimple_mean3_stderr\", timeTaken);\n\n    //GOOD (memory leak?)\n    begin = clock();\n    result = IN_AutoMutualInfoStats_40_gaussian_fmmi(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"IN_AutoMutualInfoStats_40_gaussian_fmmi\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = MD_hrv_classic_pnn40(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"MD_hrv_classic_pnn40\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = SB_BinaryStats_diff_longstretch0(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SB_BinaryStats_diff_longstretch0\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = SB_BinaryStats_mean_longstretch1(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SB_BinaryStats_mean_longstretch1\", timeTaken);\n\n    //GOOD (memory leak?)\n    begin = clock();\n    result = SB_MotifThree_quantile_hh(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SB_MotifThree_quantile_hh\", timeTaken);\n\n    //GOOD (memory leak?)\n    begin = clock();\n    result = SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = SP_Summaries_welch_rect_area_5_1(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SP_Summaries_welch_rect_area_5_1\", timeTaken);\n\n    //GOOD\n    begin = clock();\n    result = SP_Summaries_welch_rect_centroid(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SP_Summaries_welch_rect_centroid\", timeTaken);\n\n    //OK, BUT filt in Butterworth sometimes diverges, now removed alltogether, let's see results.\n    begin = clock();\n    result = SB_TransitionMatrix_3ac_sumdiagcov(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"SB_TransitionMatrix_3ac_sumdiagcov\", timeTaken);\n\n    // GOOD\n    begin = clock();\n    result = PD_PeriodicityWang_th0_01(y_zscored, size);\n    timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n    fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"PD_PeriodicityWang_th0_01\", timeTaken);\n\n    if (catch24) {\n        \n        // GOOD\n        begin = clock();\n        result = DN_Mean(y, size);\n        timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n        fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"DN_Mean\", timeTaken);\n\n        // GOOD\n        begin = clock();\n        result = DN_Spread_Std(y, size);\n        timeTaken = (double)(clock()-begin)*1000/CLOCKS_PER_SEC;\n        fprintf(outfile, \"%.14f, %s, %f\\n\", result, \"DN_Spread_Std\", timeTaken);\n    } else {\n\n    }\n  \n    fprintf(outfile, \"\\n\");\n\n    free(y_zscored);\n}\n\nvoid print_help(char *argv[], char msg[])\n{\n    if (strlen(msg) > 0) {\n        fprintf(stdout, \"ERROR: %s\\n\", msg);\n    }\n    fprintf(stdout, \"Usage is %s <infile> <outfile>\\n\", argv[0]);\n    fprintf(stdout, \"\\n\\tSpecifying outfile is optional, by default it is stdout\\n\");\n    // fprintf(stdout, \"\\tOutput order is:\\n%s\\n\", HEADER);\n    exit(1);\n}\n\n// memory leak check; use with valgrind.\n#if 0\nint main(int argc, char * argv[])\n{\n    double * y = malloc(1000 * sizeof(double));\n\n    srand(42);\n    for (int i = 0; i < 1000; ++i) {\n        y[i] = rand() % RAND_MAX;\n    }\n    run_features(y, 1000, stdout);\n    free(y);\n}\n#endif\n\n#if 1\nint main(int argc, char * argv[])\n{\n    FILE * infile, * outfile;\n    int array_size;\n    double * y;\n    int size;\n    double value;\n    // DIR *d;\n    struct dirent *dir;\n\n\n    switch (argc) {\n        case 1:\n            print_help(argv, \"\");\n            break;\n        case 2:\n            if ((infile = fopen(argv[1], \"r\")) == NULL) {\n                print_help(argv, \"Can't open input file\\n\");\n            }\n            outfile = stdout;\n            break;\n        case 3:\n            if ((infile = fopen(argv[1], \"r\")) == NULL) {\n                print_help(argv, \"Can't open input file\\n\");\n            }\n            if ((outfile = fopen(argv[2], \"w\")) == NULL) {\n                print_help(argv, \"Can't open output file\\n\");\n            }\n            break;\n    }\n\n    /*\n    // debug: fix these.\n    infile = fopen(\"/Users/carl/PycharmProjects/catch22/C/timeSeries/tsid0244.txt\", \"r\");\n    outfile = stdout;\n     */\n\n    // fprintf(outfile, \"%s\", HEADER);\n    array_size = 50;\n    size = 0;\n    y = malloc(array_size * sizeof *y);\n\n    while (fscanf(infile, \"%lf\", &value) != EOF) {\n        if (size == array_size) {\n            y = realloc(y, 2 * array_size * sizeof *y);\n            array_size *= 2;\n        }\n        y[size++] = value;\n    }\n    fclose(infile);\n    y = realloc(y, size * sizeof *y);\n    //printf(\"size=%i\\n\", size);\n\n    // catch24 specification\n\n    int catch24;\n    printf(\"Do you want to run catch24? Enter 0 for catch22 or 1 for catch24.\");\n    scanf(\"%d\", &catch24);\n\n    if (catch24 == 1) {\n        run_features(y, size, outfile, true);\n    } else {\n        run_features(y, size, outfile, false);\n    }\n\n    fclose(outfile);\n    free(y);\n\n    return 0;\n}\n#endif\n\n#if 0\nint main(int argc, char * argv[])\n{\n  (void)argc;\n  (void)argv;\n\n    /*\n    // generate some data\n    const int size = 31; // 211;\n\n    double y[size];\n    int i;\n    double sinIn=0;\n    for(i=0; i<size; i++)\n    {\n        sinIn = (double)(i-10)/10*6;\n        y[i] = sin(sinIn);\n        printf(\"%i: sinIn=%1.3f, sin=%1.3f\\n\", i, sinIn, y[i]);\n    }*/\n\n    // open a certain file\n    FILE * infile;\n    infile = fopen(\"C:\\\\Users\\\\Carl\\\\Documents\\\\catch22-master\\\\testData\\\\test.txt\", \"r\");\n    int array_size = 15000;\n    double * y = malloc(array_size * sizeof(double));\n    int size = 0;\n    double value = 0;\n    while (fscanf(infile, \"%lf\", &value) != EOF) {\n        y[size++] = value;\n    }\n\n    // first, z-score.\n    zscore_norm(y, size);\n\n    double result;\n  \n    result = DN_OutlierInclude_n_001_mdrmd(y, size);\n    printf(\"DN_OutlierInclude_n_001_mdrmd: %1.5f\\n\", result);\n    result = DN_OutlierInclude_p_001_mdrmd(y, size);\n    printf(\"DN_OutlierInclude_p_001_mdrmd: %1.5f\\n\", result);\n    result = DN_HistogramMode_5(y, size);\n    printf(\"DN_HistogramMode_5: %1.3f\\n\", result);\n    result = DN_HistogramMode_10(y, size);\n    printf(\"DN_HistogramMode_10: %1.3f\\n\", result);\n    result = SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(y, size);\n    printf(\"SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1: %1.5f\\n\", result);\n    result = SB_TransitionMatrix_3ac_sumdiagcov(y, size);\n    printf(\"SB_TransitionMatrix_3ac_sumdiagcov: %1.5f\\n\", result);\n    result = FC_LocalSimple_mean1_tauresrat(y, size);\n    printf(\"FC_LocalSimple_mean1_tauresrat: %1.5f\\n\", result);\n    result = SB_MotifThree_quantile_hh(y, size);\n    printf(\"SB_MotifThree_quantile_hh: %1.5f\\n\", result);\n    result = CO_HistogramAMI_even_2_5(y, size);\n    printf(\"CO_HistogramAMI_even_2_5: %1.3f\\n\", result);\n    result = CO_Embed2_Dist_tau_d_expfit_meandiff(y, size);\n    printf(\"CO_Embed2_Dist_tau_d_expfit_meandiff: %1.3f\\n\", result);\n    result = SB_BinaryStats_diff_longstretch0(y, size);\n    printf(\"SB_BinaryStats_diff_longstretch0: %1.5f\\n\", result);\n    result = MD_hrv_classic_pnn40(y, size);\n    printf(\"MD_hrv_classic_pnn40: %1.5f\\n\", result);\n    result = SB_BinaryStats_mean_longstretch1(y, size);\n    printf(\"SB_BinaryStats_mean_longstretch1: %1.5f\\n\", result);\n    result = FC_LocalSimple_mean3_stderr(y, size);\n    printf(\"FC_LocalSimple_mean3_stderr: %1.5f\\n\", result);\n    result = SP_Summaries_welch_rect_area_5_1(y, size);\n    printf(\"SP_Summaries_welch_rect_area_5_1: %1.5f\\n\", result);\n    result = SP_Summaries_welch_rect_centroid(y, size);\n    printf(\"SP_Summaries_welch_rect_centroid: %1.5f\\n\", result);\n    result = CO_f1ecac(y, size);\n    printf(\"CO_f1ecac: %1.f\\n\", result);\n    result = CO_FirstMin_ac(y, size);\n    printf(\"CO_FirstMin_ac: %1.f\\n\", result);\n    result = IN_AutoMutualInfoStats_40_gaussian_fmmi(y, size);\n    printf(\"IN_AutoMutualInfoStats_40_gaussian_fmmi: %1.5f\\n\", result);\n    result = PD_PeriodicityWang_th0_01(y, size);\n    printf(\"PD_PeriodicityWang_th0_01: %1.f\\n\", result);\n    result = SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(y, size);\n    printf(\"SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1: %1.5f\\n\", result);\n    result = CO_trev_1_num(y, size);\n    printf(\"CO_trev_1_num: %1.5f\\n\", result);\n\n    int catch24;\n    printf(\"Do you want to run catch24? Enter 0 for catch22 or 1 for catch24.\");\n    scanf(\"%d\", &catch24);\n\n    if (catch24 == 1) {\n        result = DN_Mean(y, size);\n        printf(\"DN_Mean: %1.5f\\n\", result);\n        result = DN_Spread_Std(y, size);\n        printf(\"DN_Spread_Std: %1.5f\\n\", result);\n    } else {\n    }\n\n  return 0;\n}\n#endif\n"
  },
  {
    "path": "C/main.h",
    "content": "#ifndef MAIN_H\n#define MAIN_H\n\n/* Include files */\n#include <math.h>\n#include <stddef.h>\n#include <stdlib.h>\n#include <string.h>\n\n/* Function Declarations */\n//extern int main(int argc, const char * const argv[]);\nextern int main(int argc, char * argv[]);\n\n#endif\n\n/* End of code generation (main.h) */\n"
  },
  {
    "path": "C/runAllTS.sh",
    "content": "#!/bin/bash\n\nhelp()\n{\n   echo \"\"\n   echo \"Usage: $0 -i indir -o outdir -a append_string -s\"\n   echo -e \"\\t-h Show this help message\"\n   echo -e \"\\t-i Path to a directory containing input time-series files (.txt with one time series value per line). Default: './timeSeries'\"\n   echo -e \"\\t-o Path to a directory in which to save output feature values. Default: './featureOutput'\"\n   echo -e \"\\t-a A string (minus extension) appended to the input file names to create the output file names. Default: 'output'\"\n   echo -e \"\\t-s A switch to evaluate catch22 (0) or catch24 (1). Default: 0\"\n   exit 1\n}\n\nwhile getopts \"i:o:a:s:h\" opt\ndo\n   case \"$opt\" in\n      i) indir=\"$OPTARG\" ;;\n      o) outdir=\"$OPTARG\" ;;\n      a) append=\"$OPTARG\" ;;\n      s) catch24=\"$OPTARG\" ;;\n      h) help ;;\n   esac\ndone\n\nsrcdir=$(dirname \"$0}\")\n\nif [ -z \"$indir\" ]\nthen\n   indir=\"./timeSeries\"\nfi\n\nif [ -z \"$outdir\" ]\nthen\n   outdir=\"./featureOutput\"\nfi\n\nif [ -z \"$append\" ]\nthen\n   append=\"output\"\nfi\n\nif [ -z \"$catch24\" ]\nthen\n   catch24=0\nfi\n\nindir=\"$(dirname $indir)/$(basename $indir)\"\noutdir=\"$(dirname $outdir)/$(basename $outdir)\"\nmkdir -p $outdir\n\n# Loop through each file in indir and save the feature outputs\nfor entry in \"${indir}\"/*.txt\ndo\n    filename=$(basename \"$entry\")\n    extension=\"${filename##*.}\"\n    filename=\"${filename%.*}\"\n    fullfile=\"${outdir}/${filename}${append}.${extension}\"\n    if [ \"${filename: -${#append}}\" != \"${append}\" ]\n    then\n        yes $catch24 | \"${srcdir}/run_features\" $entry $fullfile > /dev/null\n\n        if [ -s $fullfile ] # Remove file if catch22 errors\n        then\n            echo \"Output written to ${fullfile}\"\n        else\n            rm $fullfile\n        fi\n\n    fi\ndone\n"
  },
  {
    "path": "C/splinefit.c",
    "content": "//  Created by Carl Henning Lubba on 27/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n// Based on the work of Jonas Lundgren in his Matlab Central contribution 'SPLINEFIT'.\n//\n#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n\n#include \"splinefit.h\"\n#include \"stats.h\"\n\n#define nCoeffs 3\n#define nPoints 4\n\n#define pieces 2\n#define nBreaks 3\n#define deg 3\n#define nSpline 4\n#define piecesExt 8 //3 * deg - 1\n\n\nvoid matrix_multiply(const int sizeA1, const int sizeA2, const double *A, const int sizeB1, const int sizeB2, const double *B, double *C){\n//void matrix_multiply(int sizeA1, int sizeA2, double **A, int sizeB1, int sizeB2, double **B, double C[sizeA1][sizeB2]){\n    \n    if(sizeA2 != sizeB1){\n        return;\n    }\n    \n    /*\n    // show input\n    for(int i = 0; i < sizeA1; i++){\n        for(int j = 0; j < sizeA2; j++){\n            printf(\"A[%i][%i] = %1.3f\\n\", i, j, A[i*sizeA2 + j]);\n        }\n    }\n     */\n    \n    for(int i = 0; i < sizeA1; i++){\n        for(int j = 0; j < sizeB2; j++){\n            \n            //C[i][j] = 0;\n            C[i*sizeB2 + j] = 0;\n            for(int k = 0; k < sizeB1; k++){\n                // C[i][j] += A[i][k]*B[k][j];\n                C[i*sizeB2 + j] += A[i * sizeA2 + k]*B[k * sizeB2 + j];\n                //printf(\"C[%i][%i] (k=%i) = %1.3f\\n\", i, j, k, C[i * sizeB2 + j]);\n            }\n            \n        }\n    }\n    \n}\n\nvoid matrix_times_vector(const int sizeA1, const int sizeA2, const double *A, const int sizeb, const double *b, double *c){ //c[sizeb]\n    \n    if(sizeA2 != sizeb){\n        return;\n    }\n    \n    // row\n    for(int i = 0; i < sizeA1; i++){\n        \n        // column\n        c[i] = 0;\n        for(int k = 0; k < sizeb; k++){\n            c[i] += A[i * sizeA2 + k]*b[k];\n        }\n        \n    }\n    \n}\n\nvoid gauss_elimination(int size, double *A, double *b, double *x){\n// void gauss_elimination(int size, double A[size][size], double b[size], double x[size]){\n    \n    double factor;\n    \n    // create temp matrix and vector\n    // double *AElim[size];\n    double* AElim[nSpline + 1];\n    for (int i = 0; i < size; i++)\n        AElim[i] = (double *)malloc(size * sizeof(double));\n    double * bElim = malloc(size * sizeof(double));\n    \n    // -- create triangular matrix\n    \n    // initialise to A and b\n    for(int i = 0; i < size; i++){\n        for(int j = 0; j < size; j++){\n            AElim[i][j] = A[i*size + j];\n        }\n        bElim[i] = b[i];\n    }\n    \n    /*\n    printf(\"AElim\\n\");\n    for(int i = 0; i < size; i++){\n        for(int j = 0; j < size; j++){\n            printf(\"%1.3f, \", AElim[i][j]);\n        }\n        printf(\"\\n\");\n    }\n     */\n    \n    // go through columns in outer loop\n    for(int i = 0; i < size; i++){\n    \n        // go through rows to eliminate\n        for(int j = i+1; j < size; j++){\n            \n            factor = AElim[j][i]/AElim[i][i];\n            \n            // subtract in vector\n            bElim[j] = bElim[j] - factor*bElim[i];\n            \n            // go through entries of this row\n            for(int k = i; k < size; k++){\n                AElim[j][k] = AElim[j][k] - factor*AElim[i][k];\n            }\n            \n            /*\n            printf(\"AElim i=%i, j=%i\\n\", i, j);\n            for(int i = 0; i < size; i++){\n                for(int j = 0; j < size; j++){\n                    printf(\"%1.3f, \", AElim[i][j]);\n                }\n                printf(\"\\n\");\n            }\n             */\n            \n        }\n        \n    }\n    \n    /*\n    for(int i = 0; i < size; i++){\n        for(int j = 0; j < size; j++){\n            printf(\"AElim[%i][%i] = %1.3f\\n\", i, j, AElim[i][j]);\n        }\n    }\n    for(int i = 0; i < size; i++){\n        printf(\"bElim[%i] = %1.3f\\n\", i, bElim[i]);\n    }\n     */\n    \n    \n    // -- go backwards through triangular matrix and solve for x\n    \n    // row\n    double bMinusATemp;\n    for(int i = size-1; i >= 0; i--){\n        \n        bMinusATemp = bElim[i];\n        for(int j = i+1; j < size; j++){\n            bMinusATemp -= x[j]*AElim[i][j];\n        }\n        \n        x[i] = bMinusATemp/AElim[i][i];\n    }\n    /*\n    for(int j = 0; j < size; j++){\n        printf(\"x[%i] = %1.3f\\n\", j, x[j]);\n    }\n     */\n    \n    for (int i = 0; i < size; i++)\n        free(AElim[i]);\n    free(bElim);\n}\n\nvoid lsqsolve_sub(const int sizeA1, const int sizeA2, const double *A, const int sizeb, const double *b, double *x)\n//void lsqsolve_sub(int sizeA1, int sizeA2, double A[sizeA1][sizeA2], int sizeb, double b[sizeb], double x[sizeA1])\n{\n    // create temp matrix and vector\n    /*\n    double *AT[sizeA1*sizeA2];\n    for (int i = 0; i < sizeA2; i++)\n        AT[i] = (double *)malloc(sizeA1 * sizeof(double));\n    double *ATA[sizeA2];\n    for (int i = 0; i < sizeA2; i++)\n        ATA[i] = (double *)malloc(sizeA2 * sizeof(double));\n    double * ATb = malloc(sizeA1 * sizeof(double));\n     */\n    \n    double * AT = malloc(sizeA2 * sizeA1 * sizeof(double));\n    double * ATA = malloc(sizeA2 * sizeA2 * sizeof(double));\n    double * ATb = malloc(sizeA2 * sizeof(double));\n    \n    \n    for(int i = 0; i < sizeA1; i++){\n        for(int j = 0; j < sizeA2; j++){\n            //AT[i,j] = A[j,i]\n            AT[j * sizeA1 + i] = A[i * sizeA2 + j];\n        }\n    }\n    \n    /*\n    printf(\"\\n b \\n\");\n    for(int i = 0; i < sizeA1; i++){\n        printf(\"%i, %1.3f\\n\", i, b[i]);\n    }\n     */\n    \n    /*\n    printf(\"\\nA\\n\");\n     for(int i = 0; i < sizeA2; i++){\n         for(int j = 0; j < sizeA1; j++){\n             printf(\"%1.3f, \", AT[i * sizeA1 + j]);\n         }\n         printf(\"\\n\");\n     }\n     */\n     \n    \n    matrix_multiply(sizeA2, sizeA1, AT, sizeA1, sizeA2, A, ATA);\n    \n    /*\n    printf(\"ATA\\n\");\n    for(int i = 0; i < sizeA2; i++){\n        for(int j = 0; j < sizeA2; j++){\n            printf(\"%1.3f, \", ATA[i * sizeA2 + j]);\n        }\n        printf(\"\\n\");\n    }\n     */\n    \n    \n    \n    matrix_times_vector(sizeA2, sizeA1, AT, sizeA1, b, ATb);\n    \n    /*\n    for(int i = 0; i < sizeA2; i++){\n        ATb[i] = 0;\n        for(int j = 0; j < sizeA1; j++){\n            ATb[i] += AT[i*sizeA1 + j]*b[j];\n            //printf(\"%i, ATb[%i]=%1.3f, AT[i*sizeA1 + j]=%1.3f, b[j]=%1.3f\\n\", i, i, ATb[i], AT[i*sizeA1 + j],b[j]);\n        }\n    }\n     */\n    \n    /*\n     for(int i = 0; i < nCoeffs; i++){\n     printf(\"b[%i] = %1.3f\\n\", i, b[i]);\n     }\n     */\n    \n    /*\n    for(int i = 0; i < sizeA2; i++){\n        printf(\"ATb[%i] = %1.3f\\n\", i, ATb[i]);\n    }\n     */\n    \n    \n    gauss_elimination(sizeA2, ATA, ATb, x);\n    \n    free(AT);\n    free(ATA);\n    free(ATb);\n    \n}\n\n/*\nint lsqsolve()\n{\n    //const int nPoints = 4;\n    //const int nCoeffs = 3;\n    \n    //double A[nPoints][nCoeffs] = {};\n\tdouble A[4][3];\n    A[0][0] = 1;\n    A[1][0] = 3;\n    A[2][0] = 6;\n    A[3][0] = 8;\n    A[0][1] = 4;\n    A[1][1] = 5;\n    A[2][1] = 3;\n    A[3][1] = 12;\n    A[0][2] = 4;\n    A[1][2] = 1;\n    A[2][2] = 0;\n    A[3][2] = 7;\n    //double b[nPoints] = {};\n\tdouble b[4];\n    b[0] = 2;\n    b[1] = 8;\n    b[2] = 3;\n    b[3] = 1;\n    \n    double x[4];\n    \n    double * Alin = malloc(nPoints * nCoeffs * sizeof(double));\n    \n    for(int i = 0; i < nPoints; i++){\n        for(int j = 0; j < nCoeffs; j++){\n            //AT[i,j] = A[j,i]\n            Alin[i * nCoeffs + j] = A[i][j];\n        }\n    }\n    \n    lsqsolve_sub(nPoints, nCoeffs, Alin, nPoints, b, x);\n    \n    free(Alin);\n    \n    return 0;\n    \n    \n}\n*/\n\nint iLimit(int x, int lim){\n    return x<lim ? x : lim;\n}\n\nint splinefit(const double *y, const int size, double *yOut)\n{\n    // degree of spline\n    //const int nSpline = 4;\n    //const int deg = 3;\n    \n    // x-positions of spline-nodes\n    //const int nBreaks = 3;\n    int breaks[nBreaks];\n    breaks[0] = 0;\n    breaks[1] = (int)floor((double)size/2.0)-1;\n    breaks[2] = size-1;\n    \n    // -- splinebase\n    \n    // spacing\n    int h0[2];\n    h0[0] = breaks[1] - breaks[0];\n    h0[1] = breaks[2] - breaks[1];\n    \n    //const int pieces = 2;\n    \n    // repeat spacing\n    int hCopy[4];\n    hCopy[0] = h0[0], hCopy[1] = h0[1], hCopy[2] = h0[0], hCopy[3] = h0[1];\n    \n    // to the left\n    int hl[deg];\n    hl[0] = hCopy[deg-0];\n    hl[1] = hCopy[deg-1];\n    hl[2] = hCopy[deg-2];\n    \n    int hlCS[deg]; // cumulative sum\n    icumsum(hl, deg, hlCS);\n    \n    int bl[deg];\n    for(int i = 0; i < deg; i++){\n        bl[i] = breaks[0] - hlCS[i];\n    }\n    \n    // to the left\n    int hr[deg];\n    hr[0] = hCopy[0];\n    hr[1] = hCopy[1];\n    hr[2] = hCopy[2];\n    \n    int hrCS[deg]; // cumulative sum\n    icumsum(hr, deg, hrCS);\n    \n    int br[deg];\n    for(int i = 0; i < deg; i++){\n        br[i] = breaks[2] + hrCS[i];\n    }\n    \n    // add breaks\n    int breaksExt[3*deg];\n    for(int i = 0; i < deg; i++){\n        breaksExt[i] = bl[deg-1-i];\n        breaksExt[i + 3] = breaks[i];\n        breaksExt[i + 6] = br[i];\n    }\n    int hExt[3*deg-1];\n    for(int i = 0; i < deg*3-1; i++){\n        hExt[i] = breaksExt[i+1] - breaksExt[i];\n    }\n    //const int piecesExt = 3*deg-1;\n    \n    // initialise polynomial coefficients\n    double coefs[nSpline*piecesExt][nSpline+1];\n    for(int i = 0; i < nSpline*piecesExt; i++){\n        for(int j = 0; j < nSpline; j++){\n        coefs[i][j] = 0;\n        }\n    }\n    for(int i = 0; i < nSpline*piecesExt; i=i+nSpline){\n        coefs[i][0] = 1;\n    }\n    \n    // expand h using the index matrix ii\n    int ii[deg+1][piecesExt];\n    for(int i = 0; i < piecesExt; i++){\n        ii[0][i] = iLimit(0+i, piecesExt-1);\n        ii[1][i] = iLimit(1+i, piecesExt-1);\n        ii[2][i] = iLimit(2+i, piecesExt-1);\n        ii[3][i] = iLimit(3+i, piecesExt-1);\n    }\n    \n    // expanded h\n    double H[(deg+1)*piecesExt];\n    int iiFlat;\n    for(int i = 0; i < nSpline*piecesExt; i++){\n        iiFlat = ii[i%nSpline][i/nSpline];\n        H[i] = hExt[iiFlat];\n    }\n    \n    //recursive generation of B-splines\n    double Q[nSpline][piecesExt];\n    for(int k = 1; k < nSpline; k++){\n        \n        //antiderivatives of splines\n        for(int j = 0; j<k; j++){\n            for(int l = 0; l<(nSpline*piecesExt); l++){\n                coefs[l][j] *= H[l]/(k-j);\n                //printf(\"coefs[%i][%i]=%1.3f\\n\", l, j, coefs[l][j]);\n            }\n        }\n        \n        for(int l = 0; l<(nSpline*piecesExt); l++){\n            Q[l%nSpline][l/nSpline] = 0;\n            for(int m = 0; m < nSpline; m++){\n                Q[l%nSpline][l/nSpline] += coefs[l][m];\n            }\n        }\n        \n        /*\n        printf(\"\\nQ:\\n\");\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < piecesExt; j ++){\n                printf(\"%1.3f, \", Q[i][j]);\n            }\n            printf(\"\\n\");\n        }\n        */\n        \n        //cumsum\n        for(int l = 0; l<piecesExt; l++){\n            for(int m = 1; m < nSpline; m++){\n                Q[m][l] += Q[m-1][l];\n            }\n        }\n        \n        /*\n        printf(\"\\nQ cumsum:\\n\");\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < piecesExt; j ++){\n                printf(\"%1.3f, \", Q[i][j]);\n            }\n            printf(\"\\n\");\n        }\n        */\n        \n        for(int l = 0; l<nSpline*piecesExt; l++){\n            if(l%nSpline == 0)\n                coefs[l][k] = 0;\n            else{\n                coefs[l][k] = Q[l%nSpline-1][l/nSpline]; // questionable\n            }\n            // printf(\"coefs[%i][%i]=%1.3f\\n\", l, k, coefs[l][k]);\n        }\n        \n        // normalise antiderivatives by max value\n        double fmax[piecesExt*nSpline];\n        for(int i = 0; i < piecesExt; i++){\n            for(int j = 0; j < nSpline; j++){\n                \n                fmax[i*nSpline+j] = Q[nSpline-1][i];\n                \n            }\n        }\n        \n        /*\n        printf(\"\\n fmax:\\n\");\n        for(int i = 0; i < piecesExt*n; i++){\n            printf(\"%1.3f, \\n\", fmax[i]);\n        }\n        */\n        \n        for(int j = 0; j < k+1; j++){\n            for(int l = 0; l < nSpline*piecesExt; l++){\n                coefs[l][j] /= fmax[l];\n                // printf(\"coefs[%i][%i]=%1.3f\\n\", l, j, coefs[l][j]);\n            }\n        }\n\n        // diff to adjacent antiderivatives\n        for(int i = 0; i < (nSpline*piecesExt)-deg; i++){\n            for(int j = 0; j < k+1; j ++){\n                coefs[i][j] -= coefs[deg+i][j];\n                //printf(\"coefs[%i][%i]=%1.3f\\n\", i, j, coefs[i][j]);\n            }\n        }\n        for(int i = 0; i < nSpline*piecesExt; i += nSpline){\n            coefs[i][k] = 0;\n        }\n        \n        /*\n        printf(\"\\ncoefs:\\n\");\n        for(int i = 0; i < (n*piecesExt); i++){\n            for(int j = 0; j < n; j ++){\n                printf(\"%1.3f, \", coefs[i][j]);\n            }\n            printf(\"\\n\");\n        }\n        */\n        \n    }\n    \n    // scale coefficients\n    double scale[nSpline*piecesExt];\n    for(int i = 0; i < nSpline*piecesExt; i++)\n    {\n        scale[i] = 1;\n    }\n    for(int k = 0; k < nSpline-1; k++){\n        for(int i = 0; i < (nSpline*piecesExt); i++){\n            scale[i] /= H[i];\n        }\n        for(int i = 0; i < (nSpline*piecesExt); i++){\n            coefs[i][(nSpline-1)-(k+1)] *= scale[i];\n        }\n    }\n    \n    /*\n    printf(\"\\ncoefs scaled:\\n\");\n    for(int i = 0; i < (n*piecesExt); i++){\n        for(int j = 0; j < n; j ++){\n            printf(\"%1.4f, \", coefs[i][j]);\n        }\n        printf(\"\\n\");\n    }\n    */\n    \n    // reduce pieces and sort coefficients by interval number\n    int jj[nSpline][pieces];\n    for(int i = 0; i < nSpline; i++){\n        for(int j = 0; j < pieces; j++){\n            if(i == 0)\n                jj[i][j] = nSpline*(1+j);\n            else\n                jj[i][j] = deg;\n        }\n    }\n    \n    /*\n    printf(\"\\n jj\\n\");\n    for(int i = 0; i < n; i++){\n        for(int j = 0; j < pieces; j++){\n            printf(\"%i, \", jj[i][j]);\n        }\n        printf(\"\\n\");\n    }\n    */\n        \n    \n    for(int i = 1; i < nSpline; i++){\n        for(int j = 0; j < pieces; j++){\n            jj[i][j] += jj[i-1][j];\n        }\n    }\n    \n    /*\n    printf(\"\\n jj cumsum\\n\");\n    for(int i = 0; i < n; i++){\n        for(int j = 0; j < pieces; j++){\n            printf(\"%i, \", jj[i][j]);\n        }\n        printf(\"\\n\");\n    }\n    */\n    \n    double coefsOut[nSpline*pieces][nSpline];\n    int jj_flat;\n    for(int i = 0; i < nSpline*pieces; i++){\n        jj_flat = jj[i%nSpline][i/nSpline]-1;\n        //printf(\"jj_flat(%i) = %i\\n\", i, jj_flat);\n        for(int j = 0; j < nSpline; j++){\n            coefsOut[i][j] = coefs[jj_flat][j];\n            //printf(\"coefsOut[%i][%i]=%1.3f\\n\", i, j, coefsOut[i][j]);\n        }\n        \n    }\n    \n    /*\n    printf(\"\\n coefsOut * 1000\\n\");\n    for(int i = 0; i < n*pieces; i++){\n        for(int j = 0; j < n; j++){\n            printf(\"%1.3f, \", coefsOut[i][j]*1000);\n        }\n        printf(\"\\n\");\n    }\n     */\n    \n    \n    // -- create first B-splines to feed into optimization\n    \n    // x-values for B-splines\n    int * xsB = malloc((size*nSpline)* sizeof(int));\n    int * indexB = malloc((size*nSpline) * sizeof(int));\n    \n    int breakInd = 1;\n    for(int i = 0; i < size; i++){\n        if(i >= breaks[breakInd] & breakInd<nBreaks-1)\n            breakInd += 1;\n        for(int j = 0; j < nSpline; j++){\n            xsB[i*nSpline+j] = i - breaks[breakInd-1];\n            indexB[i*nSpline+j] = j + (breakInd-1)*nSpline;\n        }\n    }\n    \n    /*\n    printf(\"\\nxsB\\n\");\n    for(int i = 0; i < size*n; i++){\n        printf(\"%i, %i\\n\", i, xsB[i]);\n    }\n    printf(\"\\nindexB\\n\");\n    for(int i = 0; i < size*n; i++){\n        printf(\"%i, %i\\n\", i, indexB[i]);\n    }\n     */\n    \n    double * vB = malloc((size*nSpline) * sizeof(double));\n    for(int i = 0; i < size*nSpline; i++){\n        vB[i] = coefsOut[indexB[i]][0];\n    }\n    \n    /*\n    printf(\"\\nvB first iteration\\n\");\n    for(int i = 0; i < size*n; i++){\n        printf(\"%i, %1.4f\\n\", i, vB[i]);\n    }\n     */\n    \n    for(int i = 1; i < nSpline; i ++){\n        for(int j = 0; j < size*nSpline; j++){\n            vB[j] = vB[j]*xsB[j] + coefsOut[indexB[j]][i];\n        }\n        /*\n        printf(\"\\nvB k=%i\\n\", i+1);\n        for(int i = 0; i < size*n; i++){\n            printf(\"%i, %1.4f\\n\", i, vB[i]);\n        }\n         */\n    }\n    \n    /*\n    printf(\"\\nvB final\\n\");\n    for(int i = 0; i < size*n; i++){\n        printf(\"%i, %1.4f\\n\", i, vB[i]);\n    }\n     */\n    \n    \n    double * A = malloc(size*(nSpline+1) * sizeof(double));\n    \n    for(int i = 0; i < (nSpline+1)*size; i++){\n        A[i] = 0;\n    }\n    breakInd = 0;\n    for(int i = 0; i < nSpline*size; i++){\n        if(i/nSpline >= breaks[1])\n            breakInd = 1;\n        A[(i%nSpline)+breakInd + (i/nSpline)*(nSpline+1)] = vB[i];\n    }\n    \n    /*\n    printf(\"\\nA:\\n\");\n    for(int i = 0; i < size; i++){\n        for(int j = 0; j < n+1; j++){\n            printf(\"%1.5f, \", A[i * (n+1) + j]);\n        }\n        printf(\"\\n\");\n    }\n     */\n    \n    \n    \n    double * x = malloc((nSpline+1)*sizeof(double));\n    // lsqsolve_sub(int sizeA1, int sizeA2, double *A, int sizeb, double *b, double *x)\n    lsqsolve_sub(size, nSpline+1, A, size, y, x);\n    \n    /*\n    printf(\"\\nsolved x\\n\");\n    for(int i = 0; i < n+1; i++){\n        printf(\"%i, %1.4f\\n\", i, x[i]);\n    }\n    */\n    \n    // coeffs of B-splines to combine by optimised weighting in x\n    double C[pieces+nSpline-1][nSpline*pieces];\n    // initialise to 0\n    for(int i = 0; i < nSpline+1; i++){\n        for(int j = 0; j < nSpline*pieces; j++){\n            C[i][j] = 0;\n        }\n    }\n    \n    int CRow, CCol, coefRow, coefCol;\n    for(int i = 0; i < nSpline*nSpline*pieces; i++){\n        \n        CRow = i%nSpline + (i/nSpline)%2;\n        CCol = i/nSpline;\n        \n        coefRow = i%(nSpline*2);\n        coefCol =i/(nSpline*2);\n        \n        C[CRow][CCol] = coefsOut[coefRow][coefCol];\n        \n    }\n    \n    /*\n    printf(\"\\nC:\\n\");\n    for(int i = 0; i < n+1; i++){\n        for(int j = 0; j < n*pieces; j++){\n            printf(\"%1.5f, \", C[i][j]);\n        }\n        printf(\"\\n\");\n    }\n    */\n    \n    // final coefficients\n    double coefsSpline[pieces][nSpline];\n    for(int i = 0; i < pieces; i++){\n        for(int j = 0; j < nSpline; j++){\n            coefsSpline[i][j] = 0;\n        }\n    }\n    \n    //multiply with x\n    for(int j = 0; j < nSpline*pieces; j++){\n        coefCol = j/pieces;\n        coefRow = j%pieces;\n        \n        for(int i = 0; i < nSpline+1; i++){\n            \n            coefsSpline[coefRow][coefCol] += C[i][j]*x[i];\n            \n        }\n    }\n    \n    /*\n    printf(\"\\ncoefsSpline:\\n\");\n    for(int i = 0; i < pieces; i++){\n        for(int j = 0; j < n; j++){\n            printf(\"%1.5f, \", coefsSpline[i][j]);\n        }\n        printf(\"\\n\");\n    }\n     */\n     \n    \n    // compute piecewise polynomial\n    \n    int secondHalf = 0;\n    for(int i = 0; i < size; i++){\n        secondHalf = i < breaks[1] ? 0 : 1;\n        yOut[i] = coefsSpline[secondHalf][0];\n    }\n    \n    /*\n    printf(\"\\nvSpline first iter\\n\");\n    for(int i = 0; i < size; i++){\n        printf(\"%i, %1.5f\\n\", i, vSpline[i]);\n    }\n    */\n    \n    for(int i = 1; i < nSpline; i ++){\n        for(int j = 0; j < size; j++){\n            secondHalf = j < breaks[1] ? 0 : 1;\n            yOut[j] = yOut[j]*(j - breaks[1]*secondHalf) + coefsSpline[secondHalf][i];\n        }\n        \n        /*\n        printf(\"\\nvSpline %i th iter\\n\", i);\n        for(int i = 0; i < size; i++){\n            printf(\"%i, %1.4f\\n\", i, vSpline[i]);\n        }\n         */\n    }\n    \n    /*\n    printf(\"\\nvSpline\\n\");\n    for(int i = 0; i < size; i++){\n        printf(\"%i, %1.4f\\n\", i, yOut[i]);\n    }\n     */\n     \n    free(xsB);\n    free(indexB);\n    free(vB);\n    free(A);\n    free(x);\n    \n    return 0;\n    \n}\n\n\n"
  },
  {
    "path": "C/splinefit.h",
    "content": "//\n//  splinefit.h\n//  C_polished\n//\n//  Created by Carl Henning Lubba on 27/09/2018.\n//  Copyright © 2018 Carl Henning Lubba. All rights reserved.\n//\n\n#ifndef splinefit_h\n#define splinefit_h\n\n#include <stdio.h>\n\nextern int splinefit(const double *y, const int size, double *yOut);\n\n#endif /* splinefit_h */\n"
  },
  {
    "path": "C/stats.c",
    "content": "#include <math.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include \"helper_functions.h\"\n\ndouble min_(const double a[], const int size)\n{\n    double m = a[0];\n    for (int i = 1; i < size; i++) {\n        if (a[i] < m) {\n            m = a[i];\n        }\n    }\n    return m;\n}\n\ndouble max_(const double a[], const int size)\n{\n    double m = a[0];\n    for (int i = 1; i < size; i++) {\n        if (a[i] > m) {\n            m = a[i];\n        }\n    }\n    return m;\n}\n\ndouble mean(const double a[], const int size)\n{\n    double m = 0.0;\n    for (int i = 0; i < size; i++) {\n        m += a[i];\n    }\n    m /= size;\n    return m;\n}\n\ndouble sum(const double a[], const int size)\n{\n    double m = 0.0;\n    for (int i = 0; i < size; i++) {\n        m += a[i];\n    }\n    return m;\n}\n\nvoid cumsum(const double a[], const int size, double b[])\n{\n    b[0] = a[0];\n    for (int i = 1; i < size; i++) {\n        b[i] = a[i] + b[i-1];\n        //printf(\"b[%i]%1.3f = a[%i]%1.3f + b[%i-1]%1.3f\\n\", i, b[i], i, a[i], i, a[i-1]);\n    }\n    \n}\n\nvoid icumsum(const int a[], const int size, int b[])\n{\n    b[0] = a[0];\n    for (int i = 1; i < size; i++) {\n        b[i] = a[i] + b[i-1];\n        //printf(\"b[%i]%1.3f = a[%i]%1.3f + b[%i-1]%1.3f\\n\", i, b[i], i, a[i], i, a[i-1]);\n    }\n    \n}\n\ndouble isum(const int a[], const int size)\n{\n    double m = 0.0;\n    for (int i = 0; i < size; i++) {\n        m += a[i];\n    }\n    return m;\n}\n\ndouble median(const double a[], const int size)\n{\n    double m;\n    double * b = malloc(size * sizeof *b);\n    memcpy(b, a, size * sizeof *b);\n    sort(b, size);\n    if (size % 2 == 1) {\n        m = b[size / 2];\n    } else {\n        int m1 = size / 2;\n        int m2 = m1 - 1;\n        m = (b[m1] + b[m2]) / (double)2.0;\n    }\n    free(b);\n    return m;\n}\n\ndouble stddev(const double a[], const int size)\n{\n    double m = mean(a, size);\n    double sd = 0.0;\n    for (int i = 0; i < size; i++) {\n        sd += pow(a[i] - m, 2);\n    }\n    sd = sqrt(sd / (size - 1));\n    return sd;\n}\n\ndouble cov(const double x[], const double y[], const int size){\n    \n    double covariance = 0;\n    \n    double meanX = mean(x, size);\n    double meanY = mean(y, size);\n    \n    for(int i = 0; i < size; i++){\n        // double xi =x[i];\n        // double yi =y[i];\n        covariance += (x[i] - meanX) * (y[i] - meanY);\n        \n    }\n    \n    return covariance/(size-1);\n    \n}\n\ndouble cov_mean(const double x[], const double y[], const int size){\n    \n    double covariance = 0;\n    \n    for(int i = 0; i < size; i++){\n        // double xi =x[i];\n        // double yi =y[i];\n        covariance += x[i] * y[i];\n        \n    }\n    \n    return covariance/size;\n    \n}\n\ndouble corr(const double x[], const double y[], const int size){\n    \n    double nom = 0;\n    double denomX = 0;\n    double denomY = 0;\n    \n    double meanX = mean(x, size);\n    double meanY = mean(y, size);\n    \n    for(int i = 0; i < size; i++){\n        nom += (x[i] - meanX) * (y[i] - meanY);\n        denomX += (x[i] - meanX) * (x[i] - meanX);\n        denomY += (y[i] - meanY) * (y[i] - meanY);\n        \n        //printf(\"x[%i]=%1.3f, y[%i]=%1.3f, nom[%i]=%1.3f, denomX[%i]=%1.3f, denomY[%i]=%1.3f\\n\", i, x[i], i, y[i], i, nom, i, denomX, i, denomY);\n    }\n    \n    return nom/sqrt(denomX * denomY);\n    \n}\n\ndouble autocorr_lag(const double x[], const int size, const int lag){\n    \n    return corr(x, &(x[lag]), size-lag);\n    \n}\n\ndouble autocov_lag(const double x[], const int size, const int lag){\n    \n    return cov_mean(x, &(x[lag]), size-lag);\n    \n}\n\nvoid zscore_norm(double a[], int size)\n{\n    double m = mean(a, size);\n    double sd = stddev(a, size);\n    for (int i = 0; i < size; i++) {\n        a[i] = (a[i] - m) / sd;\n    }\n    return;\n}\n\nvoid zscore_norm2(const double a[], const int size, double b[])\n{\n    double m = mean(a, size);\n    double sd = stddev(a, size);\n    for (int i = 0; i < size; i++) {\n        b[i] = (a[i] - m) / sd;\n    }\n    return;\n}\n\ndouble moment(const double a[], const int size, const int start, const int end, const int r)\n{\n    int win_size = end - start + 1;\n    a += start;\n    double m = mean(a, win_size);\n    double mr = 0.0;\n    for (int i = 0; i < win_size; i++) {\n        mr += pow(a[i] - m, r);\n    }\n    mr /= win_size;\n    mr /= stddev(a, win_size); //normalize\n    return mr;\n}\n\nvoid diff(const double a[], const int size, double b[])\n{\n    for (int i = 1; i < size; i++) {\n        b[i - 1] = a[i] - a[i - 1];\n    }\n}\n\nint linreg(const int n, const double x[], const double y[], double* m, double* b) //, double* r)\n{\n    double   sumx = 0.0;                      /* sum of x     */\n    double   sumx2 = 0.0;                     /* sum of x**2  */\n    double   sumxy = 0.0;                     /* sum of x * y */\n    double   sumy = 0.0;                      /* sum of y     */\n    double   sumy2 = 0.0;                     /* sum of y**2  */\n    \n    /*\n    for (int i = 0; i < n; i++)\n    {\n        fprintf(stdout, \"x[%i] = %f, y[%i] = %f\\n\", i, x[i], i, y[i]);\n    }\n    */\n    \n    for (int i=0;i<n;i++){\n        sumx  += x[i];\n        sumx2 += x[i] * x[i];\n        sumxy += x[i] * y[i];\n        sumy  += y[i];\n        sumy2 += y[i] * y[i];\n    }\n    \n    double denom = (n * sumx2 - sumx * sumx);\n    if (denom == 0) {\n        // singular matrix. can't solve the problem.\n        *m = 0;\n        *b = 0;\n        //if (r) *r = 0;\n        return 1;\n    }\n    \n    *m = (n * sumxy  -  sumx * sumy) / denom;\n    *b = (sumy * sumx2  -  sumx * sumxy) / denom;\n    \n    /*if (r!=NULL) {\n        *r = (sumxy - sumx * sumy / n) /    // compute correlation coeff\n        sqrt((sumx2 - sumx * sumx/n) *\n             (sumy2 - sumy * sumy/n));\n    }\n    */\n    \n    return 0;\n}\n\ndouble norm_(const double a[], const int size)\n{\n    \n    double out = 0.0;\n    \n    for (int i = 0; i < size; i++)\n    {\n        out += a[i]*a[i];\n    }\n    \n    out = sqrt(out);\n    \n    return out;\n}\n"
  },
  {
    "path": "C/stats.h",
    "content": "#ifndef STATS_H\n#define STATS_H\n#include <math.h>\n#include <stdlib.h>\n#include <string.h>\n\nextern double max_(const double a[], const int size);\nextern double min_(const double a[], const int size);\nextern double mean(const double a[], const int size);\nextern double sum(const double a[], const int size);\nextern void cumsum(const double a[], const int size, double b[]);\nextern void icumsum(const int a[], const int size, int b[]);\nextern double isum(const int a[], const int size);\nextern double median(const double a[], const int size);\nextern double stddev(const double a[], const int size);\nextern double corr(const double x[], const double y[], const int size);\nextern double cov(const double x[], const double y[], const int size);\nextern double cov_mean(const double x[], const double y[], const int size);\nextern double autocorr_lag(const double x[], const int size, const int lag);\nextern double autocov_lag(const double x[], const int size, const int lag);\nextern void zscore_norm(double a[], int size);\nextern void zscore_norm2(const double a[], const int size, double b[]);\nextern double moment(const double a[], const int size, const int start, const int end, const int r);\nextern void diff(const double a[], const int size, double b[]);\nextern int linreg(const int n, const double x[], const double y[], double* m, double* b); //, double* r);\nextern double norm_(const double a[], const int size);\n\n#endif\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n"
  },
  {
    "path": "Matlab/BasisOperations/BF_Binarize.m",
    "content": "function yBin = BF_Binarize(y,binarizeHow)\n% BF_Binarize    Converts an input vector into a binarized version\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n%-------------------------------------------------------------------------------\n% Check inputs, set defaults:\n%-------------------------------------------------------------------------------\nif nargin < 2 || isempty(binarizeHow)\n    binarizeHow = 'diff';\nend\n\n%-------------------------------------------------------------------------------\n% function to transform real values to 0 if <=0 and 1 if >0:\n%-------------------------------------------------------------------------------\n\nfunction Y = stepBinary(X)\n\n    Y = zeros(size(X),'like',X);\n    Y(X > 0) = 1;\n    \nend\n\n%-------------------------------------------------------------------------------\n% Do the binary transformation:\n%-------------------------------------------------------------------------------\n\nswitch binarizeHow\n    case 'diff'\n        % Binary signal: 1 for stepwise increases, 0 for stepwise decreases\n        yBin = stepBinary(diff(y));\n\n    case 'mean'\n        % Binary signal: 1 for above mean, 0 for below mean\n        yBin = stepBinary(y - mean(y));\n\n    case 'median'\n        % Binary signal: 1 for above median, 0 for below median\n        yBin = stepBinary(y - median(y));\n\n    case 'iqr'\n        % Binary signal: 1 if inside interquartile range, 0 otherwise\n        iqr = quantile(y,[0.25, 0.75]);\n        iniqr = (y > iqr(1) & y <= iqr(2));\n        yBin = zeros(length(y),1);\n        yBin(iniqr) = 1;\n\n    otherwise\n        error('Unknown binary transformation setting ''%s''',binarizeHow)\nend\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/CO_AutoCorr.m",
    "content": "function out = CO_AutoCorr(y,tau,whatMethod)\n% CO_AutoCorr   Compute the autocorrelation of an input time series\n%\n%---INPUTS:\n% y, a scalar time series column vector.\n%\n% tau, the time-delay. If tau is a scalar, returns autocorrelation for y at that\n%       lag. If tau is a vector, returns autocorrelations for y at that set of\n%       lags. Can set tau empty, [], to return the full function for the\n%       'Fourier' estimation method.\n%\n% whatMethod, the method of computing the autocorrelation: 'Fourier',\n%             'TimeDomainStat', or 'TimeDomain'.\n%\n%---OUTPUT: the autocorrelation at the given time-lag.\n%\n%---NOTES:\n% Specifying whatMethod = 'TimeDomain' can tolerate NaN values in the time\n% series.\n%\n% Computing mean/std across the full time series makes a significant difference\n% for short time series, but can produce values outside [-1,+1]. The\n% filtering-based method used by Matlab's autocorr, is probably the best for\n% short time series, and is implemented here by specifying: whatMethod =\n% 'Fourier'.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% ------------------------------------------------------------------------------\n% Check inputs:\n% ------------------------------------------------------------------------------\nif nargin < 2\n    tau = 1; % Use a lag of 1 by default\nend\n\nif nargin < 3 || isempty(whatMethod)\n    whatMethod = 'Fourier';\nend\n\n% ------------------------------------------------------------------------------\n% Evaluate the time-series autocorrelation\n% ------------------------------------------------------------------------------\n\nswitch whatMethod\ncase 'Fourier'\n    % ------------------------------------------------------------------------------\n    % Estimation based on Matlab function autocorr, based on method of:\n    % [1] Box, G. E. P., G. M. Jenkins, and G. C. Reinsel. Time Series\n    %     Analysis: Forecasting and Control. 3rd edition. Upper Saddle River,\n    %     NJ: Prentice-Hall, 1994.\n\n    nFFT = 2^(nextpow2(length(y))+1);\n    F = fft(y-mean(y),nFFT);\n    F = F.*conj(F);\n    acf = ifft(F);\n    acf = acf./acf(1); % Normalize\n    acf = real(acf);\n\n    acf = acf(1:length(y));\n\n    if isempty(tau) % return the full function\n        out = acf;\n    else % return a specific set of values\n        out = zeros(length(tau),1);\n        for i = 1:length(tau)\n            if (tau(i) > length(acf)-1) || (tau(i) < 0)\n                out(i) = NaN;\n            else\n                out(i) = acf(tau(i)+1);\n            end\n        end\n    end\n\n\n\nend\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/CO_FirstZero.m",
    "content": "function out = CO_FirstZero(y,corrFun,maxTau)\n% CO_FirstZero      The first zero-crossing of a given autocorrelation function\n%\n%---INPUTS:\n%\n% y, the input time series\n% corrFun, the self-correlation function to measure:\n%         (i) 'ac': normal linear autocorrelation function. Uses CO_AutoCorr to\n%                   calculate autocorrelations.\n% maxTau, a maximum time-delay to search up to.\n%\n% In future, could add an option to return the point at which the function\n% crosses the axis, rather than the first integer lag at which it has already\n% crossed (what is currently implemented).\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% ------------------------------------------------------------------------------\n% Check inputs:\n% ------------------------------------------------------------------------------\n\nN = length(y); % the length of the time series\n\nif nargin < 2 || isempty(corrFun)\n    corrFun = 'ac'; % autocorrelation by default\nend\nif nargin < 3 || isempty(maxTau)\n    maxTau = N; % search up to a maximum of the length of the time series\n    % maxTau = 400; % searches up to this maximum time lag\n    % maxTau = min(maxTau,N); % searched up to the length of the time series if this is less than maxTau\nend\n\n% ------------------------------------------------------------------------------\n% Select the self-correlation function as an inline function\n% Eventually could add additional self-correlation functions\nswitch corrFun\ncase 'ac'\n    % Autocorrelation at all time lags\n    corrs = CO_AutoCorr(y,[],'Fourier');\n    corrs = corrs(2:end); % remove the zero-lag result\notherwise\n    error('Unknown correlation function ''%s''',corrFun);\nend\n\n% Calculate autocorrelation at increasing lags, until you find a negative one\nfor tau = 1:maxTau-1\n    if corrs(tau) < 0 % we know it starts positive (1), so first negative will be the zero-crossing\n        out = tau; return\n    end\nend\n\n% If haven't left yet, set output to maxTau\nout = maxTau;\n\n% make sure this is a scalar output\ncoder.varsize('out', [1, 1], [0 0])\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/CO_trev.m",
    "content": "function out = CO_trev(y, tau)\n% CO_trev   Normalized nonlinear autocorrelation, trev function of a time series\n%\n% Calculates the trev function, a normalized nonlinear autocorrelation,\n% mentioned in the documentation of the TSTOOL nonlinear time-series analysis\n% package (available here: http://www.physik3.gwdg.de/tstool/).\n%\n% The quantity is often used as a nonlinearity statistic in surrogate data\n% analysis, cf. \"Surrogate time series\", T. Schreiber and A. Schmitz, Physica D,\n% 142(3-4) 346 (2000).\n%\n%---INPUTS:\n%\n% y, time series\n%\n% tau, time lag (can be 'ac' or 'mi' to set as the first zero-crossing of the\n%       autocorrelation function, or the first minimum of the automutual\n%       information function, respectively)\n%\n%---OUTPUTS:\n% the trev numerator and the denominator.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% ------------------------------------------------------------------------------\n%% Set defaults:\n% ------------------------------------------------------------------------------\nif nargin < 2 || isempty(tau)\n    tau = 1;\nend\n\n% ------------------------------------------------------------------------------\n% Compute trev quantities\n% ------------------------------------------------------------------------------\n\nyn = y(1:end-tau);\nyn1 = y(1+tau:end); % yn, tau steps ahead\n\n% ------------------------------------------------------------------------------\n% Fill output struct\n% ------------------------------------------------------------------------------\n\n% % The numerator\nout.num = mean((yn1-yn).^3);\n\n% The denominator\nout.denom = (mean((yn1-yn).^2))^(3/2);\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/DN_HistogramMode.m",
    "content": "function out = DN_HistogramMode(y,numBins)\n% DN_HistogramMode      Mode of a data vector.\n%\n% Measures the mode of the data vector using histograms with a given number\n% of bins.\n%\n%---INPUTS:\n%\n% y, the input data vector\n%\n% numBins, the number of bins to use in the histogram.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\nif nargin < 2\n    numBins = 'auto'; % ceil(sqrt(length(y)));\nend\n\n% Compute the histogram from the data:\n[N,binEdges] = histcounts_(y,numBins);\n\n% Compute bin centers from bin edges:\nbinCenters = mean([binEdges(1:end-1); binEdges(2:end)]);\n\n% Mean position of maximums (if multiple):\nout = mean(binCenters(N == max(N)));\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/DN_OutlierInclude_001_mdrmd.m",
    "content": "function out = DN_OutlierInclude_001_mdrmd(y,thresholdHow)\n% DN_OutlierInclude     How statistics depend on distributional outliers.\n%\n% Measures a range of different statistics about the time series as more and\n% more outliers are included in the calculation according to a specified rule,\n% of outliers being furthest from the mean, greatest positive, or negative\n% deviations.\n%\n% The threshold for including time-series data points in the analysis increases\n% from zero to the maximum deviation, in increments of 0.01*sigma (by default),\n% where sigma is the standard deviation of the time series.\n%\n% At each threshold, the mean, standard error, proportion of time series points\n% included, median, and standard deviation are calculated, and outputs from the\n% algorithm measure how these statistical quantities change as more extreme\n% points are included in the calculation.\n%\n%---INPUTS:\n% y, the input time series (ideally z-scored)\n%\n% thresholdHow, the method of how to determine outliers:\n%     (i) 'abs': outliers are furthest from the mean,\n%     (ii) 'p': outliers are the greatest positive deviations from the mean, or\n%     (iii) 'n': outliers are the greatest negative deviations from the mean.\n%\n% inc, the increment to move through (fraction of std if input time series is\n%       z-scored)\n%\n% Most of the outputs measure either exponential, i.e., f(x) = Aexp(Bx)+C, or\n% linear, i.e., f(x) = Ax + B, fits to the sequence of statistics obtained in\n% this way.\n%\n% [future: could compare differences in outputs obtained with 'p', 'n', and\n%               'abs' -- could give an idea as to asymmetries/nonstationarities??]\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% ------------------------------------------------------------------------------\n%% Check Inputs\n% ------------------------------------------------------------------------------\n% If time series is all the same value -- ridiculous! ++BF 21/3/2010\nif all(y == y(1)) % the whole time series is just a single value\n%     fprintf(1,'The time series is a constant!\\n');\n    out = NaN; return % this method is not suitable for such time series: return a NaN\nend\n\nN = length(y); % length of the time series\n\ninc = 0.01;\n\n% ------------------------------------------------------------------------------\n%% Initialize thresholds\n% ------------------------------------------------------------------------------\nswitch thresholdHow\n\n    case 'p' % analyze only positive deviations\n        thr = (0:inc:max(y));\n        tot = sum(y >= 0);\n\n    otherwise % case 'n' % analyze only negative deviations\n        thr = (0:inc:max(-y));\n        tot = sum(y <= 0);\n        \nend\n\nif isempty(thr)\n    error('I suspect that this is a highly peculiar time series?!!!')\nend\n\n% msDt4 = zeros(length(thr),1); % median of index relative to middle\n%                             \n% for i = 1:length(thr)\n%     th = thr(i); % the threshold\n% \n%     % Construct a time series consisting of inter-event intervals for parts\n%     % of the time serie exceeding the threshold, th\n% \n%     if strcmp(thresholdHow,'n')% look at only positive deviations\n%         r = find(y <= -th);\n%     elseif strcmp(thresholdHow,'p')% look at only negative deviations\n%         r = find(y >= th);\n%     end\n%     \n%     msDt4 = median(r)/(N/2)-1;\n% \n% end\n\nmsDt = zeros(length(thr),6); % mean, std, proportion_of_time_series_included,\n                             % median of index relative to middle, mean,\n                             % error\nfor i = 1:length(thr)\n    th = thr(i); % the threshold\n\n    % Construct a time series consisting of inter-event intervals for parts\n    % of the time serie exceeding the threshold, th\n\n    if strcmp(thresholdHow,'n')% look at only positive deviations\n        r = find(y <= -th);\n    else % if strcmp(thresholdHow,'p')% look at only negative deviations\n        r = find(y >= th);\n    end\n    \n    Dt_exc = diff(r); % Delta t (interval) time series; exceeding threshold\n\n    msDt(i,1) = mean(Dt_exc); % the mean value of this sequence\n    msDt(i,3) = length(Dt_exc)/tot*100; % this is just really measuring the distribution\n                                      % : the proportion of possible values\n                                      % that are actually used in\n                                      % calculation\n    msDt(i,4) = median(r)/(N/2)-1;\n\n\nend\n\n% ------------------------------------------------------------------------------\n%% Trim\n% ------------------------------------------------------------------------------\n% Trim off where the number of events is only one; hence the differenced\n% series returns NaN\n%fbi = find(isnan(msDt(:,1)),1,'first'); % first bad index\nfbi = findFirstTrue(isnan(msDt(:,1)));\nif fbi ~= 0\n    msDt = msDt(1:fbi-1,:);\n    thr = thr(1:fbi-1);\nend\n\n% Trim off where the statistic power is lacking: less than 2% of data\n% included\ntrimthr = 2; % percent\n% mj = find(msDt(:,3) > trimthr,1,'last');\nmj = findLastTrue(msDt(:,3) > trimthr);\nif mj ~= 0\n    msDt = msDt(1:mj,:);\n    thr = thr(1:mj);\nend\n\n% ------------------------------------------------------------------------------\n%%% Generate output:\n% ------------------------------------------------------------------------------\n\n%% Stationarity assumption\n\n% mean, median and std of the median and mean of range indices\n% out.mdrm = mean(msDt(:,4));\n% out.mdrmd = median(msDt(:,4));\n% out.mdrstd = std(msDt(:,4));\n% \n% out.mrm = mean(msDt(:,5));\n% out.mrmd = median(msDt(:,5));\n% out.mrstd = std(msDt(:,5));\n\n% mdrmd\nout = median(msDt(:,4)); % median(msDt4(:));\n\n\nend\n\nfunction out = findFirstTrue(y)\n\n    out = 0;\n    \n    coder.varsize('out', [1 1], [0 0]);\n\n    for i = 1:length(y)\n        if y(i)\n            out = i;\n            return\n        end\n    end\n\nend\n\nfunction out = findLastTrue(y)\n\n    out = 0;\n    \n    coder.varsize('out', [1 1], [0 0]);\n\n    for i = length(y):-1:1\n        if y(i)\n            out = i;\n            return\n        end\n    end\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/NK_hist2.m",
    "content": "function [MN, xedges, yedges] = NK_hist2(x, y, xedges, yedges)\n% function MN = NK_hist2(x, y, xedges, yedges)\n%\n% 2D histogram: Extract the number of joint events - (x,y) data value pairs \n% that fall in each bin of the grid defined by xedges and yedges.\n%\n% ====================================================================\n% Uses:\n%    [N,BIN] = histc(X,EDGES)\n% which returns\n%   1) N is a LENGTH(EDGES) vector, N(k) will count the value X(i) if EDGES(k) <= X(i) < EDGES(k+1).  The\n%    last bin will count any values of X that match EDGES(end).\n%   2) an index matrix BIN.\n%    If X is a vector, N(K) = SUM(BIN==K).\n%    BIN is zero for out of range values.\n%    If X is an m-by-n matrix, then, for j=1:n, N(K,j) = SUM(BIN(:,j)==K); end\n% ====================================================================\n%\n%      Please, see the notes to histc too.\n%      N.B. It is always a better idea to use the\n%      HISTC mex (a much faster compiled C code) if you have it\n%      Then just replace the histc with HISTC in all calls\n%      contained in the NK_hist2() .m function\n%\n% (c) Nedialko Krouchev 2006, Universite de Montreal, GRSNC\n\nif nargin ~= 4\n    error('The four input arguments are required!');\nend\nif any(size(x) ~= size(y))\n    error('The size of the two first input vectors should be same!');\nend\n\n[xn, xbin] = histc(x,xedges);\n[yn, ybin] = histc(y,yedges);\n\nxnbin = length(xedges);\nynbin = length(yedges);\n\n%% xbin, ybin are zero for out of range values\nkkL = find( x<xedges(1) ); \nif ~isempty( kkL )\n    xbin = xbin + 1; xnbin = xnbin + 1;\n    xedges(2:xnbin) = xedges; xedges(1) = min(x);\nend\nxbin( kkL ) = 1;\n\nkkR = find( x>xedges(xnbin) );\nif ~isempty( kkR )\n    xnbin = xnbin + 1; xedges(xnbin) = max(x);\nend\nxbin( kkR ) = xnbin;\n\nkkL = find( y<yedges(1) ); \nif ~isempty( kkL ), ybin = ybin + 1; ynbin = ynbin + 1;\n    yedges(2:ynbin) = yedges; yedges(1) = min(y);\nend\nybin( kkL ) = 1;\n\nkkR = find( y>yedges(ynbin) );\nif ~isempty( kkR )\n    ynbin = ynbin + 1; \n    yedges(ynbin) = max(y); \nend\nybin( kkR ) = ynbin;\n\nxyBinEdges = 1:xnbin*ynbin;\n\n% ====================================================================\n% A more Elegant end-spiel:\n%\n% If x  belongs to jBin=xbin(x), and y  belongs to iBin=ybin(y),\n% Then (x,y) pairs belong \"columnwise\" to:\n%       ijBin = (jBin-1)*ynbin + iBin\n\nxyBin = (xbin-1)*ynbin + ybin;\n\n\n% ====================================================================\n\nMN = histc(xyBin, xyBinEdges);\nMN = reshape(MN, ynbin, xnbin);\nend"
  },
  {
    "path": "Matlab/BasisOperations/SB_CoarseGrain_quantile.m",
    "content": "function yth = SB_CoarseGrain_quantile(y,numGroups)\n% SB_CoarseGrain   Coarse-grains a continuous time series to a discrete alphabet.\n%\n%---INPUTS:\n% howtocg = 'quantile' puts an equal number into each bin, the method of coarse-graining\n%\n% numGroups, either specifies the size of the alphabet for 'quantile' and 'updown'\n%       or sets the timedelay for the embedding subroutines\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\nN = length(y); % length of the input sequence\n\n% ------------------------------------------------------------------------------\n% Do the coarse graining\n% ------------------------------------------------------------------------------\n\n% quantile\nth = quantile(y,linspace(0,1,numGroups+1)); % thresholds for dividing the time series values\nth(1) = th(1)-1; % this ensures the first point is included\n% turn the time series into a set of numbers from 1:numGroups\nyth = zeros(N,1);\nfor i = 1:numGroups\n    yth(y > th(i) & y <= th(i+1)) = i;\nend\n\nif any(yth == 0)\n    error('All values in the sequence were not assigned to a group')\nend\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/SB_TransitionMatrix.m",
    "content": "function out = SB_TransitionMatrix(y, numGroups, tauIn)\n% SB_TransitionMatrix  Transition probabilities between different time-series states.\n%\n% The time series is coarse-grained according to a given method.\n%\n% The input time series is transformed into a symbolic string using an\n% equiprobable alphabet of numGroups letters. The transition probabilities are\n% calculated at a lag tau.\n%\n%---INPUTS:\n% y, the input time series\n%\n%\n% numGroups: number of groups in the course-graining\n%\n% tau: analyze transition matricies corresponding to this lag. We\n%      could either downsample the time series at this lag and then do the\n%      discretization as normal, or do the discretization and then just\n%      look at this dicrete lag. Here we do the former. Can also set tau to 'ac'\n%      to set tau to the first zero-crossing of the autocorrelation function.\n%\n%---OUTPUTS: include the transition probabilities themselves, as well as the trace\n% of the transition matrix, measures of asymmetry, and eigenvalues of the\n% transition matrix.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% % ------------------------------------------------------------------------------\n% % Check inputs:\n% % ------------------------------------------------------------------------------\nif nargin < 2 || isempty(numGroups)\n    numGroups = 2;\nend\nif numGroups < 2\n    error('Too few groups for coarse-graining')\nend\n\nif nargin < 3 || isempty(tauIn)\n    tau = 1;\nelseif strcmp(tauIn,'ac') % determine tau from first zero of autocorrelation\n    tau = CO_FirstZero(y,'ac');\nelseif ischar(tauIn) || isstring(tauIn)\n    tau = str2double(tauIn); \nend\n\nif isnan(tau)\n    error('Time series too short to estimate tau');\nend\n\nif tau > 1 % calculate transition matrix at non-unity lag\n    % downsample at rate 1:tau\n    yDown = downsample(y,tau);\n%     yDown = decimate_(y,tau);\n%     yDown = resample(y,1,tau);\nelse\n    yDown = y;\nend\n\nN = length(yDown); % time-series length\n\n% ------------------------------------------------------------------------------\n%% (((1))) Discretize the time series\n% ------------------------------------------------------------------------------\nyth = SB_CoarseGrain_quantile(yDown,numGroups);\n\n% At this point we should have:\n% (*) yth: a thresholded y containing integers from 1 to numGroups\n\n% ------------------------------------------------------------------------------\n%% (((2))) find 1-time transition matrix\n% ------------------------------------------------------------------------------\n% Probably implemented already, but I'll do it myself\nT = zeros(numGroups); % probability of transition from state i -> state j\nfor i = 1:numGroups\n    ri = (yth == i); % indices where the time series is in state i\n    if sum(ri)==0 % is never in state i\n        T(i,:) = 0; % all transition probabilities are zero (could be NaN)\n    else\n        % Indices of states immediately following a state i:\n        ri_next = [logical(0);ri(1:end-1)];\n        % Compute transitions from state i to each of the states j:\n        for j = 1:numGroups\n            T(i,j) = sum(yth(ri_next) == j); % the next element is of this class\n        end\n    end\nend\n\n% Normalize from counts to probabilities:\nT = T/(N-1); % N-1 is appropriate because it's a 1-time transition matrix\n\n% ------------------------------------------------------------------------------\n%% (((3))) output measures from the transition matrix\n% ------------------------------------------------------------------------------\n% % (i) Raw values of the transition matrix\n% % [this has to be done bulkily (only for numGroups = 2,3)]:\n% if numGroups == 2; % return all elements of T\n%     for i = 1:4\n%         out.(sprintf('T%u',i)) = T(i);\n%     end\n% elseif numGroups == 3; % return all elements of T\n%     for i = 1:9\n%         out.(sprintf('T%u',i)) = T(i);\n%     end\n% elseif numGroups > 3 % return just diagonal elements of T\n%     for i = 1:numGroups\n%         out.(sprintf('TD%u',i)) = T(i,i);\n%     end\n% end\n\n% (ii) Measures on the diagonal\nout.ondiag = sum(diag(T)); % trace\n% out.stddiag = std(diag(T)); % std of diagonal elements\n% \n% % (iii) Measures of symmetry:\n% out.symdiff = sum(sum(abs((T-T')))); % sum of differences of individual elements\n% out.symsumdiff = sum(sum(tril(T,-1)))-sum(sum(triu(T,+1))); % difference in sums of upper and lower\n                                                          % triangular parts of T\n\n% (iv) Measures from covariance matrix:\ncovT = cov(T);\nout.sumdiagcov = sum(diag(covT)); % trace of covariance matrix\n\n% % % (v) Measures from eigenvalues of T\n% % eigT = eig(T);\n% % out.stdeig = std(eigT); % std of eigenvalues\n% % out.maxeig = max(real(eigT)); % maximum eigenvalue\n% % out.mineig = min(real(eigT)); % minimum eigenvalue\n% % % mean eigenvalue is equivalent to trace\n% % % (ought to be always zero? Not necessary to measure:)\n% % out.maximeig = max(imag(eigT)); % maximum imaginary part of eigenavlues\n% % \n% % (vi) Eigenvalues of covariance matrix:\n% % (mean eigenvalue of covariance matrix equivalent to trace of covariance matrix).\n% % (these measures don't make much sense in the case of 2 groups):\n% eigcovT = eig(covT);\n% % out.stdeigcov = std(eigcovT); % std of eigenvalues of covariance matrix\n% out.maxeigcov = real(max(eigcovT)); % (made real for C-implementation) max eigenvalue of covariance matrix\n% % out.mineigcov = min(eigcovT); % min eigenvalue of covariance matrix\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/SC_FluctAnal_q2_taustep50_k1_logi_prop_r1.m",
    "content": "function out = SC_FluctAnal_q2_taustep50_k1_logi_prop_r1(x,wtf,lag)\n% SC_FluctAnal   Implements fluctuation analysis by a variety of methods.\n%\n% Much of our implementation is based on the well-explained discussion of\n% scaling methods in:\n% \"Power spectrum and detrended fluctuation analysis: Application to daily\n% temperatures\" P. Talkner and R. O. Weber, Phys. Rev. E 62(1) 150 (2000)\n%\n% The main difference between algorithms for estimating scaling exponents amount\n% to differences in how fluctuations, F, are quantified in time-series segments.\n% Many alternatives are implemented in this function.\n%\n%---INPUTS:\n% y, the input time series\n%\n% q=2, the parameter in the fluctuation function q = 2 (usual) gives RMS fluctuations.\n%\n% wtf, (what to fluctuate)\n%       (i) 'dfa' removes a polynomial trend of order k in each segment,\n% \n%       (ii) 'rsrangefit' fits a polynomial of order k and then returns the\n%           range. The parameter q controls the order of fluctuations, for which\n%           we mostly use the standard choice, q = 2, corresponding to root mean\n%           square fluctuations.\n%           An optional input parameter to this operation is a timelag for\n%           computing the cumulative sum (or integrated profile), as suggested\n%           by: \"Using detrended fluctuation analysis for lagged correlation\n%           analysis of nonstationary signals\" J. Alvarez-Ramirez et al. Phys.\n%           Rev. E 79(5) 057202 (2009)\n%\n% tauStep=50, increments in tau for linear range (i.e., if logInc = 0), or number of tau\n%           steps in logarithmic range if login = 1\n%           The spacing of time scales, tau, is commonly logarithmic through a range from\n%           5 samples to a quarter of the length of the time series, as suggested in\n%           \"Statistical properties of DNA sequences\", C.-K. Peng et al. Physica A\n%           221(1-3) 180 (1995)\n%\n%           Max A. Little's fractal paper used L = 4 to L = N/2:\n%           \"Exploiting Nonlinear Recurrence and Fractal Scaling Properties for Voice Disorder Detection\"\n%           M. A. Little et al. Biomed. Eng. Online 6(1) 23 (2007)\n%\n% k=1, polynomial order of detrending for 'dfa', 'rsrangefit'\n%\n% lag, optional time-lag, as in Alvarez-Ramirez (see (vii) above)\n%\n% logInc=1, whether to use logarithmic increments in tau (it should be logarithmic).\n%\n%---OUTPUTS: include statistics of fitting a linear function to a plot of log(F) as\n% a function of log(tau), and for fitting two straight lines to the same data,\n% choosing the split point at tau = tau_{split} as that which minimizes the\n% combined fitting errors.\n%\n% This function can also be applied to the absolute deviations of the time\n% series from its mean, and also for just the sign of deviations from the mean\n% (i.e., converting the time series into a series of +1, when the time series is\n% above its mean, and -1 when the time series is below its mean).\n%\n% All results are obtained with both linearly, and logarithmically-spaced time\n% scales tau.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% ------------------------------------------------------------------------------\n% Check Inputs:\n% ------------------------------------------------------------------------------\n\nif nargin < 2 || isempty(wtf)\n    wtf = 'rsrange'; % re-scaled range analysis by default\nend\n\nif nargin < 3 || isempty(lag)\n    lag = '';\nend\n\nq = 2;\ntauStep = 50;\nk = 1;\n\n% ------------------------------------------------------------------------------\n% ------------------------------------------------------------------------------\n\nN = length(x); % length of the time series\ndoPlot = 0; % plot relevant outputs to figure\n\n% 1) Compute integrated sequence\n\nif isempty(lag)\n    % didn't specify a lag, do a normal cumsum:\n    y = cumsum(x);\nelse\n    % specified a lag, do a decimation:\n    y = cumsum(x(1:lag:end));\nend\n\n%-------------------------------------------------------------------------------\n% Perform scaling over a range of tau, up to a fifth the time-series length\n%-------------------------------------------------------------------------------\n% Peng (1995) suggests 5:N/4 for DFA\n% Caccia suggested from 10 to (N-1)/2...\n%-------------------------------------------------------------------------------\ntaur = unique(round(exp(linspace(log(5),log(floor(N/2)),tauStep))));\nntau = length(taur); % analyze the time series across this many timescales\n\nif ntau < 8 % fewer than 8 points\n%     fprintf(1,'This time series (N = %u) is too short to analyze using this fluctuation analysis\\n',N);\n    out = NaN;\n    return\nend\n\n% 2) Compute the fluctuation function as follows\nF = zeros(1,ntau);\n% F is the fluctuation function\n% each entry correponds to a given scale tau, and contains\n% the fluctuation function at that scale\n\nfor i = 1:ntau\n    % buffer the time series at the scale tau\n    tau = taur(i); % the scale on which to compute fluctuations\n\n    % y_buff = buffer(y,tau); % buff not supported by Coder\n    y_buff = buffer_(y,tau);\n      \n    if size(y_buff,2) > floor(length(y)/tau) % zero-padded, remove trailing set of points...\n        y_buff = y_buff(:,1:end-1);\n    end\n\n    % analyzed length of time series (with trailing end-points removed)\n    nn = size(y_buff,2)*tau;\n\n    switch wtf\n        case 'dfa'\n            tt = (1:tau)'; % faux time range\n            for j = 1:size(y_buff,2)\n                % fit a polynomial of order k in each subsegment\n                p = polyfit(tt,y_buff(:,j),k);\n                % remove the trend, store back in y_buff\n                y_buff(:,j) = y_buff(:,j) - polyval(p,tt);\n            end\n            % reshape to a column vector, y_dt (detrended)\n            y_dt = reshape(y_buff,nn,1);\n        case 'rsrangefit' % polynomial fit (order k) rather than endpoints fit: (~DFA)\n            tt = (1:tau)'; % faux time range\n            for j = 1:size(y_buff,2)\n                % fit a polynomial of order k in each subsegment\n                p = polyfit(tt,y_buff(:,j),k);\n                % remove the trend, store back in y_buff\n                y_buff(:,j) = y_buff(:,j) - polyval(p,tt);\n            end\n            y_dt = max(y_buff) - min(y_buff); % range(y_buff);\n        otherwise\n            error('Unknown fluctuation analysis method ''%s''',wtf);\n    end\n\n    % Compute fluctuation function:\n    F(i) = (mean(y_dt.^q)).^(1/q);\nend\n\n\n%-------------------------------------------------------------------------------\n% Smooth unevenly-distributed points in log space:\n%-------------------------------------------------------------------------------\nlogtt = log(taur);\nlogFF = log(F);\nntt = ntau;\n\n% ------------------------------------------------------------------------------\n%% Try assuming two components (2 distinct scaling regimes)\n% ------------------------------------------------------------------------------\n% Move through, and fit a straight line to loglog before and after each point.\n% Find point with the minimum sum of squared errors\n\n% First spline interpolate to get an even sampling of the interval\n% (currently, in the log scale, there are relatively more at large scales\n\n% Deterine the errors\nsserr = nan(ntt,1); % don't choose the end points\nminPoints = 6;\nfor i = minPoints:ntt-minPoints\n    r1 = 1:i;\n    p1 = polyfit(logtt(r1),logFF(r1),1);\n    r2 = i:ntt;\n    p2 = polyfit(logtt(r2),logFF(r2),1);\n    % Sum of errors from fitting lines to both segments:\n    sserr(i) = norm(polyval(p1,logtt(r1))-logFF(r1)) + norm(polyval(p2,logtt(r2))-logFF(r2));\nend\n\n% breakPt is the point where it's best to fit a line before and another line after\nbreakPt = find(sserr == min(sserr),1,'first');\nr1 = 1:breakPt;\nprop_r1 = length(r1)/ntt;\n\n% output\nout = prop_r1;\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/SP_Summaries_welch_rect.m",
    "content": "function out = SP_Summaries_welch_rect(y)\n% SP_Summaries  Statistics of the power spectrum of a time series\n%\n% The estimation can be done using a periodogram, using the periodogram code in\n% Matlab's Signal Processing Toolbox, or a fast fourier transform, implemented\n% using Matlab's fft code.\n%\n%---INPUTS:\n% y, the input time series\n%\n% psdMeth, the method of obtaining the spectrum from the signal:\n%               (i) 'periodogram': periodogram\n%               (ii) 'fft': fast fourier transform\n%               (iii) 'welch': Welch's method\n%\n% windowType='rect', the window to use:\n%               (i) 'boxcar'\n%               (ii) 'rect'\n%               (iii) 'bartlett'\n%               (iv) 'hann'\n%               (v) 'hamming'\n%               (vi) 'none'\n%\n% nf, the number of frequency components to include, if\n%           empty (default), it's approx length(y)\n%\n% dologabs, if 1, takes log amplitude of the signal before\n%           transforming to the frequency domain.\n%\n% doPower, analyzes the power spectrum rather than amplitudes of a Fourier\n%          transform\n%\n%---OUTPUTS:\n% Statistics summarizing various properties of the spectrum,\n% including its maximum, minimum, spread, correlation, centroid, area in certain\n% (normalized) frequency bands, moments of the spectrum, Shannon spectral\n% entropy, a spectral flatness measure, power-law fits, and the number of\n% crossings of the spectrum at various amplitude thresholds.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% % ------------------------------------------------------------------------------\n% %% Check that a Curve-Fitting Toolbox license is available:\n% % ------------------------------------------------------------------------------\n% BF_CheckToolbox('curve_fitting_toolbox')\n\n% ------------------------------------------------------------------------------\n% Check inputs, set defaults:\n% ------------------------------------------------------------------------------\n% if size(y,2) > size(y,1)\n%     y = y'; % Time series must be a column vector\n% end\n% if nargin < 2 || isempty(psdMeth)\n%     psdMeth = 'fft'; % fft by default\n% end\n% if nargin < 3 || isempty(windowType)\n%     windowType = 'hamming'; % Hamming window by default\n% end\n% if nargin < 4\n%     nf = [];\n% end\n% if nargin < 5 || isempty(dologabs)\n%     dologabs = false;\n% end\n% \n% if dologabs % a boolean\n%     % Analyze the spectrum of logarithmic absolute deviations\n%     y = log(abs(y));\n% end\n\ndoPlot = false; % plot outputs\nNy = length(y); % time-series length\n\n% default output\nout.centroid = NaN;\nout.area_5_1 = NaN;\n\n%-------------------------------------------------------------------------------\n% Set window (for periodogram and welch):\n%-------------------------------------------------------------------------------\n\nwindow = ones(Ny,1); % rectwin(Ny);\n\n% ------------------------------------------------------------------------------\n% Compute the Fourier Transform\n% ------------------------------------------------------------------------------\n\n% Welch power spectral density estimate:\nFs = 1; % sampling frequency\nN = 2^nextpow2(Ny);\n% [S, f] = pwelch(y,window,[],N,Fs);\n% substitute with own Welch spectrum\n[S_, f_] = welchy(y, N, Fs, window);\n\nw_ = 2*pi*f_'; % angular frequency\nS_ = S_/(2*pi); % adjust so that area remains normalized in angular frequency space\n\nif ~any(isfinite(S_)) % no finite values in the power spectrum\n    % This time series must be really weird -- return NaN (unsuitable operation)...\n    % warning('NaN in power spectrum? A weird time series.');\n    return\nend\n\n% Ensure both w and S are row vectors:\nif size(S_,1) > size(S_,2)\n    S = S_';\nelse\n    S = S_;\nend\nif size(w_,1) > size(w_,2)\n    w = w_';\nelse\n    w = w_;\nend\n\n% if doPlot\n%     figure('color','w')\n%     plot(w,S,'.-k'); % plot the spectrum\n%     % Area under S should sum to 1 if a power spectral density estimate:\n%     title(sprintf('Area under psd curve = %.1f (= %.1f)',sum(S*(w(2)-w(1))),var(y)));\n% end\n\nN = length(S);\ndw = w(2) - w(1); % spacing increment in w\n\n% ------------------------------------------------------------------------------\n% Shape of cumulative sum curve\n% ------------------------------------------------------------------------------\ncsS = cumsum(S);\n\n% this original was not well received by coder.\n% f_frac_w_max = @(f) w(find(csS >= csS(end)*f,1,'first'));\n\n% At what frequency is csS a fraction 0.5 of its maximum?\ncsSThres = csS(end)*0.5;\nfor i = 1:length(csS)\n    if csS(i) > csSThres\n        out.centroid = w(i);\n        break\n    end\nend\n\n% % wInd = find((csS >= csS(end)*0.5),1, 'first');\n% % out = w(wInd); % f_frac_w_max(0.5);\n% out = NaN;\n\n% 5 bands\nsplit = buffer_(S,floor(N/5));\nif size(split,2) > 5, split = split(:,1:5); end\nout.area_5_1 = sum(split(:,1))*dw;\n\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/buffer_.m",
    "content": "function y_buff = buffer_(y, tau)\n\n% replacement for y_buff = buffer(y,tau)\n\nnCols = ceil(length(y)/tau);\nyPadded = zeros(nCols*tau,1);\nyPadded(1:length(y)) = y;\ny_buff = reshape(yPadded, tau, nCols); "
  },
  {
    "path": "Matlab/BasisOperations/decimate_.m",
    "content": "function out = decimate_(y, q)\n\n    nfilt = 4;\n    \n    nd = length(y);\n\n    [b,a] = myButter(nfilt, 0.8/q);\n\n    % be sure to filter in both directions to make sure the filtered data has zero phase\n    % make a data vector properly pre- and ap- pended to filter forwards and back\n    % so end effects can be obliterated.\n    out_filt = filtfilt_(b,a,y);\n    nbeg = 1;\n    out = out_filt((nbeg:q:nd)');\n    "
  },
  {
    "path": "Matlab/BasisOperations/downsample_.m",
    "content": "%-------------------------------------------------------------------------\nfunction  [y, h] = downsample_( x, q )\n\np = 1;\nbta = 5;\nN = 10;\n\nif (p==1) && (q==1)\n    y = x; \n    h = 1;\n    return\nend\npqmax = max(p,q);\nif length(N)>1      % use input filter\n   L = length(N);\n   h = N;\nelse                % design filter\n   if( N>0 )\n      fc = 1/2/pqmax;\n      L = 2*N*pqmax + 1;\n      h = firls( L-1, [0 2*fc 2*fc 1], [1 1 0 0]).*kaiser(L,bta)' ;\n      h = p*h/sum(h);\n   else\n      L = p;\n      h = ones(1,p);\n   end\nend\n\nLhalf = (L-1)/2;\nisvect = any(size(x)==1);\nif isvect\n    Lx = length(x);\nelse\n    Lx = size(x, 1);\nend\n\n% Need to delay output so that downsampling by q hits center tap of filter.\nnz = floor(q-mod(Lhalf,q));\nz = zeros(1,nz);\nh = [z h(:).'];  % ensure that h is a row vector.\nLhalf = Lhalf + nz;\n\n% Number of samples removed from beginning of output sequence \n% to compensate for delay of linear phase filter:\ndelay = floor(ceil(Lhalf)/q);\n\n% Need to zero-pad so output length is exactly ceil(Lx*p/q).\nnz1 = 0;\nwhile ceil( ((Lx-1)*p+length(h)+nz1 )/q ) - delay < ceil(Lx*p/q)\n    nz1 = nz1+1;\nend\nh = [h zeros(1,nz1)];\n\n% ----  HERE'S THE CALL TO UPFIRDN  ----------------------------\ny = upfirdn(x,h,p,q);\n\n% Get rid of trailing and leading data so input and output signals line up\n% temporally:\nLy = ceil(Lx*p/q);  % output length\n% Ly = floor((Lx-1)*p/q+1);  <-- alternately, to prevent \"running-off\" the\n%                                data (extrapolation)\nif isvect\n    y(1:delay) = [];\n    y(Ly+1:end) = [];\nelse\n    y(1:delay,:) = [];\n    y(Ly+1:end,:) = [];\nend\n\nh([1:nz (end-nz1+1):end]) = [];  % get rid of leading and trailing zeros \n                                 % in case filter is output"
  },
  {
    "path": "Matlab/BasisOperations/filtfilt_.m",
    "content": "function y = filtfilt_(b,a,x)\n%FILTFILT Zero-phase forward and reverse digital IIR filtering.\n%   Y = FILTFILT(B, A, X) filters the data in vector X with the filter\n%   described by vectors A and B to create the filtered data Y.  The filter\n%   is described by the difference equation:\n%\n%     a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)\n%                           - a(2)*y(n-1) - ... - a(na+1)*y(n-na)\n%\n%   The length of the input X must be more than three times the filter\n%   order, defined as max(length(B)-1,length(A)-1).\n%\n%   References:\n%     [1] Sanjit K. Mitra, Digital Signal Processing, 2nd ed.,\n%         McGraw-Hill, 2001\n%     [2] Fredrik Gustafsson, Determining the initial states in forward-\n%         backward filtering, IEEE Transactions on Signal Processing,\n%         pp. 988-992, April 1996, Volume 44, Issue 4\n\n%   Copyright 1988-2014 The MathWorks, Inc.\n\n\n%% Parse coefficient coefficients vectors and determine initial conditions\n\nna = numel(a);\n\nL = 1;\n% Check coefficients\nb = b(:);\na = a(:);\nnb = numel(b);\nnfilt = max(nb,na);   \nnfact = max(1,3*(nfilt-1));  % length of edge transients\n\n% Zero pad shorter coefficient vector as needed\nif nb < nfilt\n    b(nfilt,1)=0;\nelseif na < nfilt\n    a(nfilt,1)=0;\nend\n\n% Compute initial conditions to remove DC offset\nif nfilt>1\n    zi = ( eye(nfilt-1) - [-a(2:nfilt), [eye(nfilt-2); ...\n                                      zeros(1,nfilt-2)]] ) \\ ...\n     ( b(2:nfilt) - b(1)*a(2:nfilt) );\nelse\n    zi = zeros(0,1);\nend\n\n%% Filter the data\nfor ii=1:L\n    \n    y = [2*x(1)-x(nfact+1:-1:2); x; 2*x(end)-x(end-1:-1:end-nfact)];\n    \n    % filter, reverse data, filter again, and reverse data again\n    y = filter(b(:,ii),a(:,ii),y,zi(:,ii)*y(1));\n    y = y(end:-1:1);\n    y = filter(b(:,ii),a(:,ii),y,zi(:,ii)*y(1));\n    \n    % retain reversed central section of y\n    y = y(end-nfact:-1:nfact+1);\nend\n"
  },
  {
    "path": "Matlab/BasisOperations/histcounts_.m",
    "content": "function [N, binEdges] = histcounts_(d, nBinsIn, normalise)\n    % own function for counting \n\n    if nargin<2 || isempty(nBinsIn)\n        nBinsIn = [];\n    end\n    \n    if nargin<3 || isempty(normalise)\n        normalise = false;\n    end\n\n    \n    dMinMax = [min(d), max(d)];\n    dRange = dMinMax(2) - dMinMax(1);\n    \n    % fixed or automatic number of bins\n    if isempty(nBinsIn)\n        nBins = ceil(dRange/(3.5*std(d)/(numel(d)^(1/3))));\n    else\n        nBins = nBinsIn;\n    end\n    \n    % compute edges\n    binWidth = dRange/nBins;\n    binEdges = dMinMax(1) + (0:nBins)*binWidth;\n    \n    % count occurences in bins\n    N = zeros(nBins, 1);\n    d_ = d - dMinMax(1);\n    for i = 1:length(d_)\n        binInd = floor(d_(i)/binWidth)+1;\n        binInd = max(1, binInd);\n        binInd = min(nBins, binInd);\n        N(binInd) = N(binInd) + 1;\n    end\n    \n    % probability normalisation\n    if normalise\n        N = N./numel(d);\n    end"
  },
  {
    "path": "Matlab/BasisOperations/myButter.m",
    "content": "function [Z_out, P_out] = myButter(n, W)\n% Digital Butterworth filter, either 2 or 3 outputs\n% Jan Simon, 2014, BSD licence\n% See docs of BUTTER for input and output\n% Fast hack with limited accuracy: Handle with care!\n% Until n=15 the relative difference to Matlab's BUTTER is < 100*eps\nV = tan(W * 1.5707963267948966);\nQ = exp((1.5707963267948966i / n) * ((2 + n - 1):2:(3 * n - 1)));\nnQ = length(Q);\n\nSg = V ^ nQ;\nSp = V * Q;\nSz = [];\n\n% Bilinear transform:\nP = (1 + Sp) ./ (1 - Sp);\nZ = repmat(-1, size(P));\nif isempty(Sz)\n   G = real(Sg / prod(1 - Sp));\nelse\n   G = real(Sg * prod(1 - Sz) / prod(1 - Sp));\n   Z(1:length(Sz)) = (1 + Sz) ./ (1 - Sz);\nend\n\n% From Zeros, Poles and Gain to B (numerator) and A (denominator):\nZ_out = G * real(poly(Z'));\nP_out = real(poly(P));\n"
  },
  {
    "path": "Matlab/BasisOperations/poly_.m",
    "content": "function c = poly_(x)\n%POLY Convert roots to polynomial.\n%   POLY(A), when A is an N by N matrix, is a row vector with\n%   N+1 elements which are the coefficients of the\n%   characteristic polynomial, det(lambda*eye(size(A)) - A).\n%\n%   POLY(V), when V is a vector, is a vector whose elements are\n%   the coefficients of the polynomial whose roots are the\n%   elements of V. For vectors, ROOTS and POLY are inverse\n%   functions of each other, up to ordering, scaling, and\n%   roundoff error.\n%\n%   Examples:\n%\n%   roots(poly(1:20)) generates Wilkinson's famous example.\n%\n%   Class support for inputs A,V:\n%      float: double, single\n%\n%   See also ROOTS, CONV, RESIDUE, POLYVAL.\n\n%   Copyright 1984-2014 The MathWorks, Inc.\n\n[m,n] = size(x);\nif m == n\n   % Characteristic polynomial (square x)\n   e = eig(x);\nelseif (m==1) || (n==1)\n   e = x;\nelse\n   error(message('MATLAB:poly:InputSize'))\nend\n\n% Strip out infinities\ne = e( isfinite(e) );\n\n% Expand recursion formula\nn = length(e);\nc = [1 zeros(1,n,class(x))];\nfor j=1:n\n    j\n    c(2:(j+1))\n    e(j)\n    c(1:j)\n    e(j).*c(1:j)\n    \n    c(2:(j+1)) = c(2:(j+1)) - e(j).*c(1:j);\nend\n\n% The result should be real if the roots are complex conjugates.\nif isequal(sort(e(imag(e)>0)),sort(conj(e(imag(e)<0))))\n    c = real(c);\nend"
  },
  {
    "path": "Matlab/BasisOperations/splinefit.m",
    "content": "function pp = splinefit(y)\n%SPLINEFIT Fit a spline to noisy data.\n%   PP = SPLINEFIT(X,Y,BREAKS) fits a piecewise cubic spline with breaks\n%   (knots) BREAKS to the noisy data (X,Y). X is a vector and Y is a vector\n%   or an ND array. If Y is an ND array, then X(j) and Y(:,...,:,j) are\n%   matched. Use PPVAL to evaluate PP.\n%\n%   PP = SPLINEFIT(X,Y,P) where P is a positive integer interpolates the\n%   breaks linearly from the sorted locations of X. P is the number of\n%   spline pieces and P+1 is the number of breaks.\n%\n%   OPTIONAL INPUT\n%   Argument places 4 to 8 are reserved for optional input.\n%   These optional arguments can be given in any order:\n%\n%   PP = SPLINEFIT(...,'p') applies periodic boundary conditions to\n%   the spline. The period length is MAX(BREAKS)-MIN(BREAKS).\n%\n%   PP = SPLINEFIT(...,'r') uses robust fitting to reduce the influence\n%   from outlying data points. Three iterations of weighted least squares\n%   are performed. Weights are computed from previous residuals.\n%\n%   PP = SPLINEFIT(...,BETA), where 0 < BETA < 1, sets the robust fitting\n%   parameter BETA and activates robust fitting ('r' can be omitted).\n%   Default is BETA = 1/2. BETA close to 0 gives all data equal weighting.\n%   Increase BETA to reduce the influence from outlying data. BETA close\n%   to 1 may cause instability or rank deficiency.\n%\n%   PP = SPLINEFIT(...,N) sets the spline order to N. Default is a cubic\n%   spline with order N = 4. A spline with P pieces has P+N-1 degrees of\n%   freedom. With periodic boundary conditions the degrees of freedom are\n%   reduced to P.\n%\n%   PP = SPLINEFIT(...,CON) applies linear constraints to the spline.\n%   CON is a structure with fields 'xc', 'yc' and 'cc':\n%       'xc', x-locations (vector)\n%       'yc', y-values (vector or ND array)\n%       'cc', coefficients (matrix).\n%\n%   Constraints are linear combinations of derivatives of order 0 to N-2\n%   according to\n%\n%     cc(1,j)*y(x) + cc(2,j)*y'(x) + ... = yc(:,...,:,j),  x = xc(j).\n%\n%   The maximum number of rows for 'cc' is N-1. If omitted or empty 'cc'\n%   defaults to a single row of ones. Default for 'yc' is a zero array.\n%\n%   EXAMPLES\n%\n%       % Noisy data\n%       x = linspace(0,2*pi,100);\n%       y = sin(x) + 0.1*randn(size(x));\n%       % Breaks\n%       breaks = [0:5,2*pi];\n%\n%       % Fit a spline of order 5\n%       pp = splinefit(x,y,breaks,5);\n%\n%       % Fit a spline of order 3 with periodic boundary conditions\n%       pp = splinefit(x,y,breaks,3,'p');\n%\n%       % Constraints: y(0) = 0, y'(0) = 1 and y(3) + y\"(3) = 0\n%       xc = [0 0 3];\n%       yc = [0 1 0];\n%       cc = [1 0 1; 0 1 0; 0 0 1];\n%       con = struct('xc',xc,'yc',yc,'cc',cc);\n%\n%       % Fit a cubic spline with 8 pieces and constraints\n%       pp = splinefit(x,y,8,con);\n%\n%       % Fit a spline of order 6 with constraints and periodicity\n%       pp = splinefit(x,y,breaks,con,6,'p');\n%\n%   See also SPLINE, PPVAL, PPDIFF, PPINT\n\n%   Author: Jonas Lundgren <splinefit@gmail.com> 2010\n\n%   2009-05-06  Original SPLINEFIT.\n%   2010-06-23  New version of SPLINEFIT based on B-splines.\n%   2010-09-01  Robust fitting scheme added.\n%   2010-09-01  Support for data containing NaNs.\n%   2011-07-01  Robust fitting parameter added.\n\n%Copyright (c) 2017, Jonas Lundgren\n% All rights reserved.\n% \n% Redistribution and use in source and binary forms, with or without\n% modification, are permitted provided that the following conditions are met:\n% \n% * Redistributions of source code must retain the above copyright notice, this\n%   list of conditions and the following disclaimer.\n% \n% * Redistributions in binary form must reproduce the above copyright notice,\n%   this list of conditions and the following disclaimer in the documentation\n%   and/or other materials provided with the distribution\n% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\n% FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n% DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n% inputs\nx = 1:length(y);\nbreaks = [1, floor(length(y)/2), length(y)];\nn = 4;\nbeta = 0;\ndim = 1;\n\n% Evaluate B-splines\n[breaksB,coefsB,nB] = splinebase(breaks,n);\n% % Make piecewise polynomial\n% base = mkpp(breaksB,coefsB,nB);\n\ncoder.varsize('coefsB',[8 4], [0 0]);\n\n% just don't use the struct...\nif nargin==2, nB = 1; else nB = nB(:).'; end\ndlk=numel(coefsB); l=length(breaksB)-1; dl=prod(nB)*l; k=fix(dlk/dl+100*eps);\n% if (k<=0)||(dl*k~=dlk)\n%    error(message('MATLAB:mkpp:PPNumberMismatchCoeffs',...\n%        int2str(l),int2str(d),int2str(dlk)))\n% end\n\nbreaksBase = reshape(breaksB,1,l+1);\ncoefsBase = coefsB; % reshape(coefsB,dl,k);\nlBase = l;\nkBase = k;\ndBase = nB;\n\npieces = lBase;\n\n% try this to get around unbounded-error in Coder.\ncoder.varsize('coefsBase',[8 4], [0 0]);\n\nbase = mkpp(breaksBase,coefsBase,dBase); % lBase,kBase,\nA_base = ppval(base,x);\n\n% Bin data\n[junk,ibin] = histc(x,[-inf,breaks(2:end-1),inf]); %#ok\n\n% Sparse system matrix\nmx = numel(x);\nii = [ibin; ones(n-1,mx)];\nii = cumsum(ii,1);\njj = repmat(1:mx,n,1);\n\nA = zeros(pieces+n-1,mx);\nlinIndices = sub2ind(size(A), ii, jj);\nA(linIndices)=A_base;\n\n% flipPoint = breaks(2)-1;\n% coder.varsize('flipPoint',[1 1], [0 0]);\n% A(1:end-1, 1:flipPoint) = A_base(:, 1:flipPoint);\n% A(2:end, (flipPoint+1):end) = A_base(:, (flipPoint+1):end);\n\n% Solve Min norm(u*A-y)\nu = lsqsolve(A,y,beta);\n\n% Compute polynomial coefficients\nii = [repmat(1:pieces,1,n); ones(n-1,n*pieces)];\nii = cumsum(ii,1);\njj = repmat(1:n*pieces,n,1);\n% C = sparse(ii,jj,base.coefs,pieces+n-1,n*pieces);\n\nC = zeros(pieces+n-1,n*pieces);\nlinIndices = sub2ind(size(C), ii, jj);\nC(linIndices)=base.coefs;\n\ncoefs = u*C;\ncoefs = reshape(coefs,[],n);\n\n% Make piecewise polynomial\npp = mkpp(breaks,coefs,dim);\n\n\n%--------------------------------------------------------------------------\nfunction [breaks0,coefsOut,n] = splinebase(breaks0,n)\n%SPLINEBASE Generate B-spline base PP of order N for breaks BREAKS\n\nassert (n == 4);\n\nbreaks0 = breaks0(:);     % Breaks\n% breaks0 = breaks0';      % Initial breaks\nh0 = diff(breaks0);       % Spacing\npieces0 = numel(h0);      % Number of pieces\ndeg = n - 1;            % Polynomial degree\n\n% distances between knots to replicate points to the sides\nhcopy = repmat(h0,ceil(deg/pieces0),1);\n\n% to the left\nhl = hcopy(end:-1:end-deg+1);\nbl = breaks0(1) - cumsum(hl);\n% and to the right\nhr = hcopy(1:deg);\nbr = breaks0(end) + cumsum(hr);\n\n% Add breaks\nbreaks = [bl(deg:-1:1); breaks0; br];\nh = diff(breaks);\npieces = numel(h);\n\nassert (pieces == 8);\n\n% Initiate polynomial coefficients\ncoefs = zeros(n*pieces,n);\ncoefs(1:n:end,1) = 1;\n\n% Expand h\nii = [1:pieces; ones(deg,pieces)];\nii = cumsum(ii,1);\nii = min(ii,pieces);\nH = h(ii(:));\n\n% Recursive generation of B-splines\nfor k = 2:n\n    % Antiderivatives of splines\n    for j = 1:k-1\n        coefs(:,j) = coefs(:,j).*H/(k-j);\n    end\n    Q = sum(coefs,2);\n    Q = reshape(Q,n,pieces);\n    Q = cumsum(Q,1);\n    c0 = [zeros(1,pieces); Q(1:deg,:)];\n    coefs(:,k) = c0(:);\n    % Normalize antiderivatives by max value\n    fmax = repmat(Q(n,:),n,1);\n    fmax = fmax(:);\n    for j = 1:k\n        coefs(:,j) = coefs(:,j)./fmax;\n    end\n    % Diff of adjacent antiderivatives\n    coefs(1:end-deg,1:k) = coefs(1:end-deg,1:k) - coefs(n:end,1:k);\n    coefs(1:n:end,k) = 0;\nend\n\n% Scale coefficients\nscale = ones(size(H));\nfor k = 1:n-1\n    scale = scale./H;\n    coefs(:,n-k) = scale.*coefs(:,n-k);\nend\n\n% Reduce number of pieces\npieces = pieces - 2*deg;\n\n% Sort coefficients by interval number\nii = [n*(1:pieces); deg*ones(deg,pieces)];\nii = cumsum(ii,1);\ncoefsOut = coefs(ii(:),:);\n\ncoder.varsize('coefsOut',[8 4], [0 0]);\n\n\n\n\n%--------------------------------------------------------------------------\nfunction u = lsqsolve(A,y,beta)\n%LSQSOLVE Solve Min norm(u*A-y)\n\n\n% Solution\nu = y/A;\n\n% % Robust fitting\n% if beta > 0\n%     [m,n] = size(y);\n%     alpha = 0.5*beta/(1-beta)/m;\n%     for k = 1:3\n%         % Residual\n%         r = u*A - y;\n%         rr = r.*conj(r);\n%         rrmean = sum(rr,2)/n;\n%         rrmean(~rrmean) = 1;\n%         rrhat = (alpha./rrmean)'*rr;\n%         % Weights\n%         w = exp(-rrhat);\n%         spw = spdiags(w',0,n,n);\n%         % Solve weighted problem\n%         u = (y*spw)/(A*spw);\n%     end\n% end\n\n"
  },
  {
    "path": "Matlab/BasisOperations/test_zp2ss.m",
    "content": "function out = test_zp2ss(z,p,k)\n\n    out = zp2ss(z,p,k);"
  },
  {
    "path": "Matlab/BasisOperations/testfilt.m",
    "content": "% testFilter\n\nfileID = fopen('/Users/carl/PycharmProjects/catch22/C/timeSeries/tsid0133.txt','r');\ntsData = fscanf(fileID,'%f');\nfclose(fileID);\n\n[b, a] = myButter(4, 0.8/24);\n\ntsDatafilt = filter(b,a,tsData)"
  },
  {
    "path": "Matlab/BasisOperations/welchy.m",
    "content": "function [Pxx, F] = calc_psd(X, NFFT, Fs, WINDOW)\r\n% Calculate Power Spectral Density \r\n%\t[Pxx ,F]= PSD(X, NFFT, Fs, WINDOW) estimates the Power Spectral Density of \r\n%\tsignal vector X using Welch's averaged periodogram method.  X is \r\n%\tdivided into  sections, then windowed by the WINDOW parameter\r\n%\tThe magnitude squared of the length NFFT DFTs of the sections are \r\n%\taveraged to form Pxx.  Pxx is length NFFT/2+1 for NFFT even.  the default fot  WINDOW is a rectangular window . \r\n% \tFs is the sampling frequency which  is used for scaling of plots.\r\n%\r\n% \tAuthor(s): T. Krauss, 3-26-93\r\n%\tCopyright (c) 1984-94 by The MathWorks, Inc.\r\n%   Revision: Roni P, 10.8.01\r\n%\t\t\tEU, dt used in computations\r\n%\t\t\tEU, df used to get frequency scale\r\n%   X - The signal we want to estimate the psd for.\r\n%   NFFT - number of data points of each window\r\n%   Fs - Sampling frequency\r\n%   Window - The type of window to use\r\n%\tExample of use: \r\n%       dt = 0.01;\r\n%       f = 10;              % Frequency to find\r\n%       t = 0:dt:10;         % Create time vector\r\n%       x = sin(2*pi*f*t);   % create a signal\r\n%       nfft = 64;           % Window should be less than 256.\r\n%       Fs = 1/dt;           % Sampling frequency\r\n%\t\twindow = hanning(nfft); % Use hanning as window\r\n%\t\t[Pxx, F] = calc_psd(x, nfft, Fs, window);\r\n%       plot(F,Pxx); xlabel('Frequency [Hz]'); ylabel('Amplitude');\r\n\r\nif (nargin <= 2)\r\n    error('Not enough input parameters, exiting...');\r\nend\r\n\r\n% % make sure the windows width is a power of 2\r\n% NFFT = 2^(nextpow2(NFFT)-1); % this stinks.\r\n\r\nwindowWidth = numel(WINDOW);%2^(nextpow2(numel(WINDOW))-1); % \r\n\r\ndt = 1/Fs;\r\ndf = 1/(2^(nextpow2(numel(WINDOW))))/dt;\r\nif (nargin == 3)\r\n\t w = ones(windowWidth, 1);\r\nend\r\nif (nargin == 4)\r\n\tw = WINDOW;\r\n\tw = w(:);                        % Make sure w is a column vector\r\nend\r\n\t\r\nX = X(:);      \t\t\t\t         % Make sure X is a column vector\r\nk = floor(numel(X)/(windowWidth/2))-1;        % Number of windows\r\nindex = 1:windowWidth;\r\nKMU = k*norm(w)^2; \t\t\t\t\t % Normalizing scale factor\r\nw = w(:);\r\nP = zeros(NFFT, 1);\r\n\r\nfor i = 1:k\r\n\txw = w.*X(index);\r\n\tindex = index + windowWidth/2;            % Continue to next window\r\n\tP = P + abs(fft(xw, NFFT)).^2;\r\nend\r\n\r\nPxx = dt*(P(1:NFFT/2+1))/KMU;\r\n% strange correction here, don't know why it's neccesary!!\r\nPxx(2:end-1) = Pxx(2:end-1)*2;\r\n\r\nn = max(size(Pxx));\r\nF = (0:n-1)'*df;"
  },
  {
    "path": "Matlab/CO_Embed2_Dist_tau_d_expfit_meandiff.m",
    "content": "function out = CO_Embed2_Dist_tau_d_expfit_meandiff(y)\n% CO_Embed2_Dist    Analyzes distances in a 2-d embedding space of a time series.\n%\n% Returns statistics on the sequence of successive Euclidean distances between\n% points in a two-dimensional time-delay embedding space with a given\n% time-delay, tau.\n%\n% Outputs the the mean distance, the\n% spread of distances, and statistics from an exponential fit to the\n% distribution of distances.\n%\n%---INPUTS:\n% y, a z-scored column vector representing the input time series.\n% tau, the time delay.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n% ------------------------------------------------------------------------------\n%% Check inputs:\n% ------------------------------------------------------------------------------\n\nN = length(y); % time-series length\n\ntau = CO_FirstZero(y,'ac');\nif tau > N/10\n    tau = floor(N/10);\nend\n\n% ------------------------------------------------------------------------------\n% 2-dimensional time-delay embedding:\n% ------------------------------------------------------------------------------\n\nm = [y(1:end-tau), y(1+tau:end)];\n\n% ------------------------------------------------------------------------------\n% Calculate Euclidean distances between successive points in this space, d:\n% ------------------------------------------------------------------------------\n\nd = sqrt(diff(m(:,1)).^2 + diff(m(:,2)).^2); % Euclidean distance\n\n% % ------------------------------------------------------------------------------\n% % Empirical distance distribution often fits Exponential distribution quite well\n% % Fit to all values (often some extreme outliers, but oh well)\n% l = expfit(d);\nl = mean(d); % maybe this is stupid, but I seriously don't see the difference\n\n%% Sum of abs differences between exp fit and observed:\n\n[N, binEdges] = histcounts_(d, [], true);\n\n% from edges to centers\nbinCentres = mean([binEdges(1:end-1); binEdges(2:end)])';\n\n% exponential fit in each bin\nz = binCentres ./ l;\nexpf = exp(-z) ./ l;\nexpf(expf<0) = 0;\n\nd_expfit_meandiff = mean(abs(N - expf)); % mean absolute error of fit\n\nout = d_expfit_meandiff;\n\nend\n"
  },
  {
    "path": "Matlab/CO_FirstMin_ac.m",
    "content": "function out = CO_FirstMin_ac(y)\n% CO_FirstMin  Time of first minimum in a given correlation function\n%\n%---INPUTS:\n% y, the input time series\n%\n% Note that selecting 'ac' is unusual operation: standard operations are the\n% first zero-crossing of the autocorrelation (as in CO_FirstZero), or the first\n% minimum of the mutual information function ('mi').\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\nN = length(y); % Time-series length\n\n% ------------------------------------------------------------------------------\n% Define the autocorrelation function\n% ------------------------------------------------------------------------------\n\n% Autocorrelation implemented as CO_AutoCorr\ncorrfn = @(x) CO_AutoCorr(y,x,'Fourier');\n\n% ------------------------------------------------------------------------------\n% Search for a minimum\n% ------------------------------------------------------------------------------\n% (Incrementally through time lags until a minimum is found)\n\nautoCorr = zeros(N-1,1); % preallocate autocorrelation vector\nfor i = 1:N-1\n    % Calculate the auto-correlation at this lag:\n    autoCorr(i) = corrfn(i);\n\n    % Hit a NaN before got to a minimum -- there is no minimum\n    if isnan(autoCorr(i))\n        % warning('No minimum in %s [[time series too short to find it?]]',minWhat)\n        out = NaN; return\n    end\n\n    % We're at a minimum:\n    if i==2 && (autoCorr(2) > autoCorr(1))\n        % already increases at lag of 2 from lag of 1: a minimum (since ac(0) is maximal)\n        out = 1;\n        return\n    elseif (i > 2) && (autoCorr(i-2) > autoCorr(i-1)) && (autoCorr(i-1) < autoCorr(i)) % minimum at previous i\n        out = i-1; % I found the first minimum!\n        return\n    end\nend\n\n% Still decreasing -- no minimum was found after searching all across the time series:\nout = N;\n\nend\n"
  },
  {
    "path": "Matlab/CO_HistogramAMI_even_2_5.m",
    "content": "function out = CO_HistogramAMI_even_2_5(y)\n% CO_HistogramAMI      The automutual information of the distribution using histograms.\n%\n% The approach used to bin the data is provided.\n%\n%---INPUTS:\n%\n% y, the input time series\n%\n% tau, 2: the time-lag\n%\n% meth, 'even': evenly-spaced bins through the range of the time series,\n%\n% numBins, 5: the number of bins\n%\n%---OUTPUT: the automutual information calculated in this way.\n\n% Uses the hist2 function (renamed NK_hist2.m here) by Nedialko Krouchev, obtained\n% from Matlab Central,\n% http://www.mathworks.com/matlabcentral/fileexchange/12346-hist2-for-the-people\n% [[hist2 for the people by Nedialko Krouchev, 20 Sep 2006 (Updated 21 Sep 2006)]]\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n% ------------------------------------------------------------------------------\n%% Check Inputs:\n% ------------------------------------------------------------------------------\n\n% Number of options:\n% remove outliers first?, number of bins, range of bins, bin sizes\n\ntau = 2;\n% meth = 'even';\nnumBins = 5;\n\n% ------------------------------------------------------------------------------\n%% Bins by standard deviation (=1)\n% ------------------------------------------------------------------------------\n\n% even\nb = linspace(min(y)-0.1,max(y)+0.1,numBins+1); % +0.1 to make sure all points included\n\nnb = length(b) - 1; % number of bins (-1 since b defines edges)\n\n% ------------------------------------------------------------------------------\n% Form the time-delay vectors y1 and y2\n% ------------------------------------------------------------------------------\n\ny1 = y(1:end-tau);\ny2 = y(1+tau:end);\n\n% (1) Joint distribution of y1 and y2\npij = NK_hist2(y1,y2,b,b);\npij = pij(1:nb,1:nb); % joint\npij = pij/sum(sum(pij)); % joint\npi = sum(pij,1); % marginal\npj = sum(pij,2); % other marginal\n\n% Old-fashioned method (should give same result):\n% pi = histc(y1,b); pi = pi(1:nb); pi = pi/sum(pi); % marginal\n% pj = histc(y2,b); pj= pj(1:nb); pj = pj/sum(pj); % other marginal\n\npii = ones(nb,1)*pi;\npjj = pj*ones(1,nb);\n\nr = (pij > 0); % Defining the range in this way, we set log(0) = 0\nami = sum(pij(r).*log(pij(r)./pii(r)./pjj(r)));\n\nout = ami;\n\nend\n"
  },
  {
    "path": "Matlab/CO_f1ecac.m",
    "content": "function out = CO_f1ecac(y)\n% CO_f1ecac     The 1/e correlation length\n% \n% Finds where autocorrelation function first crosses 1/e\n%\n%---INPUT:\n% y, the input time series.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\nN = length(y); % time-series length\nthresh = 1/exp(1); % 1/e threshold\n\na = zeros(N,1); % autocorrelations\na(1) = 1; % perfect autocorrelation when no lag\nfor i = 2:N\n    a(i) = CO_AutoCorr(y,i-1,'Fourier');\n    if ((a(i-1)-thresh)*(a(i)-thresh) < 0)\n        % Crossed the 1/e line\n        out = i-1; % -1 since i is tau+1\n        return\n    end\nend\n\n% If no minimum in entire spectrum return the maximum value\nout = N;\n\nend\n"
  },
  {
    "path": "Matlab/CO_trev_1_num.m",
    "content": "function out = CO_trev_1_num(y)\n\n% no combination of single functions\ncoder.inline('never');\n\noutStruct = CO_trev(y, 1);\n\nout = outStruct.num;"
  },
  {
    "path": "Matlab/DN_HistogramMode_10.m",
    "content": "function out = DN_HistogramMode_10(y)\n\n% no combination of single functions\ncoder.inline('never');\n\nout = DN_HistogramMode(y, 10);"
  },
  {
    "path": "Matlab/DN_HistogramMode_5.m",
    "content": "function out = DN_HistogramMode_5(y)\n\n% no combination of single functions\ncoder.inline('never');\n\nout = DN_HistogramMode(y, 5);"
  },
  {
    "path": "Matlab/DN_Mean.m",
    "content": "function out = DN_Mean(y)\n\n    % no combination of single functions\n    coder.inline('never');\n    \n    out = DN_Mean(y, 5);"
  },
  {
    "path": "Matlab/DN_OutlierInclude_n_001_mdrmd.m",
    "content": "function out = DN_OutlierInclude_n_001_mdrmd(y)\n\n    % no combination of single functions\n    coder.inline('never');\n\n    out = DN_OutlierInclude_001_mdrmd(y, 'n');\n"
  },
  {
    "path": "Matlab/DN_OutlierInclude_p_001_mdrmd.m",
    "content": "function out = DN_OutlierInclude_p_001_mdrmd(y)\n\n    % no combination of single functions\n    coder.inline('never');\n\n    out = DN_OutlierInclude_001_mdrmd(y, 'p');\n"
  },
  {
    "path": "Matlab/DN_Spread_Std.m",
    "content": "function out = DN_Spread_Std(y)\n\n    % no combination of single functions\n    coder.inline('never');\n    \n    out = DN_Spread_Std(y, 5);"
  },
  {
    "path": "Matlab/FC_LocalSimple_mean1_tauresrat.m",
    "content": "function out = FC_LocalSimple_mean1_tauresrat(y)\n% FC_LocalSimple    Simple local time-series forecasting.\n%\n% Simple predictors using the past trainLength values of the time series to\n% predict its next value.\n%\n%---INPUTS:\n% y, the input time series\n%\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n% -------------------------------------------------------------------------\n%% Set defaults\n% -------------------------------------------------------------------------\n\ntrainLength = 1;\n\nN = length(y); % Time-series length\n\n% ------------------------------------------------------------------------------\n% Do the local prediction\n% ------------------------------------------------------------------------------\nif strcmp(trainLength,'ac')\n    lp = CO_FirstZero(y,'ac'); % make it tau\nelse\n    lp = trainLength; % the length of the subsegment preceeding to use to predict the subsequent value\nend\nevalr = lp+1:N; % range over which to evaluate the forecast\nif length(evalr)==0\n%     warning('Time series too short for forecasting');\n    out = NaN; return\nend\nres = zeros(length(evalr),1); % residuals\nfor i = 1:length(evalr)\n    res(i) = mean(y(evalr(i)-lp:evalr(i)-1)) - y(evalr(i)); % prediction-value\nend\n\n% tauresrat\nout = CO_FirstZero(res,'ac')/CO_FirstZero(y,'ac');\n\nend\n"
  },
  {
    "path": "Matlab/FC_LocalSimple_mean3_stderr.m",
    "content": "function out = FC_LocalSimple_mean3_stderr(y)\n% FC_LocalSimple    Simple local time-series forecasting.\n%\n% Simple predictors using the past trainLength values of the time series to\n% predict its next value.\n%\n%---INPUTS:\n% y, the input time series\n%\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n%-------------------------------------------------------------------------------\n%% Set defaults:\n%-------------------------------------------------------------------------------\n\ntrainLength = 3;\n\nN = length(y); % Time-series length\n\n% ------------------------------------------------------------------------------\n% Do the local prediction\n% ------------------------------------------------------------------------------\n\nlp = trainLength; % the length of the subsegment preceeding to use to predict the subsequent value\n\nevalr = lp+1:N; % range over which to evaluate the forecast\nif length(evalr)==0\n%     warning('Time series too short for forecasting');\n    out = NaN; return\nend\nres = zeros(length(evalr),1); % residuals\nfor i = 1:length(evalr)\n    res(i) = mean(y(evalr(i)-lp:evalr(i)-1)) - y(evalr(i)); % prediction-value\nend\n\n% Spread of residuals:\n% stderr\nout = std(res);\n\nend\n"
  },
  {
    "path": "Matlab/IN_AutoMutualInfoStats_40_gaussian_fmmi.m",
    "content": "function out = IN_AutoMutualInfoStats_40_gaussian_fmmi(y)\n% IN_AutoMutualInfoStats  Statistics on automutual information function for a time series.\n%\n%---INPUTS:\n% y, column vector of time series data\n%\n% maxTau, maximal time delay\n%\n% estMethod = 'gaussian'\n%\n%---OUTPUTS:\n% out = fmmi, statistic on the AMIs and their pattern across\n%       the range of specified time delays.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n% ------------------------------------------------------------------------------\n%% Preliminaries\n% ------------------------------------------------------------------------------\nN = length(y); % length of time series\n\n% ------------------------------------------------------------------------------\n%% Check Inputs\n% ------------------------------------------------------------------------------\n\n% maxTau: the maximum time delay to investigate\nmaxTau = 40;\n\n% Don't go above N/2\nmaxTau = min(maxTau,ceil(N/2));\n\n% ------------------------------------------------------------------------------\n%% Get the AMI data:\n% ------------------------------------------------------------------------------\n\n% do this manually, Gaussian really is the easiest MI\nautocorrs = autocorrelation(y, maxTau);\nami = -0.5*log(1 - autocorrs.^2);\n\n\n% ------------------------------------------------------------------------------\n% Output statistics:\n% ------------------------------------------------------------------------------\nlami = length(ami);\n\n% First minimum of mutual information across range\ndami = diff(ami);\nextremai = find(dami(1:end-1).*dami(2:end) < 0 & dami(1:end-1)<0);\nif isempty(extremai)\n    % fmmi\n    out = lami; % actually represents lag, because indexes don't but diff delays by 1\nelse\n    % fmmi\n    out = min(extremai);\nend\n\nend\n\nfunction out = autocorrelation(y, maxLag)\n\n    N = length(y);\n\n    if maxLag >= N\n        maxLag = N-1;\n    end\n    \n    out = zeros(1,maxLag);\n    \n    for lag = 1:maxLag\n        corrs = corrcoef(y(1:end-lag), y(1+lag:end));\n        out(lag) = corrs(2,1);\n    end\n\nend\n"
  },
  {
    "path": "Matlab/MD_hrv_classic_pnn40.m",
    "content": "function out = MD_hrv_classic_pnn40(y)\n% MD_hrv_classic    Classic heart rate variability (HRV) statistics.\n%\n% Typically assumes an NN/RR time series in units of seconds.\n%\n%---INPUTS:\n% y, the input time series.\n%\n%---OUTPUTS:\n%  pNN40\n%  cf. \"The pNNx files: re-examining a widely used heart rate variability\n%           measure\", J.E. Mietus et al., Heart 88(4) 378 (2002)\n%\n% Code is heavily derived from that provided by Max A. Little:\n% http://www.maxlittle.net/\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n% Standard defaults\ndiffy = diff(y);\nN = length(y); % time-series length\n\n% ------------------------------------------------------------------------------\n% Calculate pNNx percentage\n% ------------------------------------------------------------------------------\n% pNNx: recommendation as per Mietus et. al. 2002, \"The pNNx files: ...\", Heart\n% strange to do this for a z-scored time series...\n% pnntime = 20;\n\nDy = abs(diffy) * 1000;\n\n% Anonymous function to do the PNNx calcualtion:\nPNNxfn = @(x) sum(Dy > x)/(N-1);\n\n% % exceed  = sum(Dy > pnntime);\n% out.pnn5  = PNNxfn(5); %sum(Dy > 5)/(N-1); % proportion of difference magnitudes greater than 0.005*sigma\n% out.pnn10 = PNNxfn(10); %sum(Dy > 10)/(N-1);\n% out.pnn20 = PNNxfn(20); %sum(Dy > 20)/(N-1);\n% out.pnn30 = PNNxfn(30); %sum(Dy > 30)/(N-1);\n% pnn40\nout = PNNxfn(40); %sum(Dy > 40)/(N-1);\n\n\nend\n"
  },
  {
    "path": "Matlab/PD_PeriodicityWang_th0_01.m",
    "content": "function out = PD_PeriodicityWang_th0_01(y_in)\n% PD_PeriodicityWang    Periodicity extraction measure of Wang et al.\n%\n% Implements an idea based on the periodicity extraction measure proposed in:\n%\n% \"Structure-based Statistical Features and Multivariate Time Series Clustering\"\n% Wang, X. and Wirth, A. and Wang, L.\n% Seventh IEEE International Conference on Data Mining, 351--360 (2007)\n% DOI: 10.1109/ICDM.2007.103\n%\n% Detrends the time series using a single-knot cubic regression spline\n% and then computes autocorrelations up to one third of the length of\n% the time series. The frequency is the first peak in the autocorrelation\n% function satisfying a set of conditions.\n% \n% This code uses the SPLINEFIT v1.13.0.0 function by Jonas Lundgren from\n% Matlab Central accessed on 25 Aug 2018.\n%\n%---INPUT:\n% y, the input time series.\n%\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n% ------------------------------------------------------------------------------\n%% Foreplay\n% ------------------------------------------------------------------------------\nN = length(y_in); % length of the time series\nth = 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\n\n% ------------------------------------------------------------------------------\n%% 1: Detrend using a regression spline with 3 knots\n% ------------------------------------------------------------------------------\n\nppSpline = splinefit(y_in');\n\ny_spl = ppval(ppSpline,1:N);\n% x = (ppSpline.breaks(1):ppSpline.breaks(2))-1;\n% 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);\n% x = (ppSpline.breaks(2):ppSpline.breaks(3))-ppSpline.breaks(2)+1;\n% 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);\n% y_spl = [y_spl_1, y_spl_2];\n\ny = y_in - y_spl';\n\n%% 2. Compute autocorrelations up to 1/3 the length of the time series.\nacmax = ceil(N/3); % compute autocorrelations up to this lag\nacf = zeros(acmax,1); % the autocorrelation function\nfor i = 1:acmax % i is the \\tau, the AC lag\n    acf(i) = mean(y(1:N-i).*y(i+1:N));\nend\n\n% ------------------------------------------------------------------------------\n%% 3. Frequency is the first peak satisfying the following conditions:\n% ------------------------------------------------------------------------------\n% (a) a trough before it\n% (b) difference between peak and trough is at least 0.01\n% (c) peak corresponds to positive correlation\n\n% (i) find peaks and troughs in ACF\ndiffac = diff(acf); % differenced time series\nsgndiffac = sign(diffac); % sign of differenced time series\nbath = diff(sgndiffac); % differenced, signed, differenced time series\ntroughs = find(bath == 2) + 1; % finds troughs\npeaks = find(bath == -2) + 1; % finds peaks\nnpeaks = length(peaks);\n\nout = 0;\n\nfor i = 1:npeaks % search through all peaks for one that meets the condition\n    ipeak = peaks(i); % acf lag at which there is a peak\n    thepeak = acf(ipeak); % acf at the peak\n    ftrough = find(troughs < ipeak,1,'last');\n    if isempty(ftrough); continue; end\n    itrough = troughs(ftrough); % acf lag at which there is a trough (the first one preceeding the peak)\n    thetrough = acf(itrough); % acf at the trough\n\n    % (a) a trough before it: should be implicit in the ftrough bit above\n    %     if troughs(1)>ipeak % the first trough is after it\n    %         continue\n    %     end\n\n    % (b) difference between peak and trough is at least 0.01\n    if thepeak - thetrough < th\n        continue\n    end\n\n    % (c) peak corresponds to positive correlation\n    if thepeak < 0\n        continue\n    end\n\n    % we made it! Use this frequency!\n    out = ipeak; break\nend\n\n\nend\n"
  },
  {
    "path": "Matlab/SB_BinaryStats_diff_longstretch0.m",
    "content": "function out = SB_BinaryStats_diff_longstretch0(y)\n% SB_BinaryStats    Statistics on a binary symbolization of the time series\n%\n% Binary symbolization of the time series is a symbolic string of 0s and 1s.\n%\n% Provides information about the coarse-grained behavior of the time series\n%\n%---INPUTS:\n% y, the input time series\n%\n% binaryMethod, the symbolization rule:\n%         'diff': by whether incremental differences of the time series are\n%                      positive (1), or negative (0),\n%\n%---OUTPUTS:\n% Include the Shannon entropy of the string, the longest stretches of 0s\n% or 1s, the mean length of consecutive 0s or 1s, and the spread of consecutive\n% strings of 0s or 1s.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n%-------------------------------------------------------------------------------\n% Set defaults:\n%-------------------------------------------------------------------------------\n\nbinaryMethod = 'diff';\n\n%-------------------------------------------------------------------------------\n% Binarize the time series:\n%-------------------------------------------------------------------------------\nyBin = BF_Binarize(y,binaryMethod);\n\n%-------------------------------------------------------------------------------\n% Consecutive string of ones / zeros (normalized by length)\n%-------------------------------------------------------------------------------\ndifffy = diff(find([1;yBin;1]));\nstretch0 = difffy(difffy ~= 1) - 1;\n\n%-------------------------------------------------------------------------------\n% pstretches\n%-------------------------------------------------------------------------------\n\nif isempty(stretch0) % all 1s (almost impossible to actually occur)\n    longstretch0 = 0;\nelse\n    longstretch0 = max(stretch0); % longest consecutive stretch of zeros\nend\n\nout = longstretch0;\n\nend\n"
  },
  {
    "path": "Matlab/SB_BinaryStats_mean_longstretch1.m",
    "content": "function out = SB_BinaryStats_mean_longstretch1(y)\n% SB_BinaryStats    Statistics on a binary symbolization of the time series\n%\n% Binary symbolization of the time series is a symbolic string of 0s and 1s.\n%\n% Provides information about the coarse-grained behavior of the time series\n%\n%---INPUTS:\n% y, the input time series\n%\n% binaryMethod, the symbolization rule:\n%         'diff': by whether incremental differences of the time series are\n%                      positive (1), or negative (0),\n%\n%---OUTPUTS:\n% Include the Shannon entropy of the string, the longest stretches of 0s\n% or 1s, the mean length of consecutive 0s or 1s, and the spread of consecutive\n% strings of 0s or 1s.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n%-------------------------------------------------------------------------------\n% Set defaults:\n%-------------------------------------------------------------------------------\n\nbinaryMethod = 'mean';\n\n%-------------------------------------------------------------------------------\n% Binarize the time series:\n%-------------------------------------------------------------------------------\nyBin = BF_Binarize(y,binaryMethod);\n\n%-------------------------------------------------------------------------------\n% Consecutive string of ones (normalized by length)\n%-------------------------------------------------------------------------------\ndifffy = diff(find([0;yBin;0] == 0));\nstretch1 = difffy(difffy ~= 1) - 1;\n\n%-------------------------------------------------------------------------------\n% pstretches\n%-------------------------------------------------------------------------------\n\nif isempty(stretch1) % all 1s (almost impossible to actually occur)\n    longstretch1 = 0;\nelse\n    longstretch1 = max(stretch1); % longest consecutive stretch of zeros\nend\n\nout = longstretch1;\n\nend\n"
  },
  {
    "path": "Matlab/SB_MotifThree_quantile_hh.m",
    "content": "function out = SB_MotifThree_quantile_hh(y)\n% SB_MotifThree     Motifs in a coarse-graining of a time series to a 3-letter alphabet\n%\n% (As SB_MotifTwo but with a 3-letter alphabet)\n%\n%---INPUTS:\n% y, time series to analyze\n% cgHow, the coarse-graining method to use. 'quantile': equiprobable alphabet by time-series value\n%\n%---OUTPUTS:\n% Statistics on words of length 1, 2, 3, and 4.\n\n% ------------------------------------------------------------------------------\n% Copyright (C) 2017, Ben D. Fulcher <ben.d.fulcher@gmail.com>,\n% <http://www.benfulcher.com>\n%\n% If you use this code for your research, please cite the following two papers:\n%\n% (1) B.D. Fulcher and N.S. Jones, \"hctsa: A Computational Framework for Automated\n% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).\n% DOI: 10.1016/j.cels.2017.10.001\n%\n% (2) B.D. Fulcher, M.A. Little, N.S. Jones, \"Highly comparative time-series\n% analysis: the empirical structure of time series and their methods\",\n% J. Roy. Soc. Interface 10(83) 20130048 (2013).\n% DOI: 10.1098/rsif.2013.0048\n%\n% This function is free software: you can redistribute it and/or modify it under\n% the terms of the GNU General Public License as published by the Free Software\n% Foundation, either version 3 of the License, or (at your option) any later\n% version.\n%\n% This program is distributed in the hope that it will be useful, but WITHOUT\n% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n% FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n% details.\n%\n% You should have received a copy of the GNU General Public License along with\n% this program. If not, see <http://www.gnu.org/licenses/>.\n% ------------------------------------------------------------------------------\n\n% no combination of single functions\ncoder.inline('never');\n\n%-------------------------------------------------------------------------------\n%% Set defaults:\n%-------------------------------------------------------------------------------\n\n% quantile graining\nyt = SB_CoarseGrain_quantile(y,3);\n\nN = length(yt); % Length of the symbolized sequence derived from the time series\n\n% So we have a vector yt with entries \\in {1,2,3}\n\n% ------------------------------------------------------------------------------\n%% Words of length 1\n% ------------------------------------------------------------------------------\nr1 = cell(3,1); % stores ranges as vectors\n% out1 = zeros(3,1); % stores probabilities as doubles\n\nfor i = 1:3\n\tr1{i} = find(yt == i);\n% \tout1(i) = length(r1{i})/N;\nend\n\n\n% ------------------------------------------------------------------------------\n%% Words of length 2\n% ------------------------------------------------------------------------------\n% Make sure ranges are valid for looking at the next one\nfor i = 1:3\n\tif (~isempty(r1{i})) && (r1{i}(end) == N)\n        r1{i} = r1{i}(1:end-1);\n    end\nend\n\nr2 = cell(3,3);\nout2 = zeros(3,3);\nfor i = 1:3\n\tfor j = 1:3\n\t\tr2{i,j} = r1{i}(yt(r1{i}+1) == j);\n\t\tout2(i,j) = length(r2{i,j})/(N-1);\n\tend\nend\n\n% hh\nout = f_entropy(out2); % entropy of this result\n\n%-------------------------------------------------------------------------------\nfunction h = f_entropy(x)\n    % entropy of a set of counts, log(0)=0\n    h = -sum(x(x > 0).*log(x(x > 0)));\nend\n\nend\n"
  },
  {
    "path": "Matlab/SB_TransitionMatrix_3ac_sumdiagcov.m",
    "content": "function out = SB_TransitionMatrix_3ac_sumdiagcov(y)\n\n% no combination of single functions\ncoder.inline('never');\n\noutStruct = SB_TransitionMatrix(y, 3, 'ac');\n\nout = outStruct.sumdiagcov;"
  },
  {
    "path": "Matlab/SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1.m",
    "content": "function out = SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(y)\n\n    % no combination of single functions\n    coder.inline('never');\n\n    out = SC_FluctAnal_q2_taustep50_k1_logi_prop_r1(y, 'dfa', 2);"
  },
  {
    "path": "Matlab/SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1.m",
    "content": "function out = SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(y)\n\n    % no combination of single functions\n    coder.inline('never');\n\n    out = SC_FluctAnal_q2_taustep50_k1_logi_prop_r1(y, 'rsrangefit');"
  },
  {
    "path": "Matlab/SP_Summaries_welch_rect_area_5_1.m",
    "content": "function out = SP_Summaries_welch_rect_area_5_1(y)\n\n    % no combination of single functions\n    coder.inline('never');\n\n    outStruct = SP_Summaries_welch_rect(y);\n    out = outStruct.area_5_1;"
  },
  {
    "path": "Matlab/SP_Summaries_welch_rect_centroid.m",
    "content": "function out = SP_Summaries_welch_rect_centroid(y)\n\n    % no combination of single functions\n    coder.inline('never');\n\n    outStruct = SP_Summaries_welch_rect(y);\n    out = outStruct.centroid;\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\"><img src=\"img/catch22_logo_square.png\" alt=\"catch22 logo\" height=\"220\"/></p>\n\n<h1 align=\"center\"><em>catch22</em>: CAnonical Time-series CHaracteristics</h1>\n\n<p align=\"center\">\n \t<a href=\"https://zenodo.org/badge/latestdoi/146194807\"><img src=\"https://zenodo.org/badge/146194807.svg\" height=\"20\"/></a>\n    <a href=\"https://www.gnu.org/licenses/gpl-3.0\"><img src=\"https://img.shields.io/badge/License-GPLv3-blue.svg\" height=\"20\"/></a>\n \t<a href=\"https://twitter.com/compTimeSeries\"><img src=\"https://img.shields.io/twitter/url/https/twitter.com/compTimeSeries.svg?style=social&label=Follow%20%40compTimeSeries\" height=\"20\"/></a>\n</p>\n\n_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).\nThe _catch22_ features are a high-performing subset of the over 7000 features in [_hctsa_](https://github.com/benfulcher/hctsa).\n\nThe 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, [&#x1F4D7; Lubba et al. (2019). _catch22_: CAnonical Time-series CHaracteristics](https://doi.org/10.1007/s10618-019-00647-x).\n\n## [&#x1F4D9;&#x1F4D8;&#x1F4D7;___catch22_ documentation__](https://time-series-features.gitbook.io/catch22/)\n\nThere is [comprehensive documentation](https://time-series-features.gitbook.io/catch22/) for _catch22_, including:\n\n- Installation instructions (across C, python, R, Julia, and Matlab)\n- Information about the theory behind and behavior of each of the features,\n- A list of publications that have used or extended _catch22_\n- And more :yum:\n\n## Installation and Usage in Python, R, Matlab, Julia, and compiled C\n\nThere are also native versions of this code for other programming languages:\n\n- [Rcatch22](https://github.com/hendersontrent/Rcatch22) (R) `install.packages(\"Rcatch22\")`\n- [pycatch22](https://github.com/DynamicsAndNeuralSystems/pycatch22) (python) `pip install pycatch22`\n- [Catch22.jl](https://github.com/brendanjohnharris/Catch22.jl) (Julia) `Pkg.add(\"Catch22\")`\n\nYou 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/).\n\n## Acknowledgement :+1:\n\nIf you use this software, please read and cite this open-access article:\n\n- &#x1F4D7; Lubba et al. [_catch22_: CAnonical Time-series CHaracteristics](https://doi.org/10.1007/s10618-019-00647-x), _Data Min Knowl Disc_ __33__, 1821 (2019).\n\n## Performance Summary\n\nSummary 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)):\n\n![](img/PerformanceComparisonFig4.png)\n\n## Notes\n\n- 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.\n- _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).\n- 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.\n- 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.\n- Time-series data are taken as an ordered sequence of values (without time stamps). We assume an evenly sampled time series.\n- See language-specific usage information in the [docs](https://time-series-features.gitbook.io/catch22/).\n- The computational pipeline used to generate the _catch22_ feature set is in the [`op_importance`](https://github.com/chlubba/op_importance) repository.\n"
  },
  {
    "path": "catch22.m",
    "content": "function out = catch22(y)\n% catch22   Compute all 22 catch22 features\n\n% No combination of single functions\ncoder.inline('never');\n\n% First z-score:\ny = (y - mean(y))/std(y);\n\nout = zeros(22,1);\n\nout(1) = DN_HistogramMode_5(y);\nout(2) = DN_HistogramMode_10(y);\nout(3) = CO_f1ecac(y);\nout(4) = CO_FirstMin_ac(y);\nout(5) = CO_HistogramAMI_even_2_5(y);\nout(6) = CO_trev_1_num(y);\nout(7) = MD_hrv_classic_pnn40(y);\nout(8) = SB_BinaryStats_mean_longstretch1(y);\nout(9) = SB_TransitionMatrix_3ac_sumdiagcov(y);\nout(10) = PD_PeriodicityWang_th0_01(y);\nout(11) = CO_Embed2_Dist_tau_d_expfit_meandiff(y);\nout(12) = IN_AutoMutualInfoStats_40_gaussian_fmmi(y);\nout(13) = FC_LocalSimple_mean1_tauresrat(y);\nout(14) = DN_OutlierInclude_p_001_mdrmd(y);\nout(15) = DN_OutlierInclude_n_001_mdrmd(y);\nout(16) = SP_Summaries_welch_rect_area_5_1(y);\nout(17) = SB_BinaryStats_diff_longstretch0(y);\nout(18) = SB_MotifThree_quantile_hh(y);\nout(19) = SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1(y);\nout(20) = SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1(y);\nout(21) = SP_Summaries_welch_rect_centroid(y);\nout(22) = FC_LocalSimple_mean3_stderr(y);\n\nend\n"
  },
  {
    "path": "featureList.txt",
    "content": "# Full_feature_name_code                        short_feature_name\n# ---------------------------------------------------------------\nDN_HistogramMode_5                              mode_5\nDN_HistogramMode_10                             mode_10\nDN_OutlierInclude_p_001_mdrmd                   outlier_timing_pos\nDN_OutlierInclude_n_001_mdrmd                   outlier_timing_neg\nCO_f1ecac                                       acf_timescale\nCO_FirstMin_ac                                  acf_first_min\nSP_Summaries_welch_rect_area_5_1                low_freq_power\nSP_Summaries_welch_rect_centroid                centroid_freq\nFC_LocalSimple_mean3_stderr                     forecast_error\nFC_LocalSimple_mean1_tauresrat                  whiten_timescale\nMD_hrv_classic_pnn40                            high_fluctuation\nSB_BinaryStats_mean_longstretch1                stretch_high\nSB_BinaryStats_diff_longstretch0                stretch_decreasing\nSB_MotifThree_quantile_hh                       entropy_pairs\nCO_HistogramAMI_even_2_5                        ami2\nCO_trev_1_num                                   trev\nIN_AutoMutualInfoStats_40_gaussian_fmmi         ami_timescale\nSB_TransitionMatrix_3ac_sumdiagcov              transition_variance\nPD_PeriodicityWang_th0_01                       periodicity\nCO_Embed2_Dist_tau_d_expfit_meandiff            embedding_dist\nSC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1     rs_range\nSC_FluctAnal_2_dfa_50_1_2_logi_prop_r1          dfa\nDN_Mean                                         mean\nDN_Spread_Std                                   std\n"
  },
  {
    "path": "testData/runtests.sh",
    "content": "#!/bin/bash\n\n\"$(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\n"
  },
  {
    "path": "testData/test.txt",
    "content": "-0.89094\n-0.86099\n-0.82438\n-0.78214\n-0.73573\n-0.68691\n-0.63754\n-0.58937\n-0.54342\n-0.50044\n-0.46082\n-0.42469\n-0.3924\n-0.36389\n-0.33906\n-0.31795\n-0.30056\n-0.28692\n-0.27727\n-0.27105\n-0.26777\n-0.26678\n-0.26742\n-0.26927\n-0.27202\n-0.27529\n-0.27898\n-0.2832\n-0.28814\n-0.29431\n-0.30185\n-0.31086\n-0.32135\n-0.33326\n-0.3465\n-0.36103\n-0.37659\n-0.39297\n-0.40995\n-0.42731\n-0.44484\n-0.46226\n-0.47921\n-0.49534\n-0.51031\n-0.52382\n-0.53567\n-0.54568\n-0.55375\n-0.55984\n-0.56397\n-0.56617\n-0.56653\n-0.56511\n-0.56201\n-0.55736\n-0.55133\n-0.54419\n-0.53617\n-0.52758\n-0.51876\n-0.51004\n-0.50174\n-0.49418\n-0.48731\n-0.48128\n-0.47619\n-0.4721\n-0.46921\n-0.4674\n-0.46649\n-0.46659\n-0.46785\n-0.47045\n-0.4749\n-0.48081\n-0.48822\n-0.49726\n-0.50805\n-0.52086\n-0.53596\n-0.55266\n-0.57081\n-0.59021\n-0.61063\n-0.63238\n-0.65484\n-0.67722\n-0.69907\n-0.72004\n-0.73987\n-0.75965\n-0.77816\n-0.79527\n-0.8109\n-0.82509\n-0.83844\n-0.85159\n-0.86373\n-0.87474\n-0.88447\n-0.8929\n-0.90125\n-0.90911\n-0.91606\n-0.92197\n-0.92677\n-0.93071\n-0.93528\n-0.93931\n-0.9426\n-0.94494\n-0.94622\n-0.94735\n-0.94879\n-0.94965\n-0.94971\n-0.94878\n-0.94679\n-0.94571\n-0.94428\n-0.94176\n-0.93756\n-0.9311\n-0.92258\n-0.91342\n-0.90142\n-0.88573\n-0.86549\n-0.83998\n-0.81054\n-0.77682\n-0.73745\n-0.692\n-0.64033\n-0.58278\n-0.52295\n-0.45966\n-0.39357\n-0.32536\n-0.2557\n-0.18627\n-0.11888\n-0.052529\n0.012911\n0.077684\n0.14195\n0.2039\n0.26391\n0.3225\n0.37976\n0.43566\n0.48977\n0.53999\n0.58745\n0.63232\n0.6749\n0.71548\n0.75342\n0.78841\n0.82157\n0.85356\n0.88519\n0.91734\n0.94972\n0.98403\n1.0219\n1.0648\n1.1143\n1.1713\n1.2359\n1.3092\n1.3911\n1.4809\n1.5776\n1.6787\n1.7819\n1.8846\n1.9842\n2.0777\n2.1627\n2.2362\n2.2969\n2.3436\n2.3759\n2.3942\n2.3994\n2.3927\n2.3763\n2.3521\n2.3222\n2.2886\n2.2524\n2.2149\n2.1772\n2.1394\n2.1018\n2.0641\n2.0259\n1.9878\n1.9494\n1.9106\n1.8711\n1.8305\n1.7886\n1.7455\n1.7008\n1.6537\n1.6036\n1.5495\n1.492\n1.431\n1.3664\n1.2981\n1.2262\n1.1508\n1.0736\n0.99504\n0.91575\n0.83626\n0.75657\n0.67816\n0.60206\n0.52843\n0.45712\n0.38776\n0.31881\n0.2515\n0.18511\n0.11894\n0.052471\n-0.01492\n-0.082568\n-0.14848\n-0.21193\n-0.27229\n-0.32905\n-0.38303\n-0.43222\n-0.47628\n-0.51587\n-0.55188\n-0.58534\n-0.61763\n-0.64653\n-0.67227\n-0.69521\n-0.71576\n-0.73517\n-0.75286\n-0.76798\n-0.7812\n-0.79326\n-0.80474\n-0.81719\n-0.82831\n-0.83768\n-0.84538\n-0.85165\n-0.85731\n-0.86309\n-0.86791\n-0.87271\n-0.87846\n-0.88592\n-0.89619\n-0.90783\n-0.91942\n-0.93018\n-0.93939\n"
  },
  {
    "path": "testData/test2.txt",
    "content": "-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"
  },
  {
    "path": "testData/test2_output.txt",
    "content": "-0.23703703703704, DN_OutlierInclude_n_001_mdrmd, 0.248000\n0.40740740740741, DN_OutlierInclude_p_001_mdrmd, 0.342000\n-0.61479911484527, DN_HistogramMode_5, 0.005000\n-0.78225446555221, DN_HistogramMode_10, 0.003000\n7.13507860878856, CO_Embed2_Dist_tau_d_expfit_meandiff, 0.283000\n32.50260547693646, CO_f1ecac, 0.197000\n77.00000000000000, CO_FirstMin_ac, 0.315000\n1.00638907799376, CO_HistogramAMI_even_2_5, 0.017000\n0.00001782472612, CO_trev_1_num, 0.008000\n0.84782608695652, FC_LocalSimple_mean1_tauresrat, 0.522000\n0.08029384289851, FC_LocalSimple_mean3_stderr, 0.010000\n40.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 0.114000\n0.31970260223048, MD_hrv_classic_pnn40, 0.002000\n83.00000000000000, SB_BinaryStats_diff_longstretch0, 0.003000\n88.00000000000000, SB_BinaryStats_mean_longstretch1, 0.003000\n1.21058781724385, SB_MotifThree_quantile_hh, 0.047000\n0.29545454545455, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 0.193000\n0.75000000000000, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 0.075000\n0.99313877887425, SP_Summaries_welch_rect_area_5_1, 0.077000\n0.03681553890926, SP_Summaries_welch_rect_centroid, 0.074000\n0.08000000000000, SB_TransitionMatrix_3ac_sumdiagcov, 0.309000\n0.00000000000000, PD_PeriodicityWang_th0_01, 0.135000\n\n"
  },
  {
    "path": "testData/testInf.txt",
    "content": "inf\n-0.42469\n-0.3924\n-0.36389\n-0.33906\n-0.31795\n-0.30056\n-0.28692\n-0.27727\n-0.27105\n-0.26777\n-0.26678\n-0.26742\n-0.26927\n-0.27202\n-0.27529\n-0.27898\n-0.2832\n-0.28814\n-0.29431\n-0.30185\n-0.31086\n-0.32135\n-0.33326\n-0.3465\n-0.36103\n-0.37659\n-0.39297\n-0.40995\n-0.42731\n-0.44484\n-0.46226\n-0.47921\n-0.49534\n-0.51031\n-0.52382\n-0.53567\n-0.54568\n-0.55375\n-0.55984\n-0.56397\n-0.56617\n-0.56653\n-0.56511\n-0.56201\n-0.55736\n-0.55133\n-0.54419\n-0.53617\n-0.52758\n-0.51876\n-0.51004\n-0.50174\n-0.49418\n-0.48731\n-0.48128\n-0.47619\n-0.4721\n-0.46921\n-0.4674\n-0.46649\n-0.46659\n-0.46785\n-0.47045\n-0.4749\n-0.48081\n-0.48822\n-0.49726\n-0.50805\n-0.52086\n-0.53596\n-0.55266\n-0.57081\n-0.59021\n-0.61063\n-0.63238\n-0.65484\n-0.67722\n-0.69907\n-0.72004\n-0.73987\n-0.75965\n-0.77816\n-0.79527\n-0.8109\n-0.82509\n-0.83844\n-0.85159\n-0.86373\n-0.87474\n-0.88447\n-0.8929\n-0.90125\n-0.90911\n-0.91606\n-0.92197\n-0.92677\n-0.93071\n-0.93528\n-0.93931\n-0.9426\n-0.94494\n-0.94622\n-0.94735\n-0.94879\n-0.94965\n-0.94971\n-0.94878\n-0.94679\n-0.94571\n-0.94428\n-0.94176\n-0.93756\n-0.9311\n-0.92258\n-0.91342\n-0.90142\n-0.88573\n-0.86549\n-0.83998\n-0.81054\n-0.77682\n-0.73745\n-0.692\n-0.64033\n-0.58278\n-0.52295\n-0.45966\n-0.39357\n-0.32536\n-0.2557\n-0.18627\n-0.11888\n-0.052529\n0.012911\n0.077684\n0.14195\n0.2039\n0.26391\n0.3225\n0.37976\n0.43566\n0.48977\n0.53999\n0.58745\n0.63232\n0.6749\n0.71548\n0.75342\n0.78841\n0.82157\n0.85356\n0.88519\n0.91734\n0.94972\n0.98403\n1.0219\n1.0648\n1.1143\n1.1713\n1.2359\n1.3092\n1.3911\n1.4809\n1.5776\n1.6787\n1.7819\n1.8846\n1.9842\n2.0777\n2.1627\n2.2362\n2.2969\n2.3436\n2.3759\n2.3942\n2.3994\n2.3927\n2.3763\n2.3521\n2.3222\n2.2886\n2.2524\n2.2149\n2.1772\n2.1394\n2.1018\n2.0641\n2.0259\n1.9878\n1.9494\n1.9106\n1.8711\n1.8305\n1.7886\n1.7455\n1.7008\n1.6537\n1.6036\n1.5495\n1.492\n1.431\n1.3664\n1.2981\n1.2262\n1.1508\n1.0736\n0.99504\n0.91575\n0.83626\n0.75657\n0.67816\n0.60206\n0.52843\n0.45712\n0.38776\n0.31881\n0.2515\n0.18511\n0.11894\n0.052471\n-0.01492\n-0.082568\n-0.14848\n-0.21193\n-0.27229\n-0.32905\n-0.38303\n-0.43222\n-0.47628\n-0.51587\n-0.55188\n-0.58534\n-0.61763\n-0.64653\n-0.67227\n-0.69521\n-0.71576\n-0.73517\n-0.75286\n-0.76798\n-0.7812\n-0.79326\n-0.80474\n-0.81719\n-0.82831\n-0.83768\n-0.84538\n-0.85165\n-0.85731\n-0.86309\n-0.86791\n-0.87271\n-0.87846\n-0.88592\n-0.89619\n-0.90783\n-0.91942\n-0.93018\n-0.93939\n"
  },
  {
    "path": "testData/testInfMinus.txt",
    "content": "-inf\n-0.42469\n-0.3924\n-0.36389\n-0.33906\n-0.31795\n-0.30056\n-0.28692\n-0.27727\n-0.27105\n-0.26777\n-0.26678\n-0.26742\n-0.26927\n-0.27202\n-0.27529\n-0.27898\n-0.2832\n-0.28814\n-0.29431\n-0.30185\n-0.31086\n-0.32135\n-0.33326\n-0.3465\n-0.36103\n-0.37659\n-0.39297\n-0.40995\n-0.42731\n-0.44484\n-0.46226\n-0.47921\n-0.49534\n-0.51031\n-0.52382\n-0.53567\n-0.54568\n-0.55375\n-0.55984\n-0.56397\n-0.56617\n-0.56653\n-0.56511\n-0.56201\n-0.55736\n-0.55133\n-0.54419\n-0.53617\n-0.52758\n-0.51876\n-0.51004\n-0.50174\n-0.49418\n-0.48731\n-0.48128\n-0.47619\n-0.4721\n-0.46921\n-0.4674\n-0.46649\n-0.46659\n-0.46785\n-0.47045\n-0.4749\n-0.48081\n-0.48822\n-0.49726\n-0.50805\n-0.52086\n-0.53596\n-0.55266\n-0.57081\n-0.59021\n-0.61063\n-0.63238\n-0.65484\n-0.67722\n-0.69907\n-0.72004\n-0.73987\n-0.75965\n-0.77816\n-0.79527\n-0.8109\n-0.82509\n-0.83844\n-0.85159\n-0.86373\n-0.87474\n-0.88447\n-0.8929\n-0.90125\n-0.90911\n-0.91606\n-0.92197\n-0.92677\n-0.93071\n-0.93528\n-0.93931\n-0.9426\n-0.94494\n-0.94622\n-0.94735\n-0.94879\n-0.94965\n-0.94971\n-0.94878\n-0.94679\n-0.94571\n-0.94428\n-0.94176\n-0.93756\n-0.9311\n-0.92258\n-0.91342\n-0.90142\n-0.88573\n-0.86549\n-0.83998\n-0.81054\n-0.77682\n-0.73745\n-0.692\n-0.64033\n-0.58278\n-0.52295\n-0.45966\n-0.39357\n-0.32536\n-0.2557\n-0.18627\n-0.11888\n-0.052529\n0.012911\n0.077684\n0.14195\n0.2039\n0.26391\n0.3225\n0.37976\n0.43566\n0.48977\n0.53999\n0.58745\n0.63232\n0.6749\n0.71548\n0.75342\n0.78841\n0.82157\n0.85356\n0.88519\n0.91734\n0.94972\n0.98403\n1.0219\n1.0648\n1.1143\n1.1713\n1.2359\n1.3092\n1.3911\n1.4809\n1.5776\n1.6787\n1.7819\n1.8846\n1.9842\n2.0777\n2.1627\n2.2362\n2.2969\n2.3436\n2.3759\n2.3942\n2.3994\n2.3927\n2.3763\n2.3521\n2.3222\n2.2886\n2.2524\n2.2149\n2.1772\n2.1394\n2.1018\n2.0641\n2.0259\n1.9878\n1.9494\n1.9106\n1.8711\n1.8305\n1.7886\n1.7455\n1.7008\n1.6537\n1.6036\n1.5495\n1.492\n1.431\n1.3664\n1.2981\n1.2262\n1.1508\n1.0736\n0.99504\n0.91575\n0.83626\n0.75657\n0.67816\n0.60206\n0.52843\n0.45712\n0.38776\n0.31881\n0.2515\n0.18511\n0.11894\n0.052471\n-0.01492\n-0.082568\n-0.14848\n-0.21193\n-0.27229\n-0.32905\n-0.38303\n-0.43222\n-0.47628\n-0.51587\n-0.55188\n-0.58534\n-0.61763\n-0.64653\n-0.67227\n-0.69521\n-0.71576\n-0.73517\n-0.75286\n-0.76798\n-0.7812\n-0.79326\n-0.80474\n-0.81719\n-0.82831\n-0.83768\n-0.84538\n-0.85165\n-0.85731\n-0.86309\n-0.86791\n-0.87271\n-0.87846\n-0.88592\n-0.89619\n-0.90783\n-0.91942\n-0.93018\n-0.93939\n"
  },
  {
    "path": "testData/testNaN.txt",
    "content": "nan\n-0.42469\n-0.3924\n-0.36389\n-0.33906\n-0.31795\n-0.30056\n-0.28692\n-0.27727\n-0.27105\n-0.26777\n-0.26678\n-0.26742\n-0.26927\n-0.27202\n-0.27529\n-0.27898\n-0.2832\n-0.28814\n-0.29431\n-0.30185\n-0.31086\n-0.32135\n-0.33326\n-0.3465\n-0.36103\n-0.37659\n-0.39297\n-0.40995\n-0.42731\n-0.44484\n-0.46226\n-0.47921\n-0.49534\n-0.51031\n-0.52382\n-0.53567\n-0.54568\n-0.55375\n-0.55984\n-0.56397\n-0.56617\n-0.56653\n-0.56511\n-0.56201\n-0.55736\n-0.55133\n-0.54419\n-0.53617\n-0.52758\n-0.51876\n-0.51004\n-0.50174\n-0.49418\n-0.48731\n-0.48128\n-0.47619\n-0.4721\n-0.46921\n-0.4674\n-0.46649\n-0.46659\n-0.46785\n-0.47045\n-0.4749\n-0.48081\n-0.48822\n-0.49726\n-0.50805\n-0.52086\n-0.53596\n-0.55266\n-0.57081\n-0.59021\n-0.61063\n-0.63238\n-0.65484\n-0.67722\n-0.69907\n-0.72004\n-0.73987\n-0.75965\n-0.77816\n-0.79527\n-0.8109\n-0.82509\n-0.83844\n-0.85159\n-0.86373\n-0.87474\n-0.88447\n-0.8929\n-0.90125\n-0.90911\n-0.91606\n-0.92197\n-0.92677\n-0.93071\n-0.93528\n-0.93931\n-0.9426\n-0.94494\n-0.94622\n-0.94735\n-0.94879\n-0.94965\n-0.94971\n-0.94878\n-0.94679\n-0.94571\n-0.94428\n-0.94176\n-0.93756\n-0.9311\n-0.92258\n-0.91342\n-0.90142\n-0.88573\n-0.86549\n-0.83998\n-0.81054\n-0.77682\n-0.73745\n-0.692\n-0.64033\n-0.58278\n-0.52295\n-0.45966\n-0.39357\n-0.32536\n-0.2557\n-0.18627\n-0.11888\n-0.052529\n0.012911\n0.077684\n0.14195\n0.2039\n0.26391\n0.3225\n0.37976\n0.43566\n0.48977\n0.53999\n0.58745\n0.63232\n0.6749\n0.71548\n0.75342\n0.78841\n0.82157\n0.85356\n0.88519\n0.91734\n0.94972\n0.98403\n1.0219\n1.0648\n1.1143\n1.1713\n1.2359\n1.3092\n1.3911\n1.4809\n1.5776\n1.6787\n1.7819\n1.8846\n1.9842\n2.0777\n2.1627\n2.2362\n2.2969\n2.3436\n2.3759\n2.3942\n2.3994\n2.3927\n2.3763\n2.3521\n2.3222\n2.2886\n2.2524\n2.2149\n2.1772\n2.1394\n2.1018\n2.0641\n2.0259\n1.9878\n1.9494\n1.9106\n1.8711\n1.8305\n1.7886\n1.7455\n1.7008\n1.6537\n1.6036\n1.5495\n1.492\n1.431\n1.3664\n1.2981\n1.2262\n1.1508\n1.0736\n0.99504\n0.91575\n0.83626\n0.75657\n0.67816\n0.60206\n0.52843\n0.45712\n0.38776\n0.31881\n0.2515\n0.18511\n0.11894\n0.052471\n-0.01492\n-0.082568\n-0.14848\n-0.21193\n-0.27229\n-0.32905\n-0.38303\n-0.43222\n-0.47628\n-0.51587\n-0.55188\n-0.58534\n-0.61763\n-0.64653\n-0.67227\n-0.69521\n-0.71576\n-0.73517\n-0.75286\n-0.76798\n-0.7812\n-0.79326\n-0.80474\n-0.81719\n-0.82831\n-0.83768\n-0.84538\n-0.85165\n-0.85731\n-0.86309\n-0.86791\n-0.87271\n-0.87846\n-0.88592\n-0.89619\n-0.90783\n-0.91942\n-0.93018\n-0.93939\n"
  },
  {
    "path": "testData/testShort.txt",
    "content": "-0.89094\n-0.86099\n-0.82438\n-0.78214\n-0.73573\n-0.68691\n-0.63754\n-0.58937\n-0.54342\n-0.50044\n-0.46082\n-0.42469\n"
  },
  {
    "path": "testData/testShort_output.txt",
    "content": "-0.58333333333333, DN_OutlierInclude_n_001_mdrmd, 0.019000\n0.75000000000000, DN_OutlierInclude_p_001_mdrmd, 0.017000\n0.02269949495805, DN_HistogramMode_5, 0.001000\n0.02269949495805, DN_HistogramMode_10, 0.001000\n0.51152503131790, CO_Embed2_Dist_tau_d_expfit_meandiff, 0.012000\n2.67524184613158, CO_f1ecac, 0.004000\n8.00000000000000, CO_FirstMin_ac, 0.004000\n1.36615884756920, CO_HistogramAMI_even_2_5, 0.003000\n0.01964378196445, CO_trev_1_num, 0.001000\n0.60000000000000, FC_LocalSimple_mean1_tauresrat, 0.008000\n0.05070841167817, FC_LocalSimple_mean3_stderr, 0.000000\n6.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 0.002000\n1.00000000000000, MD_hrv_classic_pnn40, 0.000000\n1.00000000000000, SB_BinaryStats_diff_longstretch0, 0.001000\n5.00000000000000, SB_BinaryStats_mean_longstretch1, 0.000000\n1.49903067297901, SB_MotifThree_quantile_hh, 0.004000\n0.00000000000000, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 0.007000\n0.00000000000000, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 0.006000\n0.00000000000000, SP_Summaries_welch_rect_area_5_1, 0.004000\n0.39269908169875, SP_Summaries_welch_rect_centroid, 0.003000\n0.16666666666667, SB_TransitionMatrix_3ac_sumdiagcov, 0.006000\n0.00000000000000, PD_PeriodicityWang_th0_01, 0.013000\n\n"
  },
  {
    "path": "testData/testSinusoid.txt",
    "content": "0.07278102\n0.04887893\n0.08751903\n0.13499968\n0.12611472\n0.32822557\n0.07535813\n0.24774287\n0.12878436\n0.34140028\n0.15010170\n0.26043849\n0.41951105\n0.23625629\n0.15366643\n0.21353631\n0.27866994\n0.26928280\n0.24791033\n0.46969495\n0.40362597\n0.49709404\n0.34962158\n0.51007852\n0.23945292\n0.43049607\n0.49740328\n0.33662590\n0.55609625\n0.51493106\n0.54345507\n0.47709771\n0.55234106\n0.42275539\n0.40052568\n0.43661371\n0.52763128\n0.61058967\n0.45805922\n0.50095473\n0.64803553\n0.58303119\n0.70511679\n0.47798046\n0.67410219\n0.63772402\n0.51863295\n0.59562197\n0.58150174\n0.65045736\n0.71958237\n0.51969788\n0.74331280\n0.75785924\n0.62048786\n0.65170807\n0.70285796\n0.74987947\n0.77076486\n0.78372627\n0.68138110\n0.70165821\n0.86793856\n0.76103617\n0.85211206\n0.68809000\n0.79981394\n0.79749449\n0.91783356\n0.66230799\n0.79436735\n0.80831067\n0.68643447\n0.93826958\n0.93960459\n0.81333566\n0.92343823\n0.74067475\n0.88922420\n0.78854038\n0.85105295\n0.97748703\n0.79000731\n0.82908686\n0.88963149\n0.85262402\n0.99738831\n1.06057521\n0.81845315\n0.84813568\n0.99399790\n0.90214524\n1.08771309\n1.09331161\n1.00066752\n1.07144517\n0.93975659\n1.01446495\n1.12606836\n1.00386920\n1.12154856\n1.06293481\n0.99731958\n1.04900832\n1.12869529\n0.92704425\n0.99096536\n1.17485310\n1.00266329\n1.08428386\n1.16161180\n1.19431322\n1.09604943\n0.93694312\n0.91946771\n1.09819131\n1.08694642\n1.20934000\n1.14843765\n1.12712380\n1.08903308\n1.01358429\n1.22769749\n1.10455001\n0.95486505\n1.15787896\n1.10800519\n0.97281002\n1.22502673\n1.05989574\n1.03246854\n1.00036954\n1.06199191\n1.03967807\n1.16908369\n0.99557140\n1.06049402\n1.06445413\n1.24587341\n1.11699992\n1.21222397\n1.16808901\n1.22363154\n1.02428375\n1.28502751\n1.24729199\n1.00906231\n1.13478490\n1.09357683\n1.18579929\n1.06658474\n1.17211796\n1.17965704\n1.17913167\n1.13405419\n1.01041080\n1.15408617\n1.12231873\n1.03237146\n1.13777830\n1.13483843\n1.16457374\n1.24041104\n1.20850300\n1.25927703\n1.01252267\n1.06192838\n1.13297595\n1.28160328\n1.22991726\n1.12722719\n1.09035526\n1.00661836\n1.20962543\n1.13775754\n1.04396357\n1.11031238\n1.03083156\n1.20370498\n1.08657617\n1.25639297\n0.97667872\n1.21782590\n1.15457168\n1.12560695\n1.15642749\n1.17646014\n0.98391809\n1.21584837\n0.95379426\n1.03459088\n0.99699439\n1.21753375\n0.95663118\n1.10694298\n1.12010508\n1.12059230\n1.18075741\n0.93422371\n1.15846991\n1.06797417\n1.11339573\n0.96451466\n1.05938973\n1.10268473\n1.17429274\n1.01607000\n0.90358341\n0.89033502\n1.05704973\n1.10206309\n1.06547523\n0.95653284\n1.13172284\n0.99838753\n1.12304270\n0.85346215\n0.88789458\n1.05261229\n1.08859724\n1.04326160\n0.89123133\n0.84211919\n1.04485338\n1.01977230\n0.85932265\n0.84009587\n0.86166192\n1.00774925\n0.99898523\n0.91691007\n0.91055417\n0.81803693\n0.93512446\n0.95734218\n0.84395007\n0.83827545\n0.83697646\n0.77378674\n0.88541582\n0.94656254\n0.94061336\n0.88474028\n0.73119420\n0.85232635\n0.67731390\n0.66708088\n0.67950441\n0.65809389\n0.78196661\n0.62048065\n0.83712878\n0.79920154\n0.85192956\n0.71374781\n0.75414859\n0.81639248\n0.70252989\n0.61719646\n0.81683160\n0.52642903\n0.60478022\n0.79016573\n0.59907639\n0.57356750\n0.50830426\n0.73792098\n0.49494913\n0.54501001\n0.70564305\n0.57727451\n0.60290441\n0.58415406\n0.60954566\n0.39968448\n0.54002580\n0.38202089\n0.61124254\n0.45576021\n0.59840675\n0.40880902\n0.49999671\n0.59738103\n0.32091117\n0.31323465\n0.29366342\n0.48232948\n0.44785461\n0.29282836\n0.48782039\n0.42460451\n0.25059200\n0.24056730\n0.25081952\n0.43689738\n0.21814218\n0.25195691\n0.24384620\n0.19233698\n0.40851854\n0.35057994\n0.35133583\n0.31645244\n0.26624236\n0.19933443\n0.28999750\n0.11677180\n0.11587674\n0.06748312\n0.34085729\n0.33269253\n0.06874555\n0.16181398\n0.20860059\n0.08864832\n0.21795374\n0.14902911\n0.09993425\n0.04176031\n0.17773238\n0.21113875\n0.15017920\n0.04372201\n0.19320252\n-0.02162036\n0.05175384\n0.16829561\n-0.04773050\n-0.06294048\n0.13043864\n-0.13717099\n-0.07779232\n0.00001264\n-0.12630492\n-0.00634321\n0.03260911\n-0.06616476\n-0.03118288\n0.00263117\n-0.17584837\n-0.07528942\n-0.23145743\n-0.12009497\n-0.03307351\n-0.01776128\n-0.15407313\n-0.22977102\n-0.12677991\n-0.05679555\n-0.18844944\n-0.05852578\n-0.30094642\n-0.33608546\n-0.28950859\n-0.26902536\n-0.27092146\n-0.31286309\n-0.20726966\n-0.39693642\n-0.31290430\n-0.35396620\n-0.35951672\n-0.42869758\n-0.29107176\n-0.39320899\n-0.44022016\n-0.49529977\n-0.41907992\n-0.34752604\n-0.26005813\n-0.51716011\n-0.26687391\n-0.50739882\n-0.30491823\n-0.32318677\n-0.29619729\n-0.53854710\n-0.43643741\n-0.47442968\n-0.55184610\n-0.43930281\n-0.43787146\n-0.56322010\n-0.47932837\n-0.34624300\n-0.50365059\n-0.44972451\n-0.54225544\n-0.66267791\n-0.59262310\n-0.44733364\n-0.59104038\n-0.67715151\n-0.55589948\n-0.60619555\n-0.50134427\n-0.57263631\n-0.49549933\n-0.49850579\n-0.69338688\n-0.71969446\n-0.51700204\n-0.57835385\n-0.77123239\n-0.51354952\n-0.63391274\n-0.63127917\n-0.61873412\n-0.57848688\n-0.55588399\n-0.70341658\n-0.79858958\n-0.60944718\n-0.73555425\n-0.58868454\n-0.73446671\n-0.60280882\n-0.80352239\n-0.82274094\n-0.60266459\n-0.85835203\n-0.67041871\n-0.66107415\n-0.75473748\n-0.77653213\n-0.60109213\n-0.77970738\n-0.77167545\n-0.86092489\n-0.81430192\n-0.82194736\n-0.65177785\n-0.84989090\n-0.83457216\n-0.80880012\n-0.72264931\n-0.89545958\n-0.68055866\n-0.92031874\n-0.80995987\n-0.94248537\n-0.72866761\n-0.74754521\n-0.89603881\n-0.75915952\n-0.79858526\n-0.71311494\n-0.80319769\n-0.70258688\n-0.84951801\n-0.87009161\n-0.83289291\n-0.90476161\n-0.70466241\n-0.84515074\n-0.91064150\n-0.85904572\n-0.77912080\n-0.87055041\n-0.93796779\n-0.73681567\n-0.81950246\n-0.88366154\n-0.93009958\n-0.93168283\n-0.84138471\n-0.86860120\n-0.77671053\n-0.97834063\n-0.74554935\n-0.79595919\n-0.95900169\n-0.74245038\n-0.93989469\n-0.81741686\n-0.83637929\n-0.95016940\n-0.99664502\n-0.76626970\n-0.76755351\n-0.86984380\n-0.97819587\n-0.81849142\n-0.94084522\n-0.77328556\n-0.83025922\n-0.91320597\n-0.71248805\n-0.75852777\n-0.71815936\n-0.96181316\n-0.92547994\n-0.75740433\n-0.76740155\n-0.74111038\n-0.82133204\n-0.84185165\n-0.78363024\n-0.70767379\n-0.76047377\n-0.80184666\n-0.86639513\n-0.74186891\n-0.83550094\n-0.77650828\n-0.67719038\n-0.68730442\n-0.66709616\n-0.65148765\n-0.68491756\n-0.92540733\n-0.92106147\n-0.89182983\n-0.83584226\n-0.90311945\n-0.77854120\n-0.79916417\n-0.73470434\n-0.61479695\n-0.79854574\n-0.78202922\n-0.62088136\n-0.77176477\n-0.82756762\n-0.71167263\n-0.60193755\n-0.73847669\n-0.63981441\n-0.65481649\n-0.70265303\n-0.69018206\n-0.54177027\n-0.79596498\n-0.73131554\n-0.67533046\n-0.62724878\n-0.53423706\n-0.65072454\n-0.65407741\n-0.55521719\n-0.63239135\n-0.50813082\n-0.61996332\n-0.60394749\n-0.60053622\n-0.67123668\n-0.70764953\n-0.70626477\n-0.45305439\n-0.64264132\n-0.44706160\n-0.48489794\n-0.42938287\n-0.40256535\n-0.63472995\n-0.55106981\n-0.36760721\n-0.46080787\n-0.37772774\n-0.49432148\n-0.62703872\n-0.43661544\n-0.54630150\n-0.44948891\n-0.38224974\n-0.40949084\n-0.40711473\n-0.44544493\n-0.49401668\n-0.43031689\n-0.54763231\n-0.35966459\n-0.24648971\n-0.49676617\n-0.50618828\n-0.24240854\n-0.42555947\n-0.48828021\n-0.23774239\n-0.43128417\n-0.20064225\n-0.42711087\n-0.34103202\n-0.25980535\n-0.25326472\n-0.21945949\n-0.21625871\n-0.27151789\n-0.35042260\n-0.15755375\n-0.30134063\n-0.16944554\n-0.09804134\n-0.32057711\n-0.04486161\n-0.31761683\n-0.06696720\n-0.05737655\n-0.28360449\n-0.12523721\n0.00353545\n-0.17335806\n-0.01821745\n-0.07006936\n-0.00390929\n0.00867772\n-0.20646761\n-0.12661458\n-0.00575308\n-0.04508931\n0.10969317\n0.05222610\n0.00789033\n-0.06289766\n-0.06586361\n0.13317723\n0.01116626\n0.13185238\n-0.07350111\n0.16482753\n-0.07480070\n0.19662694\n0.20683738\n0.10407157\n-0.00711203\n0.02015901\n0.18864905\n0.23622300\n0.00726484\n0.23416625\n0.30394755\n0.12967263\n0.22827949\n0.14969934\n0.12172555\n0.30262518\n0.29366616\n0.17035735\n0.27139295\n0.23291343\n0.14416982\n0.13368326\n0.28373201\n0.22976795\n0.25809993\n0.25224699\n0.22716580\n0.30550895\n0.40484139\n0.26644645\n0.41501793\n0.35779477\n0.36459600\n0.29688826\n0.31196170\n0.44858658\n0.35399618\n0.45080186\n0.57591087\n0.51636511\n0.51530726\n0.60884213\n0.56308274\n0.52222197\n0.63369204\n0.37653634\n0.44857421\n0.67324439\n0.61814453\n0.53829229\n0.60911979\n0.53905378\n0.53710016\n0.49607625\n0.55597305\n0.45894440\n0.60064781\n0.56782481\n0.76938118\n0.65202788\n0.74800444\n0.62520152\n0.65000677\n0.76786105\n0.82584570\n0.69413190\n0.82298784\n0.77541796\n0.73223968\n0.86088703\n0.82578959\n0.87445074\n0.78854131\n0.71651961\n0.75356978\n0.89205307\n0.63076919\n0.68108546\n0.78324853\n0.81231236\n0.67489391\n0.86190174\n0.93882284\n0.71219443\n0.81794106\n0.77791397\n0.99658527\n0.89073532\n0.79125799\n0.76187166\n0.89247051\n0.98411912\n0.99361515\n0.99917894\n0.81687514\n0.92559640\n1.03118827\n0.81136296\n1.03824815\n1.05747757\n0.85902740\n0.82280532\n0.94793990\n1.06206678\n0.95817863\n0.94721186\n0.97954275\n0.87190598\n0.87943129\n1.10627602\n1.03132168\n0.93524530\n1.12022816\n0.88326675\n1.00812002\n1.09232961\n0.98215176\n1.00551522\n1.04785192\n1.16254847\n1.13221629\n0.92385884\n0.99093408\n1.02526910\n1.17492820\n1.04549129\n0.99535120\n1.10647676\n1.07470146\n1.20405103\n1.21841275\n1.18678542\n1.15741732\n1.17094158\n1.22102433\n0.97372421\n1.05787108\n0.96124800\n1.21112991\n1.11758933\n1.07776840\n1.03837575\n1.13320047\n1.06186627\n0.99770442\n1.00475901\n1.00174633\n1.10606802\n1.02191775\n1.11949009\n1.25785015\n1.09574424\n1.02709132\n1.16305742\n1.25602094\n1.09917127\n1.00816328\n1.03917753\n1.02024246\n1.22011185\n1.13550088\n1.19950776\n1.20919650\n1.17111962\n1.18851026\n1.26332125\n1.19868741\n1.26249579\n1.13991665\n1.04175222\n1.01938168\n1.21270410\n1.09021739\n1.19846119\n1.19202895\n1.15470843\n1.20891742\n1.14472060\n1.13847000\n1.14011525\n1.27015091\n1.10463831\n1.02139412\n1.05667579\n1.18822096\n1.23262592\n1.26989656\n1.04130951\n1.20266940\n1.14750757\n1.09077528\n1.12041802\n1.11351855\n1.15755867\n1.18248668\n1.04709161\n0.98042423\n1.19827002\n1.06420116\n1.17666647\n0.99454129\n0.97010039\n1.20530727\n1.19303944\n1.22635326\n1.18188062\n0.92976392\n1.07810998\n1.20990322\n1.05974287\n1.16422549\n0.91887947\n1.18962606\n1.16564055\n1.05347800\n1.00892311\n0.97603470\n1.08600772\n0.86890974\n0.97196704\n1.13140447\n1.01330727\n0.98620897\n0.98759924\n0.92584064\n1.11282853\n1.11652045\n0.97025440\n1.10814380\n0.94122032\n0.92629938\n0.85639160\n0.84426283\n1.02989645\n0.99176548\n0.92632487\n1.00967544\n0.90798752\n0.91341227\n0.80513293\n0.91074329\n0.77040226\n0.73634379\n0.91870047\n0.88923594\n0.76545421\n0.81426079\n0.87409933\n0.84440086\n0.70869614\n0.71372873\n0.65574957\n0.77331345\n0.78676059\n0.68046170\n0.82477553\n0.62226050\n0.64488575\n0.88665858\n0.88575493\n0.59419155\n0.72494171\n0.82739607\n0.63318771\n0.80229530\n0.78772580\n0.72392020\n0.52742604\n0.63214539\n0.78097172\n0.70512636\n0.60598854\n0.67319952\n0.54781711\n0.63743584\n0.75165961\n0.70312893\n0.52429611\n0.63499475\n0.52864639\n0.70819652\n0.42818262\n0.46890644\n0.62800722\n0.40068027\n0.52544210\n0.59692877\n0.56902913\n0.38048661\n0.45992774\n0.42421247\n0.45315460\n0.47630240\n0.33426910\n0.55254354\n0.46339151\n0.31057684\n0.42180372\n0.52182575\n0.46755761\n0.42859606\n0.35299628\n0.28144519\n0.36432915\n0.25835948\n0.26967996\n0.43727397\n0.41972673\n0.38264954\n0.41211323\n0.17810641\n0.26978846\n0.29268794\n0.36859083\n0.28386692\n0.19146614\n0.28673494\n0.30004103\n0.22486644\n0.06027007\n0.30148283\n0.03085677\n0.16288543\n0.03043397\n0.09882145\n0.21863039\n0.03801402\n0.22012017\n0.15860006\n0.04826872\n-0.00047524\n-0.00926279\n0.13509487\n-0.09006942\n0.09061931\n0.06118840\n0.08919506\n0.14846456\n-0.03942542\n-0.08640967\n0.08891408\n0.05766402\n-0.05564804\n-0.17649604\n-0.04428370\n-0.16710793\n-0.07355204\n-0.13626173\n-0.15802521\n-0.04410111\n-0.11702877\n-0.04417706\n-0.22960452\n-0.09707314\n-0.29428191\n-0.07916748\n-0.12540827\n-0.05460294\n-0.32033111\n-0.08462519\n-0.21349322\n-0.19129384\n-0.29019176\n-0.37097658\n-0.14820889\n-0.36916499\n-0.31046601\n-0.24394085\n-0.14039618\n-0.29341801\n-0.16038253\n-0.39844444\n-0.35582547\n-0.27503114\n-0.47333585\n-0.27710665\n-0.38391191\n-0.27521272\n-0.41325041\n-0.43988299\n-0.24820579\n-0.33693021\n-0.43673761\n-0.53935562\n-0.35677213\n-0.39408544\n-0.57120369\n-0.56522341\n-0.31485645\n-0.46819402\n-0.61834655\n-0.61669548\n-0.59829382\n-0.38016063\n-0.51603904\n-0.49504460\n-0.52241495\n-0.65779937\n-0.41615639\n-0.60612756\n-0.61916064\n-0.52872398\n-0.57125537\n-0.61049121\n-0.53119454\n-0.45323831\n-0.55531797\n-0.66326644\n-0.69316223\n-0.62949904\n-0.75951074\n-0.51120028\n-0.59732028\n-0.72548457\n-0.63672292\n-0.78260708\n-0.54607468\n-0.67774657\n-0.65203922\n-0.65211708\n-0.62370797\n-0.72198125\n-0.81541123\n-0.70737576\n-0.83524454\n-0.63335233\n-0.84857523\n-0.57876266\n-0.64729802\n-0.59366162\n-0.72568656\n-0.81213563\n-0.81104035\n-0.66587165\n-0.60000567\n-0.79535158\n-0.68077053\n-0.87778724\n-0.73577105\n-0.78969741\n-0.70356002\n-0.84822975\n-0.90185482\n-0.79862957\n-0.74542436\n-0.90126943\n-0.80837462\n-0.75180732\n-0.70251880\n-0.86125127\n-0.83592594\n-0.69423063\n-0.75209524\n-0.89238024\n-0.73956873\n-0.88272015\n-0.88914885\n-0.97283348\n-0.86444037\n-0.84786408\n-0.88964669\n-0.89557235\n-0.91187150\n-0.70531878\n-0.72986564\n-0.87025428\n-0.84699814\n-0.82262708\n-0.84644291\n-0.91348872\n-0.69851421\n-0.94123805\n-0.73864860\n-0.98806101\n-0.89886874\n-0.77433757\n-0.80605736\n-0.94890161\n-0.71421719\n-0.83700339\n-0.92456616\n-0.82632426\n-0.72505873\n-0.73072854\n-0.85426136\n-0.86569729\n-0.90439890\n-0.98063755\n-0.77030073\n-0.95596096\n-0.88777595\n-0.87469923\n-0.72661273\n-0.98460660\n-0.73636451\n-0.90167883\n-0.91140966\n-0.83831247\n-0.76433089\n-0.92037396\n-0.91429487\n-0.68419840\n-0.79695134\n-0.88132683\n-0.67996560\n-0.69901705\n-0.90823511\n-0.96204119\n-0.74629383\n-0.69665092\n-0.91852688\n-0.93926725\n-0.76837559\n-0.76330491\n-0.78633980\n-0.93559373\n-0.72764859\n-0.64691170\n-0.66495302\n-0.88923447\n-0.81295772\n-0.84276667\n-0.74317538\n-0.72329377\n-0.81261500\n-0.65907074\n-0.65538645\n-0.65522754\n-0.77961301\n-0.86395216\n-0.66284079\n-0.57269690\n-0.81686869\n-0.82649138\n-0.58156224\n-0.70570582\n-0.58935416\n-0.59653034\n-0.77800121\n-0.75431030\n-0.80657194\n-0.63441622\n-0.57812927\n-0.65209299\n-0.79111987\n-0.49628205\n-0.63698905\n-0.68146645\n-0.72261731\n-0.58073042\n-0.58944313\n-0.53017401\n-0.70282449\n-0.63517958\n-0.69229189\n-0.47348268\n-0.62041903\n-0.63226381\n-0.70599078\n-0.46012102\n-0.54430260\n-0.52493335\n-0.41770494\n-0.45475022\n-0.46373494\n-0.60300340\n-0.48392849\n-0.35347502\n-0.45492735\n-0.38339556\n-0.32277741\n-0.34446830\n-0.53814203\n-0.58389138\n-0.45087110\n-0.57393909\n-0.42777565\n-0.27628417\n-0.47865588\n-0.42905765\n-0.40714291\n-0.27884175\n-0.27219561\n-0.37512007\n-0.38823051\n-0.21596666\n-0.26275342\n-0.25494738\n-0.18334567\n-0.30552698\n-0.21208371\n-0.30504102\n-0.17693499\n-0.30552373\n-0.19205612\n-0.11151226\n-0.23828841\n-0.25709831\n-0.31468164\n-0.27052714\n-0.32496822\n-0.23631217\n-0.24051502\n-0.22743173\n-0.07547169\n-0.15161376\n-0.14526363\n-0.05975807\n-0.24639368\n-0.08523075\n-0.15923719\n-0.15318565\n-0.07150081\n0.02500558\n-0.16487330\n-0.01295100\n0.06564053\n-0.13536384\n-0.09580834\n-0.02650157\n0.10136709\n-0.00530976\n-0.06274995\n0.02423913\n0.04624033\n0.00773318\n-0.10174104\n0.11460793\n0.06576088\n0.03808343\n-0.04684244\n0.05123322\n0.02392137\n0.02468862\n0.21776632\n0.10166049\n0.00970198\n0.11614485\n0.24612722\n0.07321647\n0.30728872\n0.13937728\n0.15253758\n0.12485716\n0.30372730\n0.10452388\n0.37850283\n0.15090694\n0.19931878\n0.32945343\n0.17557699\n0.29676206\n0.36942385\n0.44155372\n0.39238945\n0.40755354\n0.31461760\n0.27407256\n0.36826331\n0.28749329\n0.48422620\n0.44010629\n0.49578946\n0.49874953\n0.41095913\n0.37269936\n0.49570194\n0.59504120\n0.53949317\n0.56688388\n0.53929987\n0.51550743\n0.57216712\n0.50468530\n0.62453661\n0.39469681\n0.67410654\n0.42238555\n0.56602841\n0.53196268\n0.45227908\n0.64647020\n0.62233544\n0.68208775\n0.62610532\n0.70839112\n0.64685787\n0.76581622\n0.75277720\n0.65230717\n0.74530841\n0.65915475\n0.77441843\n0.63100218\n0.83552803\n0.63451948\n0.58122240\n0.79300129\n0.82519509\n0.86068663\n0.69018080\n0.84132340\n0.76954681\n0.75496846\n0.87005176\n0.91718294\n0.66221400\n0.85959066\n0.72505979\n0.78177758\n0.75000709\n0.92671765\n0.98290199\n0.88647291\n0.90992207\n0.98554592\n0.91919888\n0.89038615\n0.84103911\n0.92399090\n0.84934448\n0.86934652\n0.86428070\n0.90072514\n0.91768838\n1.04620700\n0.84128031\n0.88715891\n0.96396374\n0.94387486\n0.88245012\n0.98357138\n1.07901960\n0.83955276\n0.95919491\n0.85779095\n1.00698316\n1.00521958\n1.07917396\n0.92392898\n1.03537034\n1.00192797\n1.12751784\n1.07237487\n0.98510103\n0.98781852\n0.96441504\n1.17860621\n0.98676693\n0.94919759\n1.01434386\n1.13263185\n1.12601049\n1.12851408\n0.92402828\n1.03828612\n1.20016043\n1.02885153\n1.11601596\n1.02967895\n0.98119998\n1.06346328\n1.19542912\n1.24754671\n1.21476683\n0.98419641\n1.06314811\n1.03536144\n1.06245604\n1.26494396\n1.13648277\n1.19908374\n1.22906731\n1.02868448\n1.25155477\n1.01407258\n1.20787487\n1.20487170\n1.20291556\n1.02922001\n1.12434406\n1.14456134\n1.15229089\n1.25217823\n1.19860048\n1.23795484\n1.15639697\n1.28451390\n1.01836950\n1.16134325\n1.08380749\n1.14390110\n1.20531179\n1.06245183\n1.18244428\n1.09777051\n1.26399350\n1.03947943\n1.02980514\n1.28633973\n1.04389725\n1.04311027\n1.04323708\n1.02256493\n1.13104471\n1.19430981\n1.24185600\n1.22826119\n1.20362996\n1.13012299\n1.19934841\n1.27251935\n1.13506521\n1.07298118\n1.21644316\n1.04835250\n1.04556613\n1.11242643\n1.15647669\n1.15280644\n1.00244495\n1.00014942\n1.04560635\n1.17814975\n1.07788786\n1.20016007\n1.22887466\n1.06484051\n0.95746951\n1.10975333\n1.15919605\n1.02737220\n1.07549037\n0.99032408\n1.20173618\n1.06067945\n1.07392889\n0.97409821\n0.93232482\n0.91726083\n1.14064383\n1.12172515\n0.94439184\n1.14953146\n1.08151084\n1.06841192\n1.16352237\n0.87147894\n0.98352464\n0.99803540\n1.02079817\n0.86534971\n1.03295310\n0.84505271\n0.99078180\n1.03162934\n0.95860227\n0.99163538\n0.86453392\n0.98806368\n0.90244475\n0.81317308\n0.88904165\n0.84829782\n0.83539970\n0.94338937\n0.90681297\n0.86725346\n0.80189291\n0.98732090\n0.98118383\n0.80111730\n0.89353611\n0.93567687\n0.98112580\n0.96332469\n0.79559180\n0.72157536\n0.90437596\n0.69199723\n0.69793513\n0.74940701\n0.88929261\n0.80204237\n0.79524156\n0.88925798\n0.77608722\n0.59855377\n0.83031099\n0.76201881\n0.71517097\n0.64349236\n0.63209638\n0.69062201\n0.60611865\n0.54404016\n0.57172233\n0.58992190\n0.56314800\n0.67681951\n0.73350978\n0.72082163\n0.70949894\n0.67240566\n0.70888282\n0.67644752\n0.49426972\n0.72209882\n0.44310598\n0.60108545\n0.46129353\n0.46070351\n0.48021018\n0.42838696\n0.51176580\n0.63559473\n0.45936601\n0.50690572\n0.50407670\n0.52702543\n0.42357926\n0.55118114\n0.56014544\n0.49964933\n0.35044545\n0.49415648\n0.28825978\n0.38708884\n0.40920034\n0.42738055\n0.32146946\n0.41527782\n0.45304383\n0.19377987\n0.20863953\n0.41622665\n0.27394791\n0.26092027\n0.41535673\n0.34276346\n0.40205279\n0.16786140\n0.11671790\n0.19325897\n0.21799272\n0.22900758\n0.34093436\n0.18581070\n0.14822448\n0.31645938\n0.08626259\n0.19756068\n0.27724054\n0.17931036\n0.05772120\n0.11731361\n-0.05157430\n0.20313970\n0.04934071\n0.00841693\n0.19326763\n0.03633469\n-0.02550824\n-0.09634605\n0.04300098\n-0.09563902\n-0.12952339\n0.01284084\n-0.08508494\n-0.07245700\n0.02658883\n0.05682845\n-0.10607675\n0.06830687\n0.05611057\n-0.17786927\n-0.01890340\n-0.07438873\n0.00698292\n-0.09755131\n-0.07726185\n-0.07436287\n-0.19146697\n-0.24104811\n-0.31494127\n-0.19376968\n-0.15128865\n-0.27048869\n-0.20815531\n-0.29911115\n-0.29281896\n-0.19615126\n-0.13305844\n-0.15128738\n-0.35574673\n-0.30805314\n-0.17043369\n-0.36881380\n-0.16466075\n-0.27783758\n-0.42281826\n-0.23335223\n-0.29324585\n-0.33471085\n-0.43189081\n-0.50383493\n-0.45440988\n-0.42457685\n-0.35130914\n-0.25389702\n-0.49590528\n-0.33919711\n-0.30863724\n-0.44102265\n-0.54311521\n-0.35555162\n-0.46385423\n-0.57983832\n-0.35986495\n-0.43981951\n-0.60892228\n-0.37324229\n-0.64287219\n-0.64898962\n-0.37181560\n-0.46993610\n-0.57012084\n-0.53909904\n-0.46854728\n-0.69006346\n-0.49400705\n-0.50837519\n-0.58802275\n-0.55784537\n-0.63757744\n-0.69481339\n-0.63286503\n-0.48323667\n-0.69782706\n-0.66373298\n-0.68098347\n-0.75951670\n-0.63695248\n-0.54697441\n-0.53145186\n-0.59167889\n-0.69969980\n-0.73095286\n-0.61852187\n-0.56749307\n-0.55977729\n-0.81819386\n-0.70311144\n-0.81469269\n-0.78247241\n-0.59824501\n-0.80955177\n-0.83694328\n-0.71506807\n-0.78852972\n-0.77295476\n-0.65466759\n-0.64484864\n-0.69691503\n-0.78020270\n-0.71661520\n-0.84936959\n-0.73243331\n-0.71898598\n-0.74507289\n-0.82523116\n-0.82345477\n-0.88488874\n-0.70118885\n-0.79536753\n-0.84005670\n-0.71710652\n-0.88166979\n-0.70225228\n-0.71363974\n-0.70752898\n-0.85304495\n-0.85173926\n-0.71081813\n-0.83245932\n-0.80278396\n-0.76757535\n-0.69001356\n-0.81641836\n-0.79126477\n-0.81279726\n-0.70766022\n-0.72829447\n-0.93800391\n-0.93677862\n-0.91867062\n-0.76742256\n-0.93435119\n-0.70024508\n-0.78317184\n-0.94426922\n-0.74014777\n-0.72545071\n-0.71031256\n-0.82806903\n-0.83072270\n-0.94682568\n-0.84585792\n-0.83545766\n-0.95035359\n-0.85160652\n-0.83897688\n-0.93950759\n-0.81173682\n-0.99023077\n-0.90182619\n-0.83680195\n-0.89780836\n-0.81422243\n-0.88523935\n-0.95218319\n-0.71725628\n-0.79787449\n-0.79095271\n-0.78442981\n-0.76200684\n-0.73096759\n-0.82677207\n-0.93425878\n-0.86357231\n-0.72932019\n-0.92197355\n-0.87204980\n-0.67866320\n-0.72418257\n-0.89678292\n-0.66077997\n-0.93876683\n-0.82732425\n-0.83065300\n-0.82875663\n-0.91206288\n-0.81504705\n-0.75488289\n-0.63904076\n-0.86590785\n-0.82197951\n-0.84456420\n-0.83312784\n-0.86010882\n-0.90572456\n-0.77362671\n-0.83113057\n-0.63928891\n-0.73691790\n-0.61676529\n-0.59424239\n-0.70612063\n-0.84129459\n-0.59417852\n-0.68913395\n-0.59709475\n-0.72972751\n-0.66969831\n-0.82536650\n-0.56379924\n-0.64315841\n-0.79890003\n-0.61456707\n-0.70019550\n-0.78768569\n-0.74295245\n-0.72671471\n-0.72733657\n-0.57832979\n-0.55680501\n-0.61260617\n-0.60441083\n-0.57487067\n-0.46191567\n-0.56070379\n-0.56420996\n-0.46487551\n-0.55959181\n-0.62335494\n-0.42990488\n-0.57806370\n-0.52250087\n-0.47973765\n-0.48496599\n-0.61748606\n-0.64947289\n-0.58419483\n-0.39879523\n-0.48368981\n-0.50448964\n-0.50710436\n-0.39625188\n-0.42446172\n-0.41544719\n-0.55652655\n-0.46712614\n-0.43726005\n-0.46807399\n-0.42839175\n-0.46154948\n-0.32284803\n-0.43246927\n-0.32579120\n-0.38652988\n-0.30355452\n-0.23248728\n-0.34997382\n-0.22557408\n-0.42233184\n-0.21706997\n-0.44542614\n-0.32176421\n-0.44591137\n-0.20106598\n-0.38080277\n-0.37591997\n-0.36198607\n-0.19992396\n-0.33407296\n-0.29957782\n-0.14927710\n-0.22016300\n-0.08836193\n-0.33450272\n-0.21145504\n-0.16139198\n-0.15410273\n-0.06700002\n-0.26680605\n-0.20506090\n-0.28489005\n0.00940337\n-0.03641361\n-0.03126012\n-0.20531421\n-0.13247539\n-0.18214295\n-0.06878002\n0.03457012\n-0.00837345\n0.01809766\n0.01327841\n0.05005186\n0.09907393\n0.03908759\n-0.08492596\n0.04279817\n-0.07020146\n0.16247863\n-0.07618871\n0.01212414\n0.09471324\n0.07307070\n0.18207542\n0.10969780\n0.02864749\n0.18329387\n0.02503509\n0.18787908\n0.19063884\n0.07923576\n0.07511106\n0.08034513\n0.08531518\n0.11124691\n0.34689495\n0.07515833\n0.36761165\n0.09802851\n0.39160847\n0.19949839\n0.27767500\n0.38877622\n0.40890431\n0.20658038\n0.35797246\n0.45198929\n0.47217860\n0.22167554\n0.25277431\n0.43285963\n0.23350353\n0.24979535\n0.38487161\n0.50280235\n0.55662211\n0.26847718\n0.43956464\n0.54478219\n0.56868613\n0.55908669\n0.57864993\n0.54831778\n0.36915253\n0.49602161\n0.40333934\n0.61136287\n0.64973609\n0.43144444\n0.65494852\n0.51537543\n0.52293673\n0.49871029\n0.68670615\n0.65781610\n0.57870780\n0.66617382\n0.74547241\n0.52325303\n0.55319409\n0.68084350\n0.73984922\n0.76192775\n0.63395212\n0.55771391\n0.55564668\n0.64814615\n0.79706700\n0.62111288\n0.80232103\n0.76963789\n0.58924046\n0.82523641\n0.87432049\n0.75323381\n0.86367111\n0.66074011\n0.85707331\n0.91460047\n0.89436955\n0.72999083\n0.72362500\n0.82389492\n0.79382291\n0.82569655\n0.98741435\n0.87779752\n0.98706765\n0.85779843\n0.84904938\n0.95638997\n0.95466869\n0.87110222\n0.76083947\n0.77791997\n0.99752801\n0.96128993\n0.78072241\n0.94447123\n0.99954334\n0.82289863\n0.86086479\n1.04519141\n0.84941850\n1.07824350\n1.09651299\n0.82896334\n0.94389243\n0.88661306\n1.00377768\n0.87756668\n0.86412068\n1.13749626\n1.15410651\n0.97592251\n1.06583412\n0.89779782\n0.94454063\n0.89871336\n1.03221650\n0.94092508\n1.19768591\n1.03272027\n1.19543048\n1.13021936\n1.09124787\n1.08300114\n1.13640744\n0.93004259\n1.16695464\n1.21383055\n0.94174057\n1.19002564\n1.17612890\n1.24826562\n1.02052198\n1.23109500\n1.15074288\n0.99255409\n1.04412515\n1.19545249\n1.21047826\n1.00253008\n1.11451366\n1.04153909\n1.25476980\n1.07609333\n1.23920079\n1.06173457\n1.24894399\n1.04365139\n1.21647653\n0.99967357\n1.18421792\n1.16282768\n1.10684023\n1.05873345\n1.23356806\n1.04040654\n1.14426904\n1.00203308\n1.05471620\n1.14475510\n1.25100723\n1.04210999\n1.21961151\n1.20732001\n1.01030125\n1.14646417\n1.29097766\n1.03294954\n1.22173194\n1.18978401\n1.17583045\n1.14641655\n1.16634013\n1.12299055\n1.01686654\n1.08002674\n1.16000801\n1.18026513\n1.26805641\n1.28061409\n1.01372326\n1.18242718\n1.16290257\n1.12228186\n1.08498119\n1.11864779\n1.17505324\n1.25931520\n0.99572479\n1.20580321\n1.14109752\n1.23481175\n0.98868334\n1.04342892\n0.96791743\n1.10058462\n1.17666915\n1.02776769\n1.00710151\n1.03540775\n1.06843007\n1.15001063\n1.07800862\n1.03595237\n1.18890614\n1.20280984\n1.09759274\n0.94451099\n1.08609080\n1.01111485\n1.18908589\n0.97320571\n1.09435601\n1.03831315\n0.93087972\n1.07482468\n0.87812159\n0.91321997\n0.86640608\n1.11295462\n1.09402932\n0.87210221\n0.95426106\n0.86160304\n0.99147752\n1.09890012\n0.88515053\n1.09926570\n0.90123934\n0.85276486\n0.98378851\n1.06979757\n0.95828013\n0.78413043\n0.87064430\n0.80191341\n0.81479268\n0.75436862\n1.00245582\n0.96306615\n0.83006013\n0.96077763\n0.93024586\n0.88351828\n0.80798147\n0.79026210\n0.70179139\n0.77022818\n0.82484892\n0.79086861\n0.83873145\n0.79147885\n0.87401365\n0.65104082\n0.75313788\n0.78304562\n0.65426794\n0.77347149\n0.59755217\n0.74652659\n0.81829347\n0.70723285\n0.68069178\n0.58531580\n0.54064282\n0.75066701\n0.75395267\n0.59459068\n0.53243859\n0.60170683\n0.72910132\n0.72417198\n0.66236919\n0.74195201\n0.72791237\n0.46980933\n0.62146459\n0.56215576\n0.42876514\n0.66899381\n0.53964503\n0.61264152\n0.39009553\n0.44142328\n0.54866976\n0.38405769\n0.52613342\n0.44061234\n0.54536606\n0.50202697\n0.41106401\n0.37705823\n0.37950118\n0.54351618\n0.39507040\n0.38126575\n0.37507387\n0.51268030\n0.28508606\n0.47430394\n0.20575751\n0.29251614\n0.40996771\n0.27315537\n0.34609393\n0.28648006\n0.14372914\n0.31049729\n0.30132295\n0.30574510\n0.20379238\n0.23901219\n0.29159173\n0.33742934\n0.07762783\n0.08063486\n0.23607180\n0.26036481\n0.31753468\n0.04874578\n0.11049173\n0.19401772\n0.09387714\n0.23019013\n0.04875137\n-0.00878950\n0.14297770\n-0.00802154\n0.18178482\n0.13661263\n0.02712338\n-0.10856728\n-0.07373269\n-0.04634488\n0.12332182\n0.03207299\n-0.06182766\n-0.08276230\n-0.04730470\n0.08339685\n0.07998817\n-0.05574868\n-0.02883405\n-0.01107987\n-0.22941295\n-0.07381118\n-0.24201007\n-0.13886488\n-0.13493134\n-0.27806303\n-0.27490052\n-0.02677771\n-0.15323323\n-0.21291727\n-0.22322019\n-0.29640654\n-0.30631647\n-0.25530372\n-0.26906376\n-0.14391748\n-0.24233841\n-0.25811628\n-0.36733567\n-0.14990907\n-0.22253278\n-0.18338312\n-0.24597225\n-0.15668686\n-0.16682313\n-0.39456625\n-0.29104604\n-0.26870179\n-0.34643196\n-0.24959352\n-0.45587505\n-0.48446456\n-0.52937559\n-0.49277887\n-0.38681459\n-0.40221618\n-0.44812938\n-0.47874672\n-0.57903334\n-0.34364356\n-0.40474824\n-0.46976983\n-0.53898335\n-0.37906977\n-0.38070824\n-0.37999373\n-0.50316326\n-0.35975261\n-0.40614753\n-0.64244884\n-0.60215961\n-0.43552665\n-0.56633985\n-0.55541654\n-0.41700155\n-0.42004279\n-0.48696994\n-0.55113468\n-0.45558426\n-0.58852602\n-0.69407228\n-0.65272257\n-0.66816186\n-0.59609825\n-0.74976351\n-0.75565495\n-0.73257705\n-0.50456681\n-0.55157874\n-0.58779605\n-0.51580648\n-0.51321882\n-0.52229586\n-0.77920991\n-0.54231340\n-0.67625750\n-0.81862390\n-0.75267413\n-0.58295510\n-0.60627662\n-0.86111760\n-0.67478820\n-0.63083863\n-0.80310924\n-0.86217920\n-0.80715063\n-0.85986967\n-0.75007166\n-0.77393410\n-0.78953484\n-0.64212372\n-0.78612691\n-0.83118947\n-0.90584753\n-0.85841809\n-0.85618867\n-0.92284473\n-0.72451664\n-0.93641337\n-0.75882808\n-0.82298346\n-0.87393782\n-0.75600054\n-0.85867680\n-0.92658428\n-0.79984667\n-0.91378923\n-0.70085654\n-0.76849231\n-0.71655108\n-0.74442284\n-0.73336704\n-0.78773790\n-0.76655014\n-0.77503600\n-0.88720928\n-0.82575931\n-0.72495737\n-0.97211666\n-0.83982249\n-0.86147893\n-0.72128918\n-0.80468570\n-0.69989725\n-0.82021594\n-0.74445344\n-0.85676895\n-0.83451533\n-0.94491993\n-0.80878193\n-0.71060217\n-0.83955509\n-0.85604438\n-0.76189828\n-0.97215344\n-0.73559715\n-0.99844442\n-0.84581726\n-0.79530649\n-0.82859098\n-0.85414755\n-0.90080139\n-0.81565171\n-0.72125063\n-0.78941238\n-0.70901955\n-0.96208544\n-0.83717684\n-0.95602135\n-0.82395671\n-0.77927618\n-0.93996493\n-0.74910138\n-0.86073575\n-0.70894451\n-0.88420688\n-0.95579260\n-0.90595710\n-0.94454188\n-0.68176955\n-0.95937664\n-0.92719057\n-0.95507523\n-0.89104124\n-0.94949682\n-0.75711064\n-0.79157350\n-0.86973884\n-0.88191364\n-0.90931902\n-0.82249639\n-0.92704641\n-0.74483634\n-0.77816021\n-0.82545904\n-0.69054693\n-0.65797002\n-0.82684879\n-0.74701995\n-0.76288200\n-0.79008408\n-0.63614882\n-0.58849876\n-0.69057399\n-0.81930976\n-0.83187882\n-0.68979804\n-0.76014626\n-0.77308357\n-0.68321488\n-0.78879384\n-0.63397936\n-0.81531463\n-0.81621507\n-0.73480510\n-0.79178996\n-0.53900012\n-0.54927394\n-0.67854978\n-0.74041861\n-0.65589225\n-0.65392875\n-0.55385351\n-0.64415158\n-0.47408596\n-0.47949124\n-0.46104569\n-0.63597822\n-0.64593994\n-0.46016429\n-0.65625399\n-0.67301704\n-0.54907078\n-0.42646175\n-0.57014672\n-0.61891355\n-0.65268784\n-0.38899186\n-0.48058160\n-0.54066251\n-0.44683244\n-0.40099187\n-0.53087452\n-0.41533463\n-0.55413539\n-0.31975230\n-0.38584219\n-0.54128555\n-0.45043085\n-0.38521408\n-0.28791263\n-0.39983744\n-0.36237248\n-0.33769218\n-0.25654746\n-0.47917198\n-0.39476899\n-0.41415379\n-0.29108747\n-0.22336144\n-0.33462810\n-0.23129574\n-0.36627722\n-0.29036483\n-0.32976742\n-0.16838353\n-0.22558197\n-0.17084183\n-0.37723525\n-0.31735366\n-0.16165087\n-0.31790539\n-0.36324612\n-0.23320422\n-0.07377930\n-0.26684486\n-0.16514649\n-0.21876921\n-0.30911586\n-0.15754229\n-0.05003342\n-0.21088319\n-0.26522358\n-0.19543087\n-0.06150904\n-0.15123613\n-0.04251552\n-0.22674447\n-0.00548360\n-0.09380448\n-0.19130359\n-0.06974546\n0.03316645\n0.10451750\n0.13318090\n0.14287825\n0.12663483\n0.12735921\n0.11785502\n0.05399111\n0.02310107\n-0.05447159\n0.11373937\n0.18651238\n0.01967946\n0.19933240\n-0.02150164\n0.08090224\n0.05771156\n0.03313547\n0.18655865\n0.10217115\n0.30499147\n0.17685759\n0.25883271\n0.05106788\n0.23883345\n0.24014347\n0.31939558\n0.28363850\n0.36057403\n0.37776511\n0.16266010\n0.18468959\n0.37412088\n0.16493866\n0.27355955\n0.25646976\n0.39658594\n0.21742907\n0.43375465\n0.44059680\n0.37527296\n0.30131333\n0.25632545\n0.43248802\n0.26183493\n0.28270127\n0.31260374\n0.41850861\n0.49460106\n0.55928018\n0.46149694\n0.33608385\n0.42505124\n0.53281084\n0.58562340\n0.44580350\n0.51773380\n0.62318199\n0.56543053\n0.55702118\n0.50451788\n0.53788462\n0.66165961\n0.53545804\n0.58027218\n0.56078769\n0.66321717\n0.63853916\n0.67255114\n0.63311715\n0.61403685\n0.64641156\n0.53175917\n0.64365685\n0.81958927\n0.77153849\n0.76443431\n0.78377632\n0.78935216\n0.82359956\n0.80984901\n0.88052584\n0.62840231\n0.72182497\n0.75856720\n0.69626341\n0.63774903\n0.92673503\n0.86004646\n0.69414193\n0.70168969\n0.87627167\n0.78655913\n0.70255391\n0.81018402\n0.73706183\n0.94100404\n0.98749565\n0.71685941\n0.91740656\n0.93283270\n0.81216546\n0.99576493\n0.83765605\n0.76410935\n0.79055060\n1.00835490\n0.98876426\n1.01664203\n0.97499515\n1.04156258\n0.81048491\n0.92758082\n0.88671855\n0.96188540\n1.08758474\n0.91317277\n1.01426151\n0.84785457\n0.89193031\n1.10084342\n0.91435254\n1.10994973\n0.96747847\n1.07234706\n0.89159098\n1.10095520\n1.03520034\n1.17295058\n0.98140813\n1.01187088\n0.93736583\n1.19694057\n1.04139422\n0.94107394\n1.13468057\n1.07559455\n1.02577300\n1.15709952\n1.18544653\n1.01426872\n1.10189654\n1.07543968\n0.99542793\n1.13139281\n1.23552032\n0.98955388\n1.23006623\n1.12796079\n1.09368150\n1.01374540\n1.04475481\n1.10706446\n1.13495438\n1.08368270\n1.21129209\n1.24583434\n1.20343184\n1.10690977\n1.16791113\n1.18056776\n1.02795621\n1.13995470\n1.08551974\n1.16713387\n1.27772745\n1.12371043\n1.00645130\n1.27612750\n1.27547684\n1.10605928\n1.07704913\n1.23549556\n1.15319768\n1.16866651\n1.20543187\n1.02769810\n1.26163819\n1.28253125\n1.02831359\n1.25268557\n1.27122510\n1.00119453\n1.15418298\n1.19136803\n1.11089471\n1.18912884\n1.22208196\n1.16472007\n1.18027919\n1.07275474\n1.23973563\n1.11422758\n1.17395758\n1.23270628\n1.06181889\n1.09900245\n1.14293972\n1.10762639\n0.99928802\n1.19309596\n0.97707800\n1.09363120\n0.97320573\n1.25198878\n1.11307790\n1.22629576\n1.06531665\n1.21251841\n1.02043378\n1.21329481\n1.20550529\n1.05315589\n1.11747697\n1.09652739\n1.19078638\n0.98277493\n0.91568345\n1.17460920\n0.97678927\n0.97543957\n1.08989249\n0.98452216\n1.13630918\n1.14909881\n1.16288495\n0.99170460\n1.10996751\n0.91172401\n1.04707171\n1.06406382\n0.87488959\n1.00315855\n1.10496603\n0.91200344\n0.89776356\n1.07356660\n0.96459081\n0.85581649\n0.87343379\n0.99560588\n0.96104073\n0.87356215\n0.96648373\n0.98826459\n0.85133566\n0.88434497\n0.86279534\n0.98194643\n0.78149541\n1.00471647\n0.81415939\n0.87023617\n0.94847409\n0.90947244\n0.74418355\n0.90104216\n0.72350732\n0.96126589\n0.93601642\n0.81713809\n0.85893691\n0.94056437\n0.67751179\n0.85782993\n0.87249271\n0.85096391\n0.66589564\n0.72925841\n0.59697813\n0.68214259\n0.61682494\n0.70336931\n0.73163946\n0.78925089\n0.66919665\n0.69461407\n0.80408837\n0.78757291\n0.67271791\n0.77097367\n0.50750304\n0.72580512\n0.57491676\n0.53422389\n0.70346651\n0.55229769\n0.48850505\n0.43829661\n0.70741716\n0.61580104\n0.66074890\n0.67513450\n0.58825147\n0.65016882\n0.44266012\n0.62201242\n0.62297854\n0.42758877\n0.35015729\n0.54889709\n0.33466873\n0.51828696\n0.42446934\n0.47589274\n0.32175635\n0.42070112\n0.44174103\n0.24613885\n0.37330653\n0.48835478\n0.24690513\n0.33567729\n0.39097737\n0.27172363\n0.45856268\n0.37188110\n0.21576389\n0.31026197\n0.39771377\n0.29137109\n0.33978516\n0.37261493\n0.34674729\n0.12349096\n0.13101163\n0.11038146\n0.06297777\n0.04704483\n0.21326266\n0.20704628\n0.29001042\n0.22440620\n0.08467800\n0.13300687\n0.05178561\n0.18419775\n-0.01062202\n0.16817510\n0.17731780\n0.14797617\n0.01558162\n0.07977723\n0.03521604\n-0.08922887\n0.12327960\n0.07053307\n-0.06495401\n0.13580687\n-0.10977710\n-0.08478177\n-0.06124578\n-0.12347323\n-0.14570269\n-0.00238438\n-0.16959116\n-0.07679087\n-0.15435095\n-0.11405536\n0.01501765\n-0.20742122\n-0.28149397\n-0.01939526\n-0.09691590\n-0.15596420\n-0.16331930\n-0.29852261\n-0.03975932\n-0.24052423\n-0.16999867\n-0.24888232\n-0.37387768\n-0.22183745\n-0.24189779\n-0.32976574\n-0.39930897\n-0.16949547\n-0.41658405\n-0.34516441\n-0.21399226\n-0.16621070\n-0.29085833\n-0.24220455\n-0.26608107\n-0.29781842\n-0.30240479\n-0.22878003\n-0.35846321\n-0.40797728\n-0.33484099\n-0.41223333\n-0.51289243\n-0.42929915\n-0.40501701\n-0.45896155\n-0.46615574\n-0.36830906\n-0.44502550\n-0.46255746\n-0.59097949\n-0.55016173\n-0.49892102\n-0.44950864\n-0.43570742\n-0.35833431\n-0.38397542\n-0.64341230\n-0.39239932\n-0.63693493\n-0.40188084\n-0.52108981\n-0.63522809\n-0.69324137\n-0.63127981\n-0.48411886\n-0.71198666\n-0.63540150\n-0.70880981\n-0.70755398\n-0.74288305\n-0.55741727\n-0.74839215\n-0.59558941\n-0.73470496\n-0.59754828\n-0.64941256\n-0.71964125\n-0.56171901\n-0.57119035\n-0.54097721\n-0.82797768\n-0.64152341\n-0.83691478\n-0.81259255\n-0.81779350\n-0.74492707\n-0.78831993\n-0.76141661\n-0.79534263\n-0.75899218\n-0.75359534\n-0.69259105\n-0.65296727\n-0.81276484\n-0.64500909\n-0.68041409\n-0.65898458\n-0.85632736\n-0.89543296\n-0.73594601\n-0.71248061\n-0.89326421\n-0.90171280\n-0.75472714\n-0.69393144\n-0.69665796\n-0.91753640\n-0.72822553\n-0.67959906\n-0.81813831\n-0.93555797\n-0.88724159\n-0.74283031\n-0.95291091\n-0.84027361\n-0.80804121\n-0.68633566\n-0.91209333\n-0.94204898\n-0.78516845\n-0.94849910\n-0.68786321\n-0.91020065\n-0.80449024\n-0.74298284\n-0.74047082\n-0.84417200\n-0.76396295\n-0.71884745\n-0.72418642\n-0.93120728\n-0.83226028\n-0.76176621\n-0.93954745\n-0.77441397\n-0.85631434\n-0.82440542\n-0.92151983\n-0.97443880\n-0.91054699\n-0.72484933\n-0.85873399\n-0.91885050\n-0.77050097\n-0.76734189\n-0.99210514\n-0.73390084\n-0.75774751\n-0.89915115\n-0.79478991\n-0.90561804\n-0.71442410\n-0.90762576\n-0.94025486\n-0.76597473\n-0.84489132\n-0.79040637\n-0.69477642\n-0.88905195\n-0.95814105\n-0.74166294\n-0.86738897\n-0.79929333\n-0.91754364\n-0.94709322\n-0.92159730\n-0.71706380\n-0.87217352\n-0.84453291\n-0.76161531\n-0.70867489\n-0.72095685\n-0.83543963\n-0.88749437\n-0.74716895\n-0.93661015\n-0.84930386\n-0.73897513\n-0.74922495\n-0.82545990\n-0.62246832\n-0.87819806\n-0.69032932\n-0.85993980\n-0.77227248\n-0.64864528\n-0.78590708\n-0.86648085\n-0.71765798\n-0.79785149\n-0.83562106\n-0.66046039\n-0.71961772\n-0.80552013\n-0.82483042\n-0.78949375\n-0.80423451\n-0.74212636\n-0.54862047\n-0.66858231\n-0.74827044\n-0.68566569\n-0.61031296\n-0.64084021\n-0.61646169\n-0.53418681\n-0.67278834\n-0.55610163\n-0.72749238\n-0.75069993\n-0.65978384\n-0.51002568\n-0.63532146\n-0.45013658\n-0.55358060\n-0.62688992\n-0.44307741\n-0.44498473\n-0.45226836\n-0.62334014\n-0.60755644\n-0.45197907\n-0.46823404\n-0.52352067\n-0.37352834\n-0.51346831\n-0.35026756\n-0.49392321\n-0.48235425\n-0.39498854\n-0.50136263\n-0.47391599\n-0.56208238\n-0.36637129\n-0.41627733\n-0.38312406\n-0.33010649\n-0.49514135\n-0.29560438\n-0.27319342\n-0.44859216\n-0.30996961\n-0.41737643\n-0.42883352\n-0.45093217\n-0.29413553\n-0.32386262\n-0.22711394\n-0.38681922\n-0.40531548\n-0.31989486\n-0.29759788\n-0.19572772\n-0.38305499\n-0.39775799\n-0.21578570\n-0.38614391\n-0.34480483\n-0.16805101\n-0.21243083\n-0.19503991\n-0.10591393\n-0.10096266\n-0.17908393\n-0.23719706\n-0.27479780\n-0.03519749\n-0.00053954\n0.00071140\n-0.08100010\n-0.23562630\n-0.23072944\n-0.18871981\n-0.22423766\n-0.00652856\n-0.17100490\n-0.01369616\n0.04227884\n-0.01498124\n-0.06179627\n0.08130962\n-0.06383121\n-0.04959725\n0.09998561\n0.02552694\n-0.03736804\n0.11401410\n-0.04689450\n0.19050173\n-0.00918657\n-0.04079617\n-0.03378692\n0.18495510\n0.20938430\n0.19620403\n0.21154877\n0.28243199\n0.14400094\n0.25017195\n0.15084156\n0.31718586\n0.04445352\n0.34842749\n0.23508789\n0.17794691\n0.25122537\n0.18387018\n0.15160754\n0.31340311\n0.32901621\n0.37139496\n0.24816289\n0.22848703\n0.26683932\n0.27178546\n0.46128139\n0.41967921\n0.28913153\n0.39429610\n0.45201189\n0.48578752\n0.51225171\n0.43006087\n0.28157581\n0.33606811\n0.54109072\n0.41411857\n0.49777202\n0.54398084\n0.39279642\n0.49422159\n0.40620021\n0.34879528\n0.58607546\n0.37196020\n0.49263129\n0.45971488\n0.45443209\n0.60102571\n0.68589912\n0.42264074\n0.65354835\n0.67853109\n0.71993413\n0.74888647\n0.50134752\n0.62990705\n0.72958880\n0.68283512\n0.78658415\n0.79312166\n0.80760714\n0.54635887\n0.66589348\n0.63930900\n0.59164230\n0.60011675\n0.80978405\n0.73363078\n0.86762273\n0.88893336\n0.72342604\n0.71978056\n0.68438599\n0.75798298\n0.71182164\n0.77740245\n0.77719949\n0.73280454\n0.70255600\n0.79566806\n0.82934859\n0.78191097\n0.89727495\n0.83198189\n0.83686838\n0.95112151\n0.96485505\n0.95272360\n0.97069554\n0.89105456\n0.91391040\n0.94318750\n0.78989070\n0.84065212\n0.95804543\n0.87111717\n1.01594279\n0.87216598\n0.80991469\n0.89301707\n0.97686337\n1.10650056\n1.02825839\n1.04254601\n1.00046822\n0.99826037\n1.10638210\n0.96692091\n0.99165294\n0.92186253\n1.09164109\n1.03345047\n0.98155610\n1.08944833\n0.91663717\n0.89048670\n1.07223829\n1.09525538\n1.07586964\n1.17912815\n1.10112885\n1.07208870\n0.99630912\n0.93768348\n1.14573506\n0.97916262\n1.01762650\n1.01487448\n1.10462018\n1.10622302\n1.18353315\n1.21114286\n1.18959033\n1.24712817\n1.01331627\n1.24113562\n0.97818540\n1.03942104\n0.97237450\n1.17358980\n1.24585225\n1.14833227\n1.02534720\n1.13142261\n1.15293774\n1.04090665\n1.08339285\n1.20255529\n1.15513411\n1.03335250\n1.10609047\n1.11216639\n1.16733303\n1.00114644\n1.16951595\n1.27671707\n1.02983669\n1.21803662\n1.29006552\n1.18199145\n1.21554265\n1.09068587\n1.13768412\n1.01440321\n1.11551749\n1.10824401\n1.08572158\n1.24407751\n1.13373954\n1.23998843\n1.23436831\n1.08142182\n1.01614561\n1.01115087\n1.18484779\n1.11969667\n1.26279115\n1.11494964\n1.03449354\n1.14869965\n1.26615245\n1.18153823\n1.09977728\n1.05710741\n1.23171616\n1.25869386\n1.08601401\n0.99073783\n1.02257097\n1.13826659\n1.01865712\n1.04757913\n1.09580086\n1.05845613\n1.04677845\n1.08617382\n1.01574381\n0.94998233\n1.13577998\n0.98237842\n1.17193606\n1.05001803\n1.02187573\n1.14358429\n1.13971518\n0.96393424\n0.94285817\n0.95556220\n1.08723958\n1.14715989\n1.04310419\n0.93520597\n1.09507740\n1.14811790\n0.93670132\n1.12747461\n0.92469652\n1.10701867\n1.10859754\n1.00252304\n0.98333685\n1.10162715\n0.84863581\n0.97631761\n1.00400564\n1.03204019\n0.87509133\n0.80669593\n0.83579292\n1.01883096\n1.07271196\n0.89154623\n1.06718419\n0.86064493\n0.79736997\n0.86506689\n0.91177573\n0.92640549\n0.89193304\n0.81707246\n0.76342350\n0.75438985\n0.74259885\n0.90729303\n0.82658049\n0.71380284\n0.88271749\n0.71901479\n0.89861798\n0.80413725\n0.80684979\n0.69697534\n0.86223874\n0.77698645\n0.78246216\n0.72982184\n0.81155065\n0.60907988\n0.75747287\n0.82942552\n0.69723355\n0.75007112\n0.63698908\n0.71977378\n0.61275338\n0.76043937\n0.75085733\n0.78961740\n0.62802717\n0.62307548\n0.65719209\n0.72122209\n0.46893743\n0.50685412\n0.72480213\n0.71710700\n0.55958896\n0.65786432\n0.68415776\n0.59814809\n0.49883185\n0.49960143\n0.50026267\n0.56289615\n0.48947247\n0.62654560\n0.43755667\n0.42340134\n0.58096874\n0.46632542\n0.51793441\n0.32103729\n0.40994105\n0.28676452\n0.45368452\n0.45609500\n0.51097736\n0.42358292\n0.42283941\n0.46215003\n0.33660788\n0.32396575\n0.41841955\n0.41416695\n0.21399943\n0.15468668\n0.15413064\n0.17005454\n0.16867449\n0.29506558\n0.10621926\n0.22910718\n0.28097441\n0.10190459\n0.12830666\n0.13422549\n0.08933728\n0.12462755\n0.25785132\n0.09740923\n0.23020691\n0.15335076\n0.14392860\n0.18671909\n0.18961941\n0.21779741\n-0.02099002\n0.16580568\n-0.02556331\n-0.08365673\n-0.06408537\n-0.07212307\n-0.08368152\n0.14848432\n-0.06003020\n0.13091315\n0.02967831\n0.09013237\n-0.07134778\n-0.12043391\n-0.14490460\n-0.04719079\n-0.14411503\n-0.13864522\n-0.23544701\n-0.07356046\n0.02929030\n-0.01416724\n-0.27635690\n-0.09812090\n-0.19010196\n-0.27320237\n-0.15467509\n-0.20146257\n-0.18069531\n-0.07939029\n-0.30977616\n-0.23352429\n-0.35551152\n-0.26817275\n-0.17499128\n-0.37234753\n-0.20986728\n-0.33020432\n-0.24861384\n-0.39164244\n-0.31525654\n-0.45129201\n-0.39527133\n-0.39370944\n-0.32818561\n-0.42581539\n-0.39519856\n-0.28332712\n-0.39217638\n-0.50807480\n-0.41627800\n-0.39937380\n-0.30250114\n-0.46732764\n-0.32015119\n-0.40519516\n-0.56673796\n-0.51314325\n-0.42245238\n-0.46323939\n-0.55547960\n-0.55122479\n-0.39666205\n-0.45325556\n-0.60287449\n-0.43887351\n-0.54079580\n-0.53000061\n-0.46393323\n-0.56308868\n-0.68640188\n-0.67552196\n-0.52772044\n-0.57829674\n-0.44109610\n-0.69752745\n-0.62021040\n-0.57580368\n-0.71279316\n-0.48157641\n-0.56947570\n-0.49430278\n-0.58315127\n-0.77436232\n-0.68992326\n-0.75746267\n-0.60826316\n-0.78488775\n-0.60682029\n-0.67162432\n-0.72894810\n-0.67138568\n-0.61976821\n-0.59330131\n-0.74806628\n-0.75475803\n-0.74991071\n-0.65868205\n-0.60533592\n-0.64012116\n-0.61081432\n-0.61701825\n-0.83128725\n-0.63270433\n-0.60445339\n-0.66573695\n-0.63867391\n-0.88524382\n-0.71562901\n-0.81654553\n-0.72568690\n-0.65779035\n-0.81345687\n-0.69926686\n-0.88250916\n-0.78057149\n-0.75171230\n-0.72914098\n-0.85466801\n-0.87065782\n-0.67804503\n-0.77132265\n-0.93077168\n-0.77321043\n-0.90661043\n-0.73373225\n-0.70997764\n-0.87166252\n-0.93342484\n-0.74662352\n-0.88279655\n-0.90468599\n-0.92229859\n-0.96344091\n-0.82029513\n-0.86635076\n-0.76398666\n-0.84429460\n-0.87634302\n-0.97458633\n-0.93003216\n-0.83200891\n-0.87290934\n-0.72664595\n-0.98078054\n-0.86524736\n-0.83748927\n-0.95904787\n-0.83731498\n-0.74262182\n-0.94056022\n-0.95331585\n-0.98151841\n-0.80144270\n-0.99391730\n-0.91180045\n-0.70651751\n-0.76870598\n-0.92432659\n-0.79203086\n-0.95444357\n-0.80589109\n-0.73666536\n-0.72266607\n-0.88683160\n-0.84408648\n-0.78466270\n-0.77572095\n-0.84703317\n-0.87425904\n-0.89760515\n-0.95686920\n-0.84429089\n-0.92581657\n-0.85365630\n-0.69476079\n-0.81509398\n-0.69171286\n-0.93574004\n-0.66267741\n-0.92883075\n-0.86089309\n-0.71620582\n-0.76798411\n-0.80572265\n-0.85275217\n-0.89884194\n-0.84679941\n-0.88172876\n-0.83290733\n-0.89131542\n-0.67077733\n-0.62497024\n-0.84691940\n-0.69643896\n-0.89232878\n-0.71482460\n-0.69449415\n-0.87964368\n-0.88521544\n-0.83879954\n-0.61805210\n-0.78910972\n-0.70747350\n-0.70528789\n-0.68655610\n-0.75173309\n-0.72233417\n-0.71668633\n-0.54036179\n-0.81268053\n-0.70542045\n-0.58128569\n-0.63464292\n-0.71416503\n-0.53054778\n-0.76712515\n-0.69325018\n-0.51668603\n-0.57928292\n-0.56481762\n-0.62157134\n-0.71488955\n-0.46541648\n-0.47926218\n-0.60610012\n-0.48005258\n-0.62613149\n-0.60644523\n-0.47127603\n-0.67285512\n-0.40996288\n-0.68783523\n-0.59236988\n-0.65909540\n-0.53338543\n-0.42176278\n-0.37710379\n-0.48356183\n-0.39462901\n-0.45930406\n-0.39502665\n-0.60964587\n-0.46144366\n-0.52138396\n-0.49605139\n-0.29022735\n-0.50949795\n-0.40776635\n-0.48795896\n-0.37712145\n-0.23943504\n-0.49087389\n-0.23552687\n-0.47621076\n-0.44889537\n-0.30215837\n-0.44895120\n-0.45424977\n-0.27207394\n-0.45277155\n-0.15654031\n-0.28135281\n-0.32201515\n-0.21311527\n-0.13183992\n-0.29226612\n-0.18992206\n-0.20797875\n-0.14678949\n-0.19254526\n-0.24793329\n-0.09624811\n-0.27434280\n-0.09356216\n-0.02413836\n-0.22933012\n-0.09109840\n-0.09527898\n-0.16065038\n-0.12602100\n0.01886156\n0.02973236\n-0.02666632\n-0.12143583\n-0.21508785\n-0.04248271\n-0.03817738\n-0.09124401\n0.07607360\n0.00920334\n0.01889774\n-0.06971891\n-0.12615591\n-0.05055179\n-0.05833149\n-0.01506118\n0.14565164\n-0.05084034\n-0.04163464\n0.07356843\n0.11193346\n-0.01065833\n0.14154419\n0.21408030\n0.20557303\n0.06025923\n0.08529797\n0.05584683\n0.14512992\n0.11889022\n0.11482813\n0.32040594\n0.17077392\n0.17467749\n0.24868274\n0.10135198\n0.15233437\n0.31780258\n0.28320533\n0.18066368\n0.38355886\n0.26754153\n0.31374155\n0.31858517\n0.22558998\n0.20441022\n0.32895908\n0.20870614\n0.33982371\n0.38645578\n0.42047684\n0.24883046\n0.46123454\n0.30873594\n0.44560205\n0.45962858\n0.51851106\n0.31325066\n0.56232188\n0.43069480\n0.44476882\n0.43194952\n0.51034902\n0.44173135\n0.47227934\n0.47645962\n0.57007695\n0.58956886\n0.69705262\n0.69187964\n0.52278230\n0.48464224\n0.71163794\n0.53135138\n0.61893579\n0.73836403\n0.49842391\n0.55751367\n0.61706658\n0.67096769\n0.77615587\n0.58036525\n0.81355376\n0.66213290\n0.77582630\n0.70633678\n0.65648186\n0.69485337\n0.78896569\n0.85662141\n0.85687058\n0.63831941\n0.64186704\n0.88185397\n0.81760756\n0.64156681\n0.78863671\n0.91323277\n0.76822560\n0.74766770\n0.73774217\n0.73522803\n0.79638016\n0.86800198\n0.77728837\n0.89064334\n0.95234831\n0.74916597\n0.94367136\n0.92632854\n0.88092686\n1.02510927\n0.78079938\n0.93815381\n0.83497076\n0.78100297\n0.95158824\n1.03653813\n0.95711763\n1.04810427\n0.86363628\n0.99445807\n0.86613808\n0.90656257\n0.83093834\n1.04144068\n1.12214038\n1.06665333\n1.07432210\n1.01519924\n0.94237475\n0.93631594\n0.95376027\n1.16172966\n0.94683519\n1.04357250\n0.94853980\n1.02182226\n0.93875685\n1.01316217\n1.14285896\n1.15284872\n1.18426365\n1.07927014\n1.16645574\n1.13746896\n0.94166135\n0.97614434\n1.00592987\n1.01341452\n0.99387011\n1.01658915\n1.03190262\n1.23784357\n1.05936492\n1.04746671\n1.08240867\n1.05446661\n1.19360691\n1.07685830\n1.00882967\n1.15884209\n1.08257332\n1.08693151\n1.00063130\n1.24217014\n1.12122899\n1.00888491\n1.25871827\n1.07329356\n1.17439216\n1.19013118\n1.05282700\n1.28196204\n1.19454512\n1.15835093\n1.25749970\n1.16467166\n1.00462548\n1.14355901\n1.24159945\n1.22035559\n1.17149316\n1.00264637\n1.21548413\n1.13477706\n1.19768320\n1.22550978\n1.24061813\n1.00749234\n1.23214021\n1.16774972\n1.01962935\n1.07143102\n1.03503135\n1.16328819\n1.15509202\n1.01222642\n1.28673244\n1.06408598\n1.08185455\n1.07576631\n0.99643896\n1.14035728\n1.05685503\n1.10062477\n1.26013120\n1.24942975\n1.00768925\n1.14647315\n1.07426202\n1.17953848\n1.11809538\n1.03647062\n1.10323314\n1.20905632\n1.16652841\n1.00574567\n0.98990980\n1.05048388\n1.19454607\n1.13772292\n1.11888993\n0.96727113\n0.94481590\n1.17992782\n1.03918010\n1.05522655\n1.04281019\n1.05511033\n0.97761004\n0.96100065\n1.15681274\n1.15489884\n1.05863139\n0.98227062\n1.04735070\n1.06330679\n1.12603069\n0.87867718\n1.00890943\n0.97038640\n1.02155837\n0.99855235\n0.89303897\n0.85095127\n0.81681839\n0.82571939\n0.89883663\n1.02987117\n0.89057950\n0.96963522\n1.07538069\n0.96558927\n0.92671577\n0.82797844\n0.97369484\n1.01181086\n0.99634892\n0.91074451\n0.92119839\n0.99235094\n0.84080388\n0.79070831\n0.88620552\n0.77805847\n0.86876270\n0.68906825\n0.96577741\n0.72194340\n0.83457706\n0.74904545\n0.85240148\n0.63773865\n0.64159056\n0.89179249\n0.63207862\n0.69747994\n0.74756813\n0.65560103\n0.73631459\n0.79948413\n0.71351099\n0.82819807\n0.58435863\n0.65681266\n0.60737556\n0.69417021\n0.51708352\n0.51659734\n0.58565672\n0.50955723\n0.52226076\n0.57375309\n0.46544277\n0.65735155\n0.62800220\n0.47879501\n0.43615665\n0.53040145\n0.53817422\n0.45086942\n0.64170488\n0.55095673\n0.36917622\n0.62276141\n0.47944334\n0.35155903\n0.35659024\n0.61476280\n0.56562770\n0.48075490\n0.29471058\n0.37378943\n0.40654321\n0.28746648\n0.41938294\n0.33614940\n0.36381111\n0.39227022\n0.23160216\n0.21656254\n0.27983760\n0.33623902\n0.33844072\n0.23248010\n0.42395073\n0.38796096\n0.26369643\n0.41503038\n0.28395878\n0.17086142\n0.33375730\n0.21599917\n0.14563635\n0.34729848\n0.09347788\n0.19446227\n0.32227721\n0.21519920\n0.19510559\n0.14159961\n0.16403884\n0.25409966\n0.08357477\n0.02934404\n0.07778192\n0.02281810\n0.06412969\n0.10904208\n0.07121549\n0.01650023\n0.15295699\n-0.02890813\n-0.00892664\n0.01647158\n-0.13019410\n-0.08921250\n-0.13294217\n-0.14870240\n0.07891561\n-0.18796210\n0.04393967\n-0.06536204\n-0.19317659\n-0.08988457\n-0.06688879\n-0.22933483\n0.02741481\n-0.07977289\n-0.14693744\n-0.03571967\n-0.22553892\n-0.06670887\n-0.22468387\n-0.05043268\n-0.26900352\n-0.06448176\n-0.20771103\n-0.20089218\n-0.08142189\n-0.15747418\n-0.30382254\n-0.38975530\n-0.40300820\n-0.18141877\n-0.31070908\n-0.32806778\n-0.29532011\n-0.19350949\n-0.34822798\n-0.29749050\n-0.45912121\n-0.39547426\n-0.46147282\n-0.44006745\n-0.40839500\n-0.44949329\n-0.47435901\n-0.35731518\n-0.31586082\n-0.50150668\n-0.30341302\n-0.35674880\n-0.42765962\n-0.30564066\n-0.43516047\n-0.54725318\n-0.36310465\n-0.36964528\n-0.54200303\n-0.54558344\n-0.39929532\n-0.51109503\n-0.65077375\n-0.44036199\n-0.55312140\n-0.60442207\n-0.59557690\n-0.59269642\n-0.47141952\n-0.70525785\n-0.50580044\n-0.46885969\n-0.65171131\n-0.54711793\n-0.68124928\n-0.57079655\n-0.74133734\n-0.48026305\n-0.59363715\n-0.66777424\n-0.77990023\n-0.53790495\n-0.62013561\n-0.55279027\n-0.66162064\n-0.81641407\n-0.54876530\n-0.70689331\n-0.61592950\n-0.79575855\n-0.60188696\n-0.57885834\n-0.62355335\n-0.63491044\n-0.74551322\n-0.66144053\n-0.70722376\n-0.70620463\n-0.78282650\n-0.67961761\n-0.84712610\n-0.89933910\n-0.73551113\n-0.74439384\n-0.74722761\n-0.70816052\n-0.64222728\n-0.64107433\n-0.65712790\n-0.75055169\n-0.65750414\n-0.90377315\n-0.84001265\n-0.93453581\n-0.78725129\n-0.73070602\n-0.90052514\n-0.82993963\n-0.93118921\n-0.87240302\n-0.73196627\n-0.80745190\n-0.74025870\n-0.78164005\n-0.70762435\n-0.95950984\n-0.92703584\n-0.85682013\n-0.76163634\n-0.71744331\n-0.97923107\n-0.94727678\n-0.86277922\n-0.76199618\n-0.83529669\n-0.76744581\n-0.94391368\n-0.79399862\n-0.81108482\n-0.99539108\n-0.77604176\n-0.70115348\n-0.96068456\n-0.89132906\n-0.94244689\n-0.78561457\n-0.94663877\n-0.70390926\n-0.99472916\n-0.98765499\n-0.75795984\n-0.74088646\n-0.82841365\n-0.77142104\n-0.84106609\n-0.82031516\n-0.93793297\n-0.84308730\n-0.97771279\n-0.97492661\n-0.88986509\n-0.79972282\n-0.71987194\n-0.78381858\n-0.77853116\n-0.77356313\n-0.74041421\n-0.78016112\n-0.82024290\n-0.87448653\n-0.69144182\n-0.89533956\n-0.81341281\n-0.74207476\n-0.88521856\n-0.70499653\n-0.79433261\n-0.67974950\n-0.84449453\n-0.66593014\n-0.66493827\n-0.76357618\n-0.90589583\n-0.82280623\n-0.84646662\n-0.84564936\n-0.85368281\n-0.91732180\n-0.64579768\n-0.77354112\n-0.73186360\n-0.80641723\n-0.59851271\n-0.59707912\n-0.59832261\n-0.68315862\n-0.66045365\n-0.77326343\n-0.71173210\n-0.78155851\n-0.64296563\n-0.61990276\n-0.82373211\n-0.77623588\n-0.77609635\n-0.64454495\n-0.60862058\n-0.57019761\n-0.80908096\n-0.74827551\n-0.66226325\n-0.68347263\n-0.68879340\n-0.76559742\n-0.55011477\n-0.65140185\n-0.56352127\n-0.59401661\n-0.73735735\n-0.65392564\n-0.44984628\n-0.45326852\n-0.61246113\n-0.53365358\n-0.54320822\n-0.45574242\n-0.41047293\n-0.66793299\n-0.41691044\n-0.50724832\n-0.61027311\n-0.59467410\n-0.44184521\n-0.46694451\n-0.46241835\n-0.34002932\n-0.44826188\n-0.58498988\n-0.55703268\n-0.56840826\n-0.54712523\n-0.38143380\n-0.38279285\n-0.45480627\n-0.50940646\n-0.43308833\n-0.30157163\n-0.41319296\n-0.29810850\n-0.42754180\n-0.31551223\n-0.23333719\n-0.42728779\n-0.33733326\n-0.43875523\n-0.42410462\n-0.43573248\n-0.42221608\n-0.24894660\n-0.30461650\n-0.22738083\n-0.15288979\n-0.17164253\n-0.09868504\n-0.14785089\n-0.09237781\n-0.14201052\n-0.27833727\n-0.12927970\n-0.12759807\n-0.09421969\n-0.09258114\n-0.21173038\n-0.14458469\n-0.05623276\n-0.10671795\n0.01721044\n-0.20782812\n0.02254149\n-0.01426748\n-0.14436101\n-0.03224773\n-0.07185765\n-0.16208839\n-0.02629881\n0.10956366\n-0.03880379\n0.01570359\n-0.11841802\n-0.08186173\n-0.08302233\n-0.11092929\n-0.03024388\n-0.03307875\n0.01539724\n-0.04190147\n0.22734419\n0.09179939\n0.06408058\n0.03267129\n0.07713419\n0.09742196\n0.26559339\n0.14634473\n0.19045887\n0.01914446\n0.20401794\n0.27093264\n0.24483972\n0.21616524\n0.31538309\n0.36635481\n0.18171140\n0.33667300\n0.19304749\n0.12189973\n0.15560096\n0.23588498\n0.23883628\n0.16245662\n0.21558009\n0.30996591\n0.41663360\n0.40079423\n0.42057369\n0.35392153\n0.50152079\n0.53215372\n0.52495791\n0.39331694\n0.53599346\n0.39008273\n0.46465521\n0.46142058\n0.55662211\n0.39782668\n0.52086452\n0.51199802\n0.53767791\n0.44310364\n0.45896593\n0.42524541\n0.40826778\n0.47327069\n0.50294938\n0.56639039\n0.71203157\n0.43231342\n0.64575553\n0.71343568\n0.71058584\n0.49549120\n0.75518036\n0.60967857\n0.74889920\n0.75437081\n0.61009518\n0.70150829\n0.78009225\n0.53553605\n0.56074273\n0.65911534\n0.59920886\n0.57297413\n0.80565801\n0.67733755\n0.83252994\n0.64743705\n0.80619141\n0.87398065\n0.84633044\n0.69589288\n0.74244692\n0.75140826\n0.73032291\n0.75884675\n0.69124429\n0.80805766\n0.81635537\n0.69596522\n0.88561482\n0.71948213\n0.75949340\n0.92115768\n0.88907158\n0.73138749\n0.82280468\n0.85609136\n0.79371025\n0.77870190\n0.90106852\n0.88039153\n1.02299110\n0.94315761\n1.03334662\n0.93232211\n0.80445466\n0.80769610\n0.86194518\n0.92765360\n1.03904810\n0.87704271\n0.91839479\n1.03370914\n0.93176909\n0.94748279\n0.90273915\n0.97753803\n1.13499788\n1.13756023\n0.99417927\n1.08351009\n0.96122644\n1.17515934\n1.08207952\n0.96118162\n0.93632625\n1.07742671\n0.99412319\n0.93723293\n0.96738672\n0.93858462\n1.13177788\n1.16573098\n1.17701215\n1.01782355\n1.21048834\n1.12743123\n0.95257802\n1.05459395\n1.11451716\n1.14568348\n1.09421713\n1.20627285\n1.00903848\n1.26059126\n1.22072602\n1.07498684\n1.16008941\n1.06850822\n1.00621294\n1.13787305\n1.23087262\n1.21423468\n1.27102151\n1.08836825\n1.10670110\n1.03627999\n1.09254489\n1.15971539\n1.15977876\n1.04379624\n1.03167656\n1.11689499\n1.24742517\n1.05409123\n1.14930735\n1.03734680\n1.25912189\n1.22990799\n1.16930128\n1.11684696\n1.14689839\n1.26570927\n1.27083352\n1.14841678\n1.15714935\n1.27067281\n1.17062368\n1.22896154\n1.19372663\n1.13518811\n1.05910450\n1.17273509\n1.04592063\n1.04848154\n1.24631305\n1.02379819\n1.17806689\n1.11377923\n1.16445799\n1.19991582\n1.06755170\n0.98725729\n1.22272091\n1.08046558\n1.16558242\n1.23330739\n1.04413546\n1.25849342\n1.20655212\n1.19067581\n1.14718779\n1.11014214\n1.05978619\n1.18709859\n1.11558245\n1.16793393\n1.22610999\n1.16255688\n1.17813751\n1.06403337\n1.17647279\n1.01040510\n0.96766000\n1.05009547\n0.90678424\n1.14123734\n0.96769641\n1.08703430\n1.11722075\n1.07880365\n1.06457988\n0.93556931\n1.00251609\n1.13506314\n0.92122532\n0.90630045\n0.91989555\n1.06540302\n0.92650180\n1.00233866\n0.87087644\n0.83608380\n0.89661394\n0.86721564\n1.06464123\n1.06680422\n0.78907780\n0.95130555\n0.77997665\n0.88784553\n0.91031630\n0.99933561\n0.92805982\n0.81035540\n0.99837107\n0.95025089\n0.88188536\n0.97518547\n0.80934632\n0.79305500\n0.87013633\n0.70322393\n0.78241242\n0.71851837\n0.89793672\n0.86416235\n0.84193457\n0.90600729\n0.87031846\n0.78080251\n0.61294091\n0.62871682\n0.74671085\n0.86994138\n0.82896975\n0.84835226\n0.85161293\n0.66303138\n0.63917299\n0.76945220\n0.58966593\n0.80521407\n0.78795552\n0.60997086\n0.59504207\n0.69064002\n0.68903558\n0.70532896\n0.63445202\n0.47658271\n0.60631755\n0.44238253\n0.64769285\n0.60920335\n0.58201152\n0.46109656\n0.59789755\n0.59188070\n0.46850465\n0.36573726\n0.59963393\n0.56824173\n0.48061448\n0.53034549\n0.54611288\n0.39843474\n0.56377998\n0.45310335\n0.35685107\n0.34089712\n0.51822441\n0.35130949\n0.27676778\n0.50592228\n0.40751326\n0.49714446\n0.25082737\n0.43147795\n0.32115542\n0.34039067\n0.16675029\n0.31273124\n0.32355342\n0.27300305\n0.13153084\n0.25825198\n0.10971040\n0.33688102\n0.25222442\n0.27115200\n0.24803176\n0.23090766\n0.32004081\n0.07697073\n0.15636092\n0.25661088\n0.14297888\n0.21261192\n0.02785595\n0.17138427\n0.22823360\n-0.00728353\n0.06236679\n-0.06348118\n-0.01827994\n0.10388281\n0.15549228\n-0.01243098\n-0.11760072\n0.13589448\n-0.00427221\n0.11766232\n-0.06695341\n0.03212979\n-0.17980328\n-0.04115152\n-0.10510988\n-0.11359820\n0.06181524\n-0.00877090\n-0.14345595\n-0.06346972\n-0.13831684\n-0.09966531\n0.00562747\n-0.10704744\n-0.25617858\n-0.05939064\n-0.10251104\n-0.29716359\n-0.29083578\n-0.25952804\n-0.23091140\n-0.20878102\n-0.29405862\n-0.13744583\n-0.15720348\n-0.32208124\n-0.22862364\n-0.39195173\n-0.23047072\n-0.33624031\n-0.24856616\n-0.36973478\n-0.26306184\n-0.35787638\n-0.36723326\n-0.43141175\n-0.28481728\n-0.26500418\n-0.24142564\n-0.37365053\n-0.47841016\n-0.36389585\n-0.49367057\n-0.43831004\n-0.31375242\n-0.44914041\n-0.30829967\n-0.48214762\n-0.39261131\n-0.43345168\n-0.58767254\n-0.50204517\n-0.35611991\n-0.62457259\n-0.53366470\n-0.58426328\n-0.59562343\n-0.56427420\n-0.40155672\n-0.53534727\n-0.45236616\n-0.59542718\n-0.57000533\n-0.42931162\n-0.68170468\n-0.70739443\n-0.52347623\n-0.46253036\n-0.71603725\n-0.55978993\n-0.71799627\n-0.56006578\n-0.58693350\n-0.76778603\n-0.54773327\n-0.49737588\n-0.66826498\n-0.70183318\n-0.79650489\n-0.74939362\n-0.64837670\n-0.64791178\n-0.75812984\n-0.64306046\n-0.82672793\n-0.56791396\n-0.82753079\n-0.76023523\n-0.67016632\n-0.71927404\n-0.71604874\n-0.76638065\n-0.65414901\n-0.80468284\n-0.69918045\n-0.62174377\n-0.80354416\n-0.66297053\n-0.67487742\n-0.87794608\n-0.87200976\n-0.79861782\n-0.72071642\n-0.73331137\n-0.73024250\n-0.93493954\n-0.90259868\n-0.71534154\n-0.69517625\n-0.72680900\n-0.67058412\n-0.68097908\n-0.89282757\n-0.80958022\n-0.72885260\n-0.81100685\n-0.78499582\n-0.80511517\n-0.75556648\n-0.95802267\n-0.83128887\n-0.91213123\n-0.88177661\n-0.81928971\n-0.76336416\n-0.86436827\n-0.83726571\n-0.95225181\n-0.92778605\n-0.90558186\n-0.85953566\n-0.92343598\n-0.91743723\n-0.72973752\n-0.82206663\n-0.71690270\n-0.81357778\n-0.92418278\n-0.96893408\n-0.83598299\n-0.86719534\n-0.79253404\n-0.77205091\n-0.87985327\n-0.82915251\n-0.93729832\n-0.71541199\n-0.84402581\n-0.91429127\n-0.92762111\n-0.70958255\n-0.78763337\n-0.78099689\n-0.79508191\n-0.75716880\n-0.81531964\n-0.83699399\n-0.72274736\n-0.86678706\n-0.91008781\n-0.89649882\n-0.70756574\n-0.76610682\n-0.71880731\n-0.85883610\n-0.78015466\n-0.95811702\n-0.68900019\n-0.82141585\n-0.80360240\n-0.72681721\n-0.85288767\n-0.76290355\n-0.84947986\n-0.85097502\n-0.74714574\n-0.80742985\n-0.90314572\n-0.85954732\n-0.63514567\n-0.71320651\n-0.72114360\n-0.81716052\n-0.90496270\n-0.73559595\n-0.89157504\n-0.81870023\n-0.83648325\n-0.75435925\n-0.65393202\n-0.69143871\n-0.78061249\n-0.78252515\n-0.84169519\n-0.80852541\n-0.63858043\n-0.82290043\n-0.56907685\n-0.71011848\n-0.80962186\n-0.65632930\n-0.57279185\n-0.71238198\n-0.57681273\n-0.59238371\n-0.62162832\n-0.67975858\n-0.66857556\n-0.65201812\n-0.64731275\n-0.70217538\n-0.61237872\n-0.74292651\n-0.57884630\n-0.72687735\n-0.47319070\n-0.47004899\n-0.61968757\n-0.42199224\n-0.42073388\n-0.40347437\n-0.64556965\n-0.68476444\n-0.60387239\n-0.56705794\n-0.59349487\n-0.42921429\n-0.58062289\n-0.50622294\n-0.55521319\n-0.52153555\n-0.34655223\n-0.60573152\n-0.56191706\n-0.47714706\n-0.33330216\n-0.51337262\n-0.28858851\n-0.26996812\n-0.44002398\n-0.24878075\n-0.49919752\n-0.29906604\n-0.34502209\n-0.32390906\n-0.35465916\n-0.42681956\n-0.44098935\n-0.28490343\n-0.22591042\n-0.25687446\n-0.30737309\n-0.15655220\n-0.25344904\n-0.35382355\n-0.20760716\n-0.30743853\n-0.16978658\n-0.08581049\n-0.29508623\n-0.08716053\n-0.14848381\n-0.31946491\n-0.26488902\n-0.04882750\n-0.17583068\n-0.04551683\n-0.06696414\n-0.28571627\n-0.05039189\n-0.06627171\n-0.00207473\n"
  },
  {
    "path": "testData/testSinusoid_output.txt",
    "content": "0.13687262547490, DN_OutlierInclude_n_001_mdrmd, 8.703000\n-0.13777244551090, DN_OutlierInclude_p_001_mdrmd, 6.593000\n1.27292807660985, DN_HistogramMode_5, 0.041000\n-1.12758575737747, DN_HistogramMode_10, 0.039000\n1.64629633438112, CO_Embed2_Dist_tau_d_expfit_meandiff, 8.099000\n119.74079600337870, CO_f1ecac, 6.009000\n2.00000000000000, CO_FirstMin_ac, 4.579000\n1.07949995567938, CO_HistogramAMI_even_2_5, 0.320000\n-0.00017509308632, CO_trev_1_num, 0.110000\n0.00625000000000, FC_LocalSimple_mean1_tauresrat, 13.819000\n0.14051134209844, FC_LocalSimple_mean3_stderr, 0.190000\n1.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 1.845000\n0.82200000000000, MD_hrv_classic_pnn40, 0.041000\n6.00000000000000, SB_BinaryStats_diff_longstretch0, 0.051000\n301.00000000000000, SB_BinaryStats_mean_longstretch1, 0.046000\n1.38225822030023, SB_MotifThree_quantile_hh, 1.417000\n0.77551020408163, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 3.221000\n0.69387755102041, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 1.645000\n0.98817221358274, SP_Summaries_welch_rect_area_5_1, 2.410000\n0.00997087512126, SP_Summaries_welch_rect_centroid, 2.218000\n0.01005896635449, SB_TransitionMatrix_3ac_sumdiagcov, 6.992000\n628.00000000000000, PD_PeriodicityWang_th0_01, 17.879000\n\n"
  },
  {
    "path": "testData/test_output.txt",
    "content": "-0.23703703703704, DN_OutlierInclude_n_001_mdrmd, 0.252000\n0.40740740740741, DN_OutlierInclude_p_001_mdrmd, 0.302000\n-0.61479911484527, DN_HistogramMode_5, 0.003000\n-0.78225446555221, DN_HistogramMode_10, 0.003000\n7.13507860878856, CO_Embed2_Dist_tau_d_expfit_meandiff, 0.234000\n32.50260547693646, CO_f1ecac, 0.192000\n77.00000000000000, CO_FirstMin_ac, 0.191000\n1.00638907799376, CO_HistogramAMI_even_2_5, 0.014000\n0.00001782472612, CO_trev_1_num, 0.006000\n0.84782608695652, FC_LocalSimple_mean1_tauresrat, 0.388000\n0.08029384289851, FC_LocalSimple_mean3_stderr, 0.007000\n40.00000000000000, IN_AutoMutualInfoStats_40_gaussian_fmmi, 0.086000\n0.31970260223048, MD_hrv_classic_pnn40, 0.002000\n83.00000000000000, SB_BinaryStats_diff_longstretch0, 0.002000\n88.00000000000000, SB_BinaryStats_mean_longstretch1, 0.003000\n1.21058781724385, SB_MotifThree_quantile_hh, 0.034000\n0.29545454545455, SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 0.169000\n0.75000000000000, SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 0.073000\n0.99313877887425, SP_Summaries_welch_rect_area_5_1, 0.075000\n0.03681553890926, SP_Summaries_welch_rect_centroid, 0.069000\n0.08000000000000, SB_TransitionMatrix_3ac_sumdiagcov, 0.198000\n0.00000000000000, PD_PeriodicityWang_th0_01, 0.100000\n\n"
  },
  {
    "path": "wrap_Matlab/GetAllFeatureNames.m",
    "content": "function [featureNamesLong,featureNamesShort] = GetAllFeatureNames(doCatch24)\n% Retrieve all feature names from featureList.txt\n\nif nargin < 1 || isempty(doCatch24)\n    doCatch24 = true;\nend\n%-------------------------------------------------------------------------------\n% Retrieve all (long) feature names from featureList.txt\nfid = fopen('../featureList.txt','r');\nformatSpec = '%s%s';\ndataIn = textscan(fid,formatSpec,'CommentStyle','#','EndOfLine','\\r\\n','CollectOutput',true);\nfclose(fid);\ndataIn = dataIn{1}; % Collect one big matrix of cells\nfeatureNamesLong = dataIn(:,1);\nfeatureNamesShort = dataIn(:,2);\n\n%-------------------------------------------------------------------------------\n% Filter out the two extra features: 'DN_Mean' and 'DN_Spread_Std'\nisMeanStd = strcmp(featureNamesLong,'DN_Mean') | strcmp(featureNamesLong,'DN_Spread_Std');\nassert(sum(isMeanStd) == 2)\nif ~doCatch24\n    keepMe = ~isMeanStd;\n    featureNamesLong = featureNamesLong(keepMe);\n    featureNamesShort = featureNamesShort(keepMe);\n    fprintf(1,'Using catch22.\\n');\nelse\n    fprintf(1,'Using catch24.\\n');\nend\n\nend\n"
  },
  {
    "path": "wrap_Matlab/M_wrapper.c",
    "content": "#include \"mex.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid M_wrapper_double( int nlhs, mxArray *plhs[], \n    int nrhs, const mxArray*prhs[], \n    double (*f) (const double*, const int), int normalize )\n     \n{ \n    double *inMatrix;       /* 1xN input matrix */\n    int ncols;\n    double *outMatrix; /* output matrix */\n    \n    // check inputs\n    if(nrhs != 1) {\n        mexErrMsgIdAndTxt(\"catch22:nrhs\",\n                          \"One input required.\");\n    }\n    if(nlhs > 1) {\n        mexErrMsgIdAndTxt(\"catch22:nlhs\",\n                          \"One output required.\");\n    }\n    if( !mxIsDouble(prhs[0]) || \n        mxIsComplex(prhs[0])) {\n        mexErrMsgIdAndTxt(\"catch22:notDouble\",\n            \"Input vector must be type double.\");\n    }\n    if(mxGetM(prhs[0]) != 1) {\n        mexErrMsgIdAndTxt(\"catch22:notRowVector\",\n                          \"Input must be a row vector.\");\n    }\n    \n    // get input\n    inMatrix = mxGetPr(prhs[0]);\n    ncols = mxGetN(prhs[0]);\n    \n    // set output\n    plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);\n    outMatrix = mxGetPr(plhs[0]);\n    \n    // calculate result\n    if (normalize){\n        \n        double * y_zscored = malloc(ncols * sizeof * y_zscored);\n        zscore_norm2(inMatrix, ncols, y_zscored);\n\n        outMatrix[0] = f(y_zscored, ncols);\n\n        free(y_zscored);\n    } \n    else {\n        outMatrix[0] = f(inMatrix, ncols);\n    }   \n    \n    return;\n    \n}\n\nvoid M_wrapper_int( int nlhs, mxArray *plhs[], \n    int nrhs, const mxArray*prhs[], \n    int (*f) (const double*, const int), int normalize )\n     \n{ \n    double *inMatrix;       /* 1xN input matrix */\n    int ncols;\n    int *outMatrix; /* output matrix */\n    \n    // check inputs\n    if(nrhs != 1) {\n        mexErrMsgIdAndTxt(\"catch22:nrhs\",\n                          \"One input required.\");\n    }\n    if(nlhs > 1) {\n        mexErrMsgIdAndTxt(\"catch22:nlhs\",\n                          \"One output required.\");\n    }\n    if( !mxIsDouble(prhs[0]) || \n        mxIsComplex(prhs[0])) {\n        mexErrMsgIdAndTxt(\"catch22:notDouble\",\n            \"Input vector must be type double.\");\n    }\n    if(mxGetM(prhs[0]) != 1) {\n        mexErrMsgIdAndTxt(\"catch22:notRowVector\",\n                          \"Input must be a row vector.\");\n    }\n    \n    // get input\n    inMatrix = mxGetPr(prhs[0]);\n    ncols = mxGetN(prhs[0]);\n    \n    // set output\n    plhs[0] = mxCreateNumericMatrix(1,1, mxINT32_CLASS, mxREAL);\n    outMatrix = (int*)mxGetData(plhs[0]);\n    \n    // calculate result\n    if (normalize){\n        \n        double * y_zscored = malloc(ncols * sizeof * y_zscored);\n        zscore_norm2(inMatrix, ncols, y_zscored);\n\n        outMatrix[0] = f(y_zscored, ncols);\n\n        free(y_zscored);\n    } \n    else {\n        outMatrix[0] = f(inMatrix, ncols);\n    }   \n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/M_wrapper.h",
    "content": "#include \"mex.h\"\n\nextern void M_wrapper_double( int nlhs, mxArray *plhs[], \n    int nrhs, const mxArray*prhs[], \n    double (*f) (const double*, const int), int normalize );\n\nextern void M_wrapper_int( int nlhs, mxArray *plhs[], \n    int nrhs, const mxArray*prhs[], \n    int (*f) (const double*, const int), int normalize );"
  },
  {
    "path": "wrap_Matlab/catch22_CO_Embed2_Dist_tau_d_expfit_meandiff.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_Embed2_Dist_tau_d_expfit_meandiff, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_CO_FirstMin_ac.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[],\n      int nrhs, const mxArray*prhs[] )\n\n{\n\n    // check inputs and call feature C-function\nM_wrapper_int( nlhs, plhs, nrhs, prhs, &CO_FirstMin_ac, 1);\n\n    return;\n\n}\n"
  },
  {
    "path": "wrap_Matlab/catch22_CO_HistogramAMI_even_2_5.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_HistogramAMI_even_2_5, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_CO_f1ecac.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[],\n      int nrhs, const mxArray*prhs[] )\n\n{\n\n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_f1ecac, 1);\n\n    return;\n\n}\n"
  },
  {
    "path": "wrap_Matlab/catch22_CO_trev_1_num.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &CO_trev_1_num, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_DN_HistogramMode_10.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_HistogramMode_10, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_DN_HistogramMode_5.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_HistogramMode_5, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_DN_Mean.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_Mean, 0);\n    \n    return;\n    \n}\n"
  },
  {
    "path": "wrap_Matlab/catch22_DN_OutlierInclude_n_001_mdrmd.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_OutlierInclude_n_001_mdrmd, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_DN_OutlierInclude_p_001_mdrmd.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_OutlierInclude_p_001_mdrmd, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_DN_Spread_Std.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &DN_Spread_Std, 0);\n    \n    return;\n    \n}\n"
  },
  {
    "path": "wrap_Matlab/catch22_FC_LocalSimple_mean1_tauresrat.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &FC_LocalSimple_mean1_tauresrat, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_FC_LocalSimple_mean3_stderr.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &FC_LocalSimple_mean3_stderr, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_IN_AutoMutualInfoStats_40_gaussian_fmmi.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &IN_AutoMutualInfoStats_40_gaussian_fmmi, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_MD_hrv_classic_pnn40.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &MD_hrv_classic_pnn40, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_PD_PeriodicityWang_th0_01.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_int( nlhs, plhs, nrhs, prhs, &PD_PeriodicityWang_th0_01, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SB_BinaryStats_diff_longstretch0.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_BinaryStats_diff_longstretch0, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SB_BinaryStats_mean_longstretch1.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_BinaryStats_mean_longstretch1, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SB_MotifThree_quantile_hh.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_MotifThree_quantile_hh, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SB_TransitionMatrix_3ac_sumdiagcov.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SB_TransitionMatrix_3ac_sumdiagcov, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SC_FluctAnal_2_dfa_50_1_2_logi_prop_r1, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SC_FluctAnal_2_rsrangefit_50_1_logi_prop_r1, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SP_Summaries_welch_rect_area_5_1.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SP_Summaries_welch_rect_area_5_1, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_SP_Summaries_welch_rect_centroid.c",
    "content": "/*=================================================================\n *\n *\n *=================================================================*/\n#include <math.h>\n#include \"mex.h\"\n\n#include \"M_wrapper.h\"\n\n#include \"CO_AutoCorr.h\"\n#include \"DN_HistogramMode_10.h\"\n#include \"DN_HistogramMode_5.h\"\n#include \"DN_Mean.h\"\n#include \"DN_Spread_Std.h\"\n#include \"DN_OutlierInclude.h\"\n#include \"FC_LocalSimple.h\"\n#include \"IN_AutoMutualInfoStats.h\"\n#include \"MD_hrv.h\"\n#include \"PD_PeriodicityWang.h\"\n#include \"SB_BinaryStats.h\"\n#include \"SB_CoarseGrain.h\"\n#include \"SB_MotifThree.h\"\n#include \"SB_TransitionMatrix.h\"\n#include \"SC_FluctAnal.h\"\n#include \"SP_Summaries.h\"\n#include \"butterworth.h\"\n#include \"fft.h\"\n#include \"helper_functions.h\"\n#include \"histcounts.h\"\n#include \"splinefit.h\"\n#include \"stats.h\"\n\nvoid mexFunction( int nlhs, mxArray *plhs[], \n      int nrhs, const mxArray*prhs[] )\n     \n{ \n    \n    // check inputs and call feature C-function\nM_wrapper_double( nlhs, plhs, nrhs, prhs, &SP_Summaries_welch_rect_centroid, 1);\n    \n    return;\n    \n}"
  },
  {
    "path": "wrap_Matlab/catch22_all.m",
    "content": "function [featureValues, featureNamesLong, featureNamesShort] = catch22_all(data, doCatch24)\n% catch22_all   Calculate all catch22 (or catch24) features from an input time series\n%\n% ---INPUTS\n% data: a univariate time series (row vector)\n% catch24: set to true to also include mean and standard deviation (a total of 24\n%               features)\n% ---OUTPUTS:\n% featureValues: computed feature values for the input data\n\n%-------------------------------------------------------------------------------\n%% Check inputs and set defaults\n%-------------------------------------------------------------------------------\nif nargin < 2\n    doCatch24 = true;\nend\n\n%-------------------------------------------------------------------------------\n% Define the features:\n%-------------------------------------------------------------------------------\n[featureNamesLong,featureNamesShort] = GetAllFeatureNames(doCatch24);\n\n%-------------------------------------------------------------------------------\n% Compute all features from their local compiled implementations\n%-------------------------------------------------------------------------------\nnumFeatures = length(featureNamesLong);\nfeatureValues = zeros(numFeatures,1);\n\nfor featureInd = 1:numFeatures\n    featureName = featureNamesLong{featureInd};\n    fh = str2func(['catch22_', featureName]);\n    featureValues(featureInd) = fh(data');\nend\n\nend\n"
  },
  {
    "path": "wrap_Matlab/mexAll.m",
    "content": "% mexAll    Mex compile all .c files to be runnable from Matlab.\n\n% Path where the C implementation lives\nbasePath = '../C';\nipath = {['-I', basePath], '-I.'};\n\n% List all C files to include in the mex-call\nCFiles = dir(basePath);\nCFiles = CFiles(cellfun(@(x) contains(x, '.c'), {CFiles.name}));\nCFileNames = {CFiles.name};\n\n% Add path to the c file names\nincludeFiles = cellfun(@(x) fullfile(basePath, x), CFileNames, 'UniformOutput', false);\n\n% Get function names\nfeatureNames = GetAllFeatureNames(true);\n\n% mex all feature functions separately\nnumFeatures = length(featureNames);\nfor i = 1:numFeatures\n    featureName = featureNames{i};\n\n    fprintf('[%u/%u]: Compiling %s...\\n', i,numFeatures,featureName);\n    mex(ipath{:}, ['catch22_', featureName,'.c'], 'M_wrapper.c', includeFiles{:})\n    fprintf('\\n');\nend\n\nfprintf(1,'All done!\\n');\n"
  },
  {
    "path": "wrap_Matlab/testing.m",
    "content": "%-------------------------------------------------------------------------------\n% Get the function names\n[featureNamesLong,featureNamesShort] = GetAllFeatureNames();\nnumFeatures = length(featureNamesLong);\n\n%-------------------------------------------------------------------------------\n% Get the data\ndataFileNames = {'../testData/test.txt', '../testData/test2.txt'};\nnumTestFiles = length(dataFileNames);\n\nfprintf(1,'Testing %u compiled features on %u data files.\\n',numFeatures,numTestFiles);\n\n%-------------------------------------------------------------------------------\n% Test all functions on all the data files\nfor j = 1:numTestFiles\n\n    dataFileName = dataFileNames{j};\n    fprintf('\\n%s\\n\\n', dataFileName)\n\n    fileID = fopen(dataFileName,'r');\n    data = fscanf(fileID,'%f');\n\n    for featureInd = 1:numFeatures\n\n        featureName = featureNamesLong{featureInd};\n        fh = str2func(['catch22_', featureName]);\n        out = fh(data');\n\n        fprintf(\"%s (%s): %1.6f\\n\", featureNamesShort{featureInd}, featureName, out);\n    end\n\n    fclose(fileID);\nend\n"
  }
]