Skip to content

Commit

Permalink
entropy_sample: return phi in info dict
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Aug 31, 2023
1 parent 1570a10 commit a12ce58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
15 changes: 8 additions & 7 deletions neurokit2/complexity/entropy_multiscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,14 @@ def _entropy_multiscale(
# Get coarse-grained signal
coarse = complexity_coarsegraining(signal, scale=scale, method=coarsegraining)

# Get delay
delay = 1 # If non-overlapping
if coarsegraining in ["rolling", "interpolate"]:
delay = scale

# For 1D coarse-graining
if coarse.ndim == 1:
# Get delay
delay = 1 # If non-overlapping
if coarsegraining in ["rolling", "interpolate"]:
delay = scale

# Compute entropy
return algorithm(
coarse,
delay=delay,
Expand All @@ -414,7 +415,7 @@ def _entropy_multiscale(
[
algorithm(
coarse[i],
delay=delay,
delay=1,
dimension=dimension,
tolerance=tolerance,
**kwargs,
Expand All @@ -428,7 +429,7 @@ def _entropy_multiscale(
[
_phi(
coarse[i],
delay=delay,
delay=1,
dimension=dimension,
tolerance=tolerance,
approximate=False,
Expand Down
6 changes: 3 additions & 3 deletions neurokit2/complexity/entropy_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def entropy_sample(signal, delay=1, dimension=2, tolerance="sd", **kwargs):
}

# Compute phi
phi = _phi(
info["phi"], _ = _phi(
signal,
delay=delay,
dimension=dimension,
tolerance=info["Tolerance"],
approximate=False,
**kwargs
)[0]
)

return _phi_divide(phi), info
return _phi_divide(info["phi"]), info
4 changes: 2 additions & 2 deletions neurokit2/complexity/utils_complexity_coarsegraining.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ def complexity_coarsegraining(
raise ValueError("Unknown `method`: {}".format(method))

if show is True:
_complexity_show(signal[0:n], coarse, method=method)
_complexity_coarsegraining_show(signal[0:n], coarse, method=method)
return coarse


# =============================================================================
# Utils
# =============================================================================
def _complexity_show(signal, coarse, method="nonoverlapping"):
def _complexity_coarsegraining_show(signal, coarse, method="nonoverlapping"):
plt.plot(signal, linewidth=1.5)
if method == "nonoverlapping":
plt.plot(
Expand Down

0 comments on commit a12ce58

Please sign in to comment.