Talk:Approximate entropy

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Interpretation[edit]

Removed parenthetical notation implying that "less predictable" and "more complex" are equivalent with respect to data sets describing measurements of processes. This is a highly contentious point within dynamical systems theory, and the comparison isn't doing any important work in the article, so it is better to simply not mention the issue. - RealityApologist (talk) 04:12, 11 January 2013 (UTC)[reply]

Algorithm[edit]

The algorithm from this article is different than the one cited (http://physionet.org/physiotools/ApEn/) but also different than one of Pincus' article (http://www.ncbi.nlm.nih.gov/pmc/articles/PMC51218/?page=3). I suspect the physionet one is the correct version.

The is also an inconsistency between the formula used for ApEn in the algorithm and the example. — Preceding unsigned comment added by 79.112.123.231 (talk) 20:17, 23 October 2013 (UTC)[reply]


Regarding the Python implementation[edit]

My opinion is that when NumPy has already been imported we should make better use of it. I suggest this

import numpy as np

def ApEn(U, m, r) -> float:
    """Approximate_entropy"""

    def _maxdist(x_i, x_j):

        return np.max(np.abs(np.array(x_i) - np.array(x_j)))

    def _phi(m):
        x = \
            [
                U[i:i+m]
                for i in range(N - m + 1)
            ]
        C = \
            [
                sum(
                    1
                    for x_j in x
                    if _maxdist(x_i, x_j) <= r
                )
                for x_i in x
            ]
        K = N - m + 1.0

        return np.sum(np.log(np.array(C)/K))/K

    N = len(U)

    return abs(_phi(m + 1) - _phi(m))

# Usage examples

U = np.array([ 85, 80, 89 ] * 17)
print(ApEn(U, 2, 3))
# 1.099654110658932e-05

randU = np.random.choice([ 85, 80, 89 ], size=17*3)
print(ApEn(randU, 2, 3))
# 0.8606697035181763

TorTheNorwegian (talk) 19:40, 28 October 2020 (UTC)[reply]


And here is a more compact version:

from itertools import product
import numpy as np

def ApEn(u, m, r) -> float:
    """Approximate_entropy"""

    n = len(u)

    def _maxdist(xi, xj):

        return np.max(np.abs(xi - xj))

    def _phi(m):
        k = n - m + 1
        x = [ np.array(u[i:i+m]) for i in range(k) ]
        d = np.array([ _maxdist(xi, xj) for xi, xj in product(x, x) ])
        c = (d < r).reshape(k, k).sum(axis=0)

        return np.sum(np.log(c/k))/k

    return abs(_phi(m + 1) - _phi(m))

# Usage examples

U = np.array([ 85, 80, 89 ] * 17)
print(ApEn(U, 2, 3))
# 1.099654110658932e-05

randU = np.random.choice([ 85, 80, 89 ], size=17*3)
print(ApEn(randU, 2, 3))
# 0.8657253438540384

TorTheNorwegian (talk) 02:08, 13 November 2020 (UTC)[reply]

Here is a version where sums of booleans are avoided:

from itertools import product
import numpy as np

def ApEn(u, m, r) -> float:
    """Approximate_entropy"""

    n = len(u)

    def _phi(m):
        k = n - m + 1
        x = [ np.array(u[i:i+m]) for i in range(k) ]
        d = np.array([ np.abs(xi - xj).max() for xi, xj in product(x, x) ])
        c = np.where(d < r, 1, 0).reshape(k, k).sum(axis=0)

        return np.sum(np.log(c/k))/k

    return abs(_phi(m + 1) - _phi(m))

# Usage examples

U = np.array([ 85, 80, 89 ] * 17)
print(ApEn(U, 2, 3))
# 1.0996541106811364e-05

randU = np.random.choice([ 85, 80, 89 ], size=17*3)
print(ApEn(randU, 2, 3))
# 0.8471275887269427

TorTheNorwegian (talk) 05:01, 13 November 2020 (UTC)[reply]

Final sentence[edit]

What does "it lacks relative consistency. That is, if ApEn of one data set is higher than that of another, it should, but does not, remain higher for all conditions tested." even mean? Could someone with knowledge of this topic rewrite this to be less confusing? Porphyro (talk) 14:06, 5 June 2017 (UTC)[reply]

Confusing[edit]

In "The Algorithm" section, step 4, "x" (without boldface) is used but not defined. Are they meant to be components of the (boldface) x-vectors? Or the x-vectors themselves? Furthermore, scalars u(a) are introduced, named exactly like those in Step 1, but without being the same. Also confusing. The notation and writing in this article looks amateurish and inconsistent. Jens olav nygaard (talk) 11:24, 18 May 2020 (UTC)[reply]

I agree that step 4 needs work. I've tidied up earlier steps and put a tag on step 4 so that others know where to start editing. Mebden (talk) 14:42, 18 February 2022 (UTC)[reply]
Not sure copyedit is the right tag, considering it's pretty much exclusively math-related. ★Ama TALK CONTRIBS 12:41, 25 April 2022 (UTC)[reply]
Hello, I've copyedited the requested section. Hopefully this new explanation is better!
As a side note, a math-specific copyedit tag would be nice, to distinguish between prose editing and markup / LaTeX editing. I don't know if one exists. It'd be helpful for both editors and readers requesting the edits. ~ Jayowyn (talk) 04:50, 25 November 2022 (UTC)[reply]