Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for sample entropy: last template vector of length M must be ignored #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CSchoel
Copy link

@CSchoel CSchoel commented Dec 28, 2019

@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 (ixjlyons/entro-py#2) and pyEntropy (nikdon/pyEntropy#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))
entro-py 0.27672305866206137
 pyentrp 0.2767230586620615
   pyeeg 0.27672305866206137
   nolds 0.2767230586620615

reason: this vector cannot be followed for the next time step and
therefore has no corresponding vector of length M+1
reference: Richman and Moorman (2000), page H2042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant