@DominiqueMakowski called my attention to a discrepancy between this implementation of the sample entropy and my implementation in nolds in this issue: neuropsychology/NeuroKit#53 .
I think there is a small issue in pyeeg that causes this inconsistence: The sample entropy is the conditional probability that two pieces of the input sequence that are similar for M time steps will remain similar for M+1 time steps. If we count the number of similar template vector pairs of length M we therefore must ignore the last template vector, since it cannot be followed for another time step. If we would include it in the calculation, this would introduce a bias that underestimates the number of template vectors that remain similar for a length of M+1.
At Dominique's hint I found similar issues with entro-py (https://github.com/ixjlyons/entro-py/pull/2) and pyEntropy (https://github.com/nikdon/pyEntropy/pull/15). With the suggested fix in this pull request, pyeeg produces the same output as nolds and the R-package pracma (which I used as reference for the implementation of nolds), as well as the fixed versions of pyEntropy and entro-py,
import nolds
import entropy as e
import pyentrp.entropy as pent
import pyeeg.entropy as peeg
import numpy as np
num = 100
dim = 2
tol = 0.2
signal = np.cos(np.linspace(start=0, stop=30, num=num))
print("entro-py", e.sampen(signal, dim, tol, False))
print(" pyentrp", pent.sample_entropy(signal, dim + 1, tol)[-1])
print(" pyeeg", peeg.samp_entropy(signal, dim, tol))
print(" nolds", nolds.sampen(signal, emb_dim=dim, tolerance=tol))
@DominiqueMakowski called my attention to a discrepancy between this implementation of the sample entropy and my implementation in nolds in this issue: neuropsychology/NeuroKit#53 .
I think there is a small issue in pyeeg that causes this inconsistence: The sample entropy is the conditional probability that two pieces of the input sequence that are similar for M time steps will remain similar for M+1 time steps. If we count the number of similar template vector pairs of length M we therefore must ignore the last template vector, since it cannot be followed for another time step. If we would include it in the calculation, this would introduce a bias that underestimates the number of template vectors that remain similar for a length of M+1.
Reference: Richman and Moorman (2000), page H2042
At Dominique's hint I found similar issues with entro-py (https://github.com/ixjlyons/entro-py/pull/2) and pyEntropy (https://github.com/nikdon/pyEntropy/pull/15). With the suggested fix in this pull request, pyeeg produces the same output as nolds and the R-package pracma (which I used as reference for the implementation of nolds), as well as the fixed versions of pyEntropy and entro-py,