-
Notifications
You must be signed in to change notification settings - Fork 14
Dispersion and reverse dispersion probability estimators #96
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5e95521
Dispersion and reverse dispersion probability estimators
kahaaga 16c130d
Fix tests
kahaaga 1f1691f
ReverseDispersion should be a complexity measure, plus addressing som…
kahaaga 5816ef8
Export reverse_dispersion
kahaaga 5bab748
Reverse dispersion
kahaaga 44354ef
Remove reference to `ReverseDispersion`
kahaaga 394a4e7
Update docstring
kahaaga 3194f82
Add analytical tests
kahaaga 9900c81
Improve tests and add doc examples
kahaaga 97a4c3a
Fix tests
kahaaga 082a6a5
Better docs and doctests
kahaaga 6ac6983
Remove file
kahaaga 6b58635
Fix tests
kahaaga aea3a03
Update src/complexity_measures/reverse_dispersion_entropy.jl
kahaaga 9391e9f
Addressing review comments (#99)
kahaaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
# Complexity measures | ||
# [Complexity measures](@id complexity_measures) | ||
|
||
## Sample entropy | ||
|
||
## Approximate entropy | ||
|
||
## Reverse dispersion entropy | ||
|
||
```@docs | ||
reverse_dispersion | ||
distance_to_whitenoise | ||
``` | ||
|
||
## Disequilibrium |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include("reverse_dispersion_entropy.jl") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
export reverse_dispersion | ||
export distance_to_whitenoise | ||
|
||
# Note: this is not an entropy estimator, so we don't use the entropy_xxx_norm interface | ||
# for normalization, even though we rely on `alphabet_length`. | ||
""" | ||
distance_to_whitenoise(p::Probabilities, estimator::Dispersion; normalize = false) | ||
|
||
Compute the distance of the probability distribution `p` from a uniform distribution, | ||
given the parameters of `estimator` (which must be known beforehand). | ||
|
||
If `normalize == true`, then normalize the value to the interval `[0, 1]` by using the | ||
parameters of `estimator`. | ||
|
||
Used to compute reverse dispersion entropy([`reverse_dispersion`](@ref); | ||
Li et al., 2019[^Li2019]). | ||
|
||
[^Li2019]: Li, Y., Gao, X., & Wang, L. (2019). Reverse dispersion entropy: a new | ||
complexity measure for sensor signal. Sensors, 19(23), 5203. | ||
""" | ||
function distance_to_whitenoise(p::Probabilities, est::Dispersion; normalize = false) | ||
# We can safely skip non-occurring symbols, because they don't contribute | ||
# to the sum in eq. 3 in Li et al. (2019) | ||
Hrde = sum(abs2, p) - (1 / alphabet_length(est)) | ||
|
||
if normalize | ||
return Hrde / (1 - (1 / alphabet_length(est))) | ||
else | ||
return Hrde | ||
end | ||
end | ||
|
||
# Note again: this is a *complexity measure*, not an entropy estimator, so we don't use | ||
# the entropy_xxx_norm interface for normalization, even though we rely on `alphabet_length`. | ||
""" | ||
reverse_dispersion(x::AbstractVector{T}, est::Dispersion = Dispersion(); | ||
normalize = true) where T <: Real | ||
|
||
Compute the reverse dispersion entropy complexity measure (Li et al., 2019)[^Li2019]. | ||
|
||
## Description | ||
|
||
Li et al. (2021)[^Li2019] defines the reverse dispersion entropy as | ||
|
||
```math | ||
H_{rde} = \\sum_{i = 1}^{c^m} \\left(p_i - \\dfrac{1}{{c^m}} \\right)^2 = | ||
\\left( \\sum_{i=1}^{c^m} p_i^2 \\right) - \\dfrac{1}{c^{m}} | ||
``` | ||
where the probabilities ``p_i`` are obtained precisely as for the [`Dispersion`](@ref) | ||
probability estimator. Relative frequencies of dispersion patterns are computed using the | ||
given `symbolization` scheme , which defaults to symbolization using the normal cumulative | ||
distribution function (NCDF), as implemented by [`GaussianSymbolization`](@ref), using | ||
embedding dimension `m` and embedding delay `τ`. | ||
Recommended parameter values[^Li2018] are `m ∈ [2, 3]`, `τ = 1` for the embedding, and | ||
`c ∈ [3, 4, …, 8]` categories for the Gaussian mapping. | ||
|
||
If `normalize == true`, then the reverse dispersion entropy is normalized to `[0, 1]`. | ||
|
||
The minimum value of ``H_{rde}`` is zero and occurs precisely when the dispersion | ||
pattern distribution is flat, which occurs when all ``p_i``s are equal to ``1/c^m``. | ||
Because ``H_{rde} \\geq 0``, ``H_{rde}`` can therefore be said to be a measure of how far | ||
the dispersion pattern probability distribution is from white noise. | ||
|
||
[^Li2019]: Li, Y., Gao, X., & Wang, L. (2019). Reverse dispersion entropy: a new | ||
complexity measure for sensor signal. Sensors, 19(23), 5203. | ||
""" | ||
function reverse_dispersion(x::AbstractVector{T}, est::Dispersion = Dispersion(); | ||
normalize = true) where T <: Real | ||
|
||
p = probabilities(x, est) | ||
|
||
# The following step combines distance information with the probabilities, so | ||
# from here on, it is not possible to use `renyi_entropy` or similar methods, because | ||
# we're not dealing with probabilities anymore. | ||
Hrde = distance_to_whitenoise(p, est, normalize = normalize) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
reverse_dispersion
arguments are positional, here they are keyword. I'd say we stick with keyword.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, definitely. As I commented above, I unintentionally missed the semi-colon.