Replace Python for-loop implementations of ap_entropy, samp_entropy with faster numpy-based implementations: a 3-dimensional array is created which stores the differences between the corresponding entries of each subsequence, and the number of "in range" sequences can be computed easily by aggregating the entries of this array.
Timing example:
np.random.seed(0); x = np.cumsum(np.random.normal(size=10000))
%time pyeeg.ap_entropy_new(x, 3, np.std(x)/5.) # optimized version
CPU times: user 9.45 s, sys: 3.33 s, total: 12.8 s
Wall time: 12.9 s
Out: 0.033903800117190248
%time pyeeg.ap_entropy_old(x, 3, np.std(x)/5.) # pure Python version
CPU times: user 1min 28s, sys: 385 ms, total: 1min 29s
Wall time: 1min 29s
Out: 0.033903800117190248
Also fixes a couple of off-by-1 errors in computing Cm and Cmp (the numbers of "in range" subsequences); the actual values will be (negligibly) different from the old ones, but code to produce exactly the same results is included (but commented out by default).
Replace Python for-loop implementations of ap_entropy, samp_entropy with faster numpy-based implementations: a 3-dimensional array is created which stores the differences between the corresponding entries of each subsequence, and the number of "in range" sequences can be computed easily by aggregating the entries of this array.
Timing example:
Also fixes a couple of off-by-1 errors in computing
Cm
andCmp
(the numbers of "in range" subsequences); the actual values will be (negligibly) different from the old ones, but code to produce exactly the same results is included (but commented out by default).