All problems
Sample Entropy Small
Problem
Compute sample entropy with embedding dimension m and tolerance r, excluding self-matches: SampEn = -ln(A / B), where B is the number of matching template pairs of length m and A the number of matching pairs of length m+1, using Chebyshev distance <= r.
Return 0.0 if m < 1, the series is shorter than m + 2, or either count is zero.
Hint
SampEn increases when longer patterns stop repeating.
Test cases
case 1
in: [[1,2,1,2,1,2],2,0]
expected: 0.6931471805599453
case 2
in: [[3,3,3,3,3],2,0]
expected: 1.0986122886681098
case 3
in: [[1,2,3,4,5,6],1,1]
expected: 0.2876820724517809
case 4
in: [[1,2,1,2,1,2,1,2],2,0]
expected: 0.40546510810816444
Starter codePython
import math
def sample_entropy(series, m, r):
# Your code here
pass4 test cases · run your code against them in the editor