From aace207fd461af02aea292c3d57b0392352a61c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Agas=C3=B8ster=20Haaga?= Date: Mon, 19 Sep 2022 14:38:47 +0200 Subject: [PATCH] WIP: reviewing new api (#95) * Equivalent to, not equivalent with * Include dispersion entropy * Clearer wording * Symbolization routines need to be imported before estimators using them * Export in-place version. * Follow Julia's linting conventions * Run CI on all pull requests * Don't export in-place version * Missing a letter --- .github/workflows/ci.yml | 1 + docs/src/index.md | 2 +- src/Entropies.jl | 4 ++-- src/entropies/entropies.jl | 4 +++- src/entropies/shannon.jl | 2 +- test/runtests.jl | 14 +++++++------- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7ee7bcbd..36d1b416f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ on: pull_request: branches: - main + - '**' # matches every branch push: branches: - main diff --git a/docs/src/index.md b/docs/src/index.md index 8f96cd1bf..3609dc576 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -50,4 +50,4 @@ The input data type typically depend on the probability estimator chosen. In gen - _Timeseries_, which are `AbstractVector{<:Real}`, used in e.g. with [`WaveletOverlap`](@ref). - _Multi-dimensional timeseries, or datasets, or state space sets_, which are `Dataset`, used e.g. with [`NaiveKernel`](@ref). -- _Spatial data_, which are higher dimensional standard `Array`, used e.g. with [`SpatialSymbolicPermutation`](@ref). +- _Spatial data_, which are higher dimensional standard `Array`s, used e.g. with [`SpatialSymbolicPermutation`](@ref). diff --git a/src/Entropies.jl b/src/Entropies.jl index 18e4b2625..a6af61930 100644 --- a/src/Entropies.jl +++ b/src/Entropies.jl @@ -1,7 +1,7 @@ """ A Julia package that provides estimators for probabilities, entropies, and complexity measures for timeseries, nonlinear dynamics and complex systems. -It can be used as standalone or part of several projects in the JuliaDynamics organization, +It can be used as a standalone package, or as part of several projects in the JuliaDynamics organization, such as [DynamicalSystems.jl](https://juliadynamics.github.io/DynamicalSystems.jl/dev/) or [CausalityTools.jl](https://juliadynamics.github.io/CausalityTools.jl/dev/). """ @@ -12,10 +12,10 @@ using DelayEmbeddings: AbstractDataset, Dataset, dimension export AbstractDataset, Dataset const Array_or_Dataset = Union{<:AbstractArray, <:AbstractDataset} +include("symbolization/symbolize.jl") include("probabilities.jl") include("probabilities_estimators/probabilities_estimators.jl") include("entropies/entropies.jl") -include("symbolization/symbolize.jl") include("deprecations.jl") diff --git a/src/entropies/entropies.jl b/src/entropies/entropies.jl index 291bf6ed9..8aa8f0a26 100644 --- a/src/entropies/entropies.jl +++ b/src/entropies/entropies.jl @@ -3,4 +3,6 @@ include("tsallis.jl") include("shannon.jl") include("convenience_definitions.jl") include("direct_entropies/nearest_neighbors/nearest_neighbors.jl") -# TODO: What else is included here from direct entropies? \ No newline at end of file +include("direct_entropies/entropy_dispersion.jl") + +# TODO: What else is included here from direct entropies? diff --git a/src/entropies/shannon.jl b/src/entropies/shannon.jl index b1a143aae..ee2a50350 100644 --- a/src/entropies/shannon.jl +++ b/src/entropies/shannon.jl @@ -2,7 +2,7 @@ export entropy_shannon """ entropy_shannon(args...; base = MathConstants.e) -Equivalent with `entropy_renyi(args...; base, q = 1)` and provided solely for convenience. +Equivalent to `entropy_renyi(args...; base, q = 1)` and provided solely for convenience. Compute the Shannon entropy, given by ```math H(p) = - \\sum_i p[i] \\log(p[i]) diff --git a/test/runtests.jl b/test/runtests.jl index e3b1d5827..5c8ab8585 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -158,16 +158,16 @@ end @test sum(p2) ≈ 1.0 # Entropies - @test entropy_renyi!(s, x, est, q = 1) ≈ 0 # Regular order-1 entropy - @test entropy_renyi!(s, y, est, q = 1) >= 0 # Regular order-1 entropy - @test entropy_renyi!(s, x, est, q = 2) ≈ 0 # Higher-order entropy - @test entropy_renyi!(s, y, est, q = 2) >= 0 # Higher-order entropy + @test Entropies.entropy_renyi!(s, x, est, q = 1) ≈ 0 # Regular order-1 entropy + @test Entropies.entropy_renyi!(s, y, est, q = 1) >= 0 # Regular order-1 entropy + @test Entropies.entropy_renyi!(s, x, est, q = 2) ≈ 0 # Higher-order entropy + @test Entropies.entropy_renyi!(s, y, est, q = 2) >= 0 # Higher-order entropy # For a time series sz = zeros(Int, N - (est.m-1)*est.τ) @test probabilities!(sz, z, est) isa Probabilities @test probabilities(z, est) isa Probabilities - @test entropy_renyi!(sz, z, est) isa Real + @test Entropies.entropy_renyi!(sz, z, est) isa Real @test entropy_renyi(z, est) isa Real end @@ -290,7 +290,7 @@ end RectangularBinning([0.2, 0.3, 0.3]) ] - @testset "Binning test $i" for i in 1:length(binnings) + @testset "Binning test $i" for i in eachindex(binnings) est = VisitationFrequency(binnings[i]) @test probabilities(D, est) isa Probabilities @test entropy_renyi(D, est, q=1, base = 3) isa Real # Regular order-1 entropy @@ -310,7 +310,7 @@ end RectangularBinning([0.2, 0.3, 0.3]) ] - @testset "Binning test $i" for i in 1:length(binnings) + @testset "Binning test $i" for i in eachindex(binnings) to = Entropies.transferoperator(D, binnings[i]) @test to isa Entropies.TransferOperatorApproximationRectangular