|
| 1 | +export reverse_dispersion |
| 2 | +export distance_to_whitenoise |
| 3 | + |
| 4 | +# Note: this is not an entropy estimator, so we don't use the entropy_xxx_norm interface |
| 5 | +# for normalization, even though we rely on `alphabet_length`. |
| 6 | +""" |
| 7 | + distance_to_whitenoise(p::Probabilities, estimator::Dispersion; normalize = false) |
| 8 | +
|
| 9 | +Compute the distance of the probability distribution `p` from a uniform distribution, |
| 10 | +given the parameters of `estimator` (which must be known beforehand). |
| 11 | +
|
| 12 | +If `normalize == true`, then normalize the value to the interval `[0, 1]` by using the |
| 13 | +parameters of `estimator`. |
| 14 | +
|
| 15 | +Used to compute reverse dispersion entropy([`reverse_dispersion`](@ref); |
| 16 | +Li et al., 2019[^Li2019]). |
| 17 | +
|
| 18 | +[^Li2019]: Li, Y., Gao, X., & Wang, L. (2019). Reverse dispersion entropy: a new |
| 19 | + complexity measure for sensor signal. Sensors, 19(23), 5203. |
| 20 | +""" |
| 21 | +function distance_to_whitenoise(p::Probabilities, est::Dispersion; normalize = false) |
| 22 | + # We can safely skip non-occurring symbols, because they don't contribute |
| 23 | + # to the sum in eq. 3 in Li et al. (2019) |
| 24 | + Hrde = sum(abs2, p) - (1 / alphabet_length(est)) |
| 25 | + |
| 26 | + if normalize |
| 27 | + return Hrde / (1 - (1 / alphabet_length(est))) |
| 28 | + else |
| 29 | + return Hrde |
| 30 | + end |
| 31 | +end |
| 32 | + |
| 33 | +# Note again: this is a *complexity measure*, not an entropy estimator, so we don't use |
| 34 | +# the entropy_xxx_norm interface for normalization, even though we rely on `alphabet_length`. |
| 35 | +""" |
| 36 | + reverse_dispersion(x::AbstractVector{T}, est::Dispersion = Dispersion(); |
| 37 | + normalize = true) where T <: Real |
| 38 | +
|
| 39 | +Compute the reverse dispersion entropy complexity measure (Li et al., 2019)[^Li2019]. |
| 40 | +
|
| 41 | +## Description |
| 42 | +
|
| 43 | +Li et al. (2021)[^Li2019] defines the reverse dispersion entropy as |
| 44 | +
|
| 45 | +```math |
| 46 | +H_{rde} = \\sum_{i = 1}^{c^m} \\left(p_i - \\dfrac{1}{{c^m}} \\right)^2 = |
| 47 | +\\left( \\sum_{i=1}^{c^m} p_i^2 \\right) - \\dfrac{1}{c^{m}} |
| 48 | +``` |
| 49 | +where the probabilities ``p_i`` are obtained precisely as for the [`Dispersion`](@ref) |
| 50 | +probability estimator. Relative frequencies of dispersion patterns are computed using the |
| 51 | +given `symbolization` scheme , which defaults to symbolization using the normal cumulative |
| 52 | +distribution function (NCDF), as implemented by [`GaussianSymbolization`](@ref), using |
| 53 | +embedding dimension `m` and embedding delay `τ`. |
| 54 | +Recommended parameter values[^Li2018] are `m ∈ [2, 3]`, `τ = 1` for the embedding, and |
| 55 | +`c ∈ [3, 4, …, 8]` categories for the Gaussian mapping. |
| 56 | +
|
| 57 | +If `normalize == true`, then the reverse dispersion entropy is normalized to `[0, 1]`. |
| 58 | +
|
| 59 | +The minimum value of ``H_{rde}`` is zero and occurs precisely when the dispersion |
| 60 | +pattern distribution is flat, which occurs when all ``p_i``s are equal to ``1/c^m``. |
| 61 | +Because ``H_{rde} \\geq 0``, ``H_{rde}`` can therefore be said to be a measure of how far |
| 62 | +the dispersion pattern probability distribution is from white noise. |
| 63 | +
|
| 64 | +[^Li2019]: Li, Y., Gao, X., & Wang, L. (2019). Reverse dispersion entropy: a new |
| 65 | + complexity measure for sensor signal. Sensors, 19(23), 5203. |
| 66 | +""" |
| 67 | +function reverse_dispersion(x::AbstractVector{T}, est::Dispersion = Dispersion(); |
| 68 | + normalize = true) where T <: Real |
| 69 | + |
| 70 | + p = probabilities(x, est) |
| 71 | + |
| 72 | + # The following step combines distance information with the probabilities, so |
| 73 | + # from here on, it is not possible to use `renyi_entropy` or similar methods, because |
| 74 | + # we're not dealing with probabilities anymore. |
| 75 | + Hrde = distance_to_whitenoise(p, est, normalize = normalize) |
| 76 | +end |
0 commit comments