Skip to content

Commit 76bf7ca

Browse files
Datseriskahaaga
andauthored
Fix some bugs (#244)
* fix diversity * spatial dispersion tests fail * test for correct error exception * up version * add a docs comment that entropies are c omplexity measures * Add test case for pre-symbolised version This would have caught the error for `entropy_normalized` at the correct level as described in ##244 * Simplify tests. No need to round. * Correctly propagate user-specified `L` to `outcome_space` * mass rename `ComplexityEstimator` from `ComplexityMeasure` * document better Complkextiy Estimator * fix and test symbolicperm with views Co-authored-by: Kristian Haaga <[email protected]>
1 parent f5e389d commit 76bf7ca

File tree

17 files changed

+75
-43
lines changed

17 files changed

+75
-43
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "ComplexityMeasures"
22
uuid = "ab4b797d-85ee-42ba-b621-05d793b346a2"
33
authors = "Kristian Agasøster Haaga <[email protected]>, George Datseries <[email protected]>"
44
repo = "https://github.com/juliadynamics/ComplexityMeasures.jl.git"
5-
version = "2.3.0"
5+
version = "2.3.1"
66

77
[deps]
88
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"

docs/src/complexity.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# Complexity measures
22

3+
In this page we document estimators for complexity measures that are not entropies in the strict mathematical sense. The API is almost identical to [`entropy`](@ref) and is defined by:
4+
5+
- [`complexity`](@ref)
6+
- [`complexity_normalized`](@ref)
7+
- [`ComplexityEstimator`](@ref)
8+
39
## Complexiy measures API
10+
411
```@docs
512
complexity
613
complexity_normalized
14+
ComplexityEstimator
715
```
816

917
## Approximate entropy

docs/src/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Before exploring the features of ComplexityMeasures.jl, it is useful to read thr
1616
In these scientific literature, words like *probabilities*, *entropies*, and other *complexity measures* are used (and abused) in multiple contexts, and are often used interchangeably to describe similar concepts. The API and documentation of ComplexityMeasures.jl aim to clarify the meaning and usage of these words, and to provide simple ways to obtain probabilities, entropies, or other complexity measures
1717
from input data.
1818

19+
For ComplexityMeasures.jl _entropies are also complexity measures_, while sometimes a distinction is made so that "complexity measures" means anything beyond entropy. However we believe the general nonlinear dynamics community agrees with our take, as most papers that introduce different entropy flavors, call them complexity measures. Example: _"Permutation Entropy: A Natural Complexity Measure for Time Series"_ from Brandt and Pompe 2002.
20+
1921
### Probabilities
2022

2123
Entropies and other complexity measures are typically computed based on _probability

src/complexity.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1-
export ComplexityMeasure
1+
export ComplexityEstimator
22
export complexity
33
export complexity_normalized
44

55
"""
6-
ComplexityMeasure
6+
ComplexityEstimator
77
8-
Supertype for (entropy-like) complexity measures.
8+
Supertype for estimators for various complexity measures that are not entropies
9+
in the strict mathematical sense.
10+
See [`complexity`](@ref) for all available estimators.
911
"""
10-
abstract type ComplexityMeasure end
12+
abstract type ComplexityEstimator end
1113

1214
"""
13-
complexity(c::ComplexityMeasure, x)
15+
complexity(c::ComplexityEstimator, x)
1416
15-
Estimate the complexity measure `c` for [input data](@ref input_data) `x`, where `c` can
16-
be any of the following measures:
17+
Estimate a complexity measure according to `c`
18+
for [input data](@ref input_data) `x`, where `c` can
19+
be any of the following estimators:
1720
1821
- [`ReverseDispersion`](@ref).
1922
- [`ApproximateEntropy`](@ref).
2023
- [`SampleEntropy`](@ref).
2124
- [`MissingDispersionPatterns`](@ref).
2225
"""
23-
function complexity(c::C, x) where C <: ComplexityMeasure
26+
function complexity(c::C, x) where C <: ComplexityEstimator
2427
T = typeof(x)
2528
msg = "`complexity` not implemented for $C and input data of type $T."
2629
throw(ArgumentError(msg))
2730
end
2831

2932
"""
30-
complexity_normalized(c::ComplexityMeasure, x) → m ∈ [a, b]
33+
complexity_normalized(c::ComplexityEstimator, x) → m ∈ [a, b]
3134
3235
The same as [`complexity`](@ref), but the result is normalized to the interval `[a, b]`,
3336
where `[a, b]` depends on `c`.
3437
"""
35-
function complexity_normalized(c::C, x) where {C <: ComplexityMeasure}
38+
function complexity_normalized(c::C, x) where {C <: ComplexityEstimator}
3639
T = typeof(x)
3740
msg = "`complexity_normalized` not implemented for $C and input data of type $T."
3841
throw(ArgumentError(msg))

src/complexity_measures/approximate_entropy.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Statistics
66
export ApproximateEntropy
77

88
"""
9-
ApproximateEntropy <: ComplexityMeasure
9+
ApproximateEntropy <: ComplexityEstimator
1010
ApproximateEntropy([x]; r = 0.2std(x), kwargs...)
1111
1212
An estimator for the approximate entropy (ApEn; Pincus, 1991)[^Pincus1991] complexity
@@ -68,7 +68,7 @@ constructed from the input timeseries ``x(t)`` as
6868
[^Pincus1991]: Pincus, S. M. (1991). Approximate entropy as a measure of system complexity.
6969
Proceedings of the National Academy of Sciences, 88(6), 2297-2301.
7070
"""
71-
Base.@kwdef struct ApproximateEntropy{I, B, R} <: ComplexityMeasure
71+
Base.@kwdef struct ApproximateEntropy{I, B, R} <: ComplexityEstimator
7272
m::I = 2
7373
τ::I = 1
7474
base::B = MathConstants.e

src/complexity_measures/missing_dispersion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using ComplexityMeasures: total_outcomes, missing_outcomes
55
export MissingDispersionPatterns
66

77
"""
8-
MissingDispersionPatterns <: ComplexityMeasure
8+
MissingDispersionPatterns <: ComplexityEstimator
99
MissingDispersionPatterns(est = Dispersion())
1010
1111
An estimator for the number of missing dispersion patterns (``N_{MDP}``), a complexity
@@ -51,7 +51,7 @@ See also: [`Dispersion`](@ref), [`ReverseDispersion`](@ref), [`total_outcomes`](
5151
[^Zhou2022]: Zhou, Q., Shang, P., & Zhang, B. (2022). Using missing dispersion patterns
5252
to detect determinism and nonlinearity in time series data. Nonlinear Dynamics, 1-20.
5353
"""
54-
Base.@kwdef struct MissingDispersionPatterns{D} <: ComplexityMeasure
54+
Base.@kwdef struct MissingDispersionPatterns{D} <: ComplexityEstimator
5555
est::D = Dispersion()
5656
end
5757

src/complexity_measures/reverse_dispersion_entropy.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ComplexityMeasures: total_outcomes
44
export ReverseDispersion
55

66
"""
7-
ReverseDispersion <: ComplexityMeasure
7+
ReverseDispersion <: ComplexityEstimator
88
ReverseDispersion(; c = 3, m = 2, τ = 1, check_unique = true)
99
1010
Estimator for the reverse dispersion entropy complexity measure (Li et al., 2019)[^Li2019].
@@ -45,7 +45,7 @@ unique element, then a `InexactError` is thrown when trying to compute probabili
4545
[^Li2019]: Li, Y., Gao, X., & Wang, L. (2019). Reverse dispersion entropy: a new
4646
complexity measure for sensor signal. Sensors, 19(23), 5203.
4747
"""
48-
Base.@kwdef struct ReverseDispersion{S <: Encoding} <: ComplexityMeasure
48+
Base.@kwdef struct ReverseDispersion{S <: Encoding} <: ComplexityEstimator
4949
encoding::Type{S} = GaussianCDFEncoding # any encoding at accepts keyword `c`
5050
c::Int = 3 # The number of categories to map encoded values to.
5151
m::Int = 2

src/complexity_measures/sample_entropy.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export SampleEntropy
77
export entropy_sample
88

99
"""
10-
SampleEntropy([x]; r = 0.2std(x), kwargs...)
10+
SampleEntropy([x]; r = 0.2std(x), kwargs...) <: ComplexityEstimator
1111
1212
An estimator for the sample entropy complexity measure (Richman & Moorman,
1313
2000)[^Richman2000], used with [`complexity`](@ref) and [`complexity_normalized`](@ref).
@@ -20,7 +20,7 @@ The keyword argument `r` is mandatory if an input timeseries `x` is not provided
2020
should be determined from the input data, for example as some proportion of the
2121
standard deviation of the data.
2222
- `m::Int = 1`: The embedding dimension.
23-
- `τ::Int = `: The embedding lag.
23+
- `τ::Int = 1`: The embedding lag.
2424
2525
## Description
2626
@@ -67,7 +67,7 @@ See also: [`entropy_sample`](@ref).
6767
analysis using approximate entropy and sample entropy. American Journal of
6868
Physiology-Heart and Circulatory Physiology, 278(6), H2039-H2049.
6969
"""
70-
Base.@kwdef struct SampleEntropy{R} <: ComplexityMeasure
70+
Base.@kwdef struct SampleEntropy{R} <: ComplexityEstimator
7171
m::Int = 2
7272
τ::Int = 1
7373
r::R

src/deprecations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function entropy(e::EntropyDefinition, est::DiffEntropyEst, x)
77
end
88
end
99

10+
@deprecate ComplexityMeasure ComplexityEstimator
11+
1012
# From before 2.0:
1113
@deprecate TimeScaleMODWT WaveletOverlap
1214
function probabilities(x::Vector_or_Dataset, ε::Union{Real, Vector{<:Real}})

src/multiscale.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function multiscale_normalized end
3636
"""
3737
multiscale(alg::MultiScaleAlgorithm, e::EntropyDefinition, est::DiffEntropyEst, x; kwargs...)
3838
multiscale(alg::MultiScaleAlgorithm, e::EntropyDefinition, est::ProbabilitiesEstimator, x; kwargs...)
39-
multiscale(alg::MultiScaleAlgorithm, c::ComplexityMeasure, x::AbstractVector; kwargs...)
39+
multiscale(alg::MultiScaleAlgorithm, c::ComplexityEstimator, x::AbstractVector; kwargs...)
4040
4141
Compute the multi-scale entropy `e` with estimator `est`, or the complexity measure `c`,
4242
for timeseries `x`.
@@ -60,7 +60,7 @@ factor `1`, the original time series is considered.
6060
## Arguments
6161
6262
- `e::EntropyDefinition`. A valid [entropy type](@ref entropies), i.e. `Shannon()` or `Renyi()`.
63-
- `c::ComplexityMeasure`. A valid complexity measure, i.e. [`SampleEntropy`](@ref),
63+
- `c::ComplexityEstimator`. A valid complexity measure, i.e. [`SampleEntropy`](@ref),
6464
or [`ApproximateEntropy`](@ref).
6565
- `alg::MultiScaleAlgorithm`. A valid [multiscale algorithm](@ref multiscale_algorithms),
6666
i.e. `Regular()` or `Composite()`, which determines how down-sampling/coarse-graining

0 commit comments

Comments
 (0)