Skip to content

Commit fd2a5eb

Browse files
github-actions[bot]CompatHelper JuliaDatseris
authored
CompatHelper: bump compat for StateSpaceSets to 2, (keep existing compat) (#426)
* CompatHelper: bump compat for StateSpaceSets to 2, (keep existing compat) * use v2 exclusively * bump project version * fix approx entr argumenterror * make `codify` do what was promised * typing * fix doc compat * fix entropy sample problem (?) * stop rounding 0 to 0... * FIX DOCS ERROR --------- Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org> Co-authored-by: Datseris <datseris.george@gmail.com>
1 parent ba9849b commit fd2a5eb

File tree

11 files changed

+61
-68
lines changed

11 files changed

+61
-68
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
Changelog is kept with respect to version 0.11 of Entropies.jl. From version v2.0 onwards, this package has been renamed to ComplexityMeasures.jl.
44

5-
## 3.6
5+
## 3.7
6+
7+
- Updated to StateSpaceSets.jl v2.0
8+
- Fixed a bug in `codify` with `StateSpaceSet`. Now it does exactly as described in the docstring.
9+
10+
## 3.6
611

712
- New information measure: `FluctuationComplexity`.
813

Project.toml

Lines changed: 3 additions & 3 deletions
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 <kahaaga@gmail.com>, George Datseries <datseris.george@gmail.com>"
44
repo = "https://github.com/juliadynamics/ComplexityMeasures.jl.git"
5-
version = "3.6.6"
5+
version = "3.7.0"
66

77
[deps]
88
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
@@ -32,10 +32,10 @@ Neighborhood = "0.2.4"
3232
QuadGK = "2.9"
3333
Reexport = "1"
3434
SpecialFunctions = "0.10, 1.0, 2"
35-
StateSpaceSets = "1.0.4"
35+
StateSpaceSets = "2.1"
3636
StaticArrays = "0.12, 1.0"
3737
Statistics = "1"
3838
StatsBase = "0.33, 0.34"
3939
StatsFuns = "1.3"
40-
Wavelets = "0.10"
40+
Wavelets = "0.9, 0.10"
4141
julia = "1.5"

docs/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ TimeseriesSurrogates = "c804724b-8c18-5caa-8579-6025a0767c70"
2323

2424
[compat]
2525
DynamicalSystemsBase = "3"
26-
StateSpaceSets = "1"

docs/src/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ using CairoMakie
834834
N, a = 2000, 10
835835
t = LinRange(0, 2*a*π, N)
836836
837-
x = repeat([-5:5 |> collect; 4:-1:-4 |> collect], N ÷ 20);
837+
x = repeat([-5:5.0 |> collect; 4.0:-1:-4 |> collect], N ÷ 20);
838838
y = sin.(t .+ cos.(t/0.5));
839839
z = rand(N)
840840

src/complexity_measures/approximate_entropy.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ Base.@kwdef struct ApproximateEntropy{I, B, R} <: ComplexityEstimator
8282
end
8383
end
8484

85-
85+
function complexity(c::ApproximateEntropy, x::AbstractStateSpaceSet)
86+
throw(ArgumentError("Approximate entropy is only computable for timeseries."))
87+
end
8688

8789
function complexity(c::ApproximateEntropy, x::AbstractVector{T}) where T
8890
(; m, τ, r, base) = c

src/core/encodings.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ spaces preserve the input data length (e.g. [`UniqueElements`](@ref)), while
6969
some outcome spaces (e.g. [`OrdinalPatterns`](@ref)) do e.g. delay embeddings before
7070
encoding, so that `length(s) < length(x)`.
7171
"""
72-
function codify end
72+
function codify(o::OutcomeSpace, s::AbstractStateSpaceSet)
73+
return map(x -> codify(o, x), columns(s))
74+
end

src/outcome_spaces/cosine_similarity_binning.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ An alias to [`CosineSimilarityBinning`](@ref).
5050
const Diversity = CosineSimilarityBinning
5151

5252
function counts_and_outcomes(o::CosineSimilarityBinning, x::AbstractVector{T}) where T <: Real
53-
# Cosine similarities are all on [-1.0, 1.0], so just discretize this interval. To
54-
# do so, we call the `counts_and_outcomes(::RectangularBinEncoding, x)` in the file
53+
# Cosine similarities are all on [-1.0, 1.0], so just discretize this interval. To
54+
# do so, we call the `counts_and_outcomes(::RectangularBinEncoding, x)` in the file
5555
# `encoding_implementations/rectangular_binning.jl`.
5656
rbc::RectangularBinEncoding = encoding_for_diversity(o.nbins)
5757
cdists = cosine_similarity_distances(o, x)
@@ -87,7 +87,7 @@ function encoding_for_diversity(nbins::Int)
8787
return RectangularBinEncoding(binning)
8888
end
8989

90-
function codify(o::CosineSimilarityBinning, x::AbstractVector{T}) where T
90+
function codify(o::CosineSimilarityBinning, x::AbstractVector{<:Real})
9191
τs = 0:o.τ:(o.m - 1)*o.τ
9292
Y = genembed(x, τs)
9393
ds = zeros(Float64, length(Y) - 1)

src/outcome_spaces/ordinal_patterns.jl

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,18 @@ is_counting_based(o::AmplitudeAwareOrdinalPatterns) = false
200200
function OrdinalPatterns{m}= 1, lt = isless_rand; kwargs...) where {m}
201201
if haskey(kwargs, )
202202
msg = "Keyword argument `τ` to `OrdinalPatterns` is deprecated. " *
203-
"The signature is now " *
204-
"`OrdinalPatterns{m}(τ = 1, lt::Function = ComplexityMeasures.isless_rand)`" *
205-
", so provide `τ` as a positional argument instead. " *
203+
"The signature is now " *
204+
"`OrdinalPatterns{m}(τ = 1, lt::Function = ComplexityMeasures.isless_rand)`" *
205+
", so provide `τ` as a positional argument instead. " *
206206
"In this call, the given keyword `τ` is used instead of the positional `τ`."
207207
@warn msg
208208
τ = kwargs[]
209209
end
210210
if haskey(kwargs, :lt)
211211
msg = "Keyword argument `lt` to `OrdinalPatterns` is deprecated. " *
212-
"The signature is now " *
213-
"`OrdinalPatterns{m}(τ = 1, lt::Function = ComplexityMeasures.isless_rand)`" *
214-
", so provide `lt` as a positional argument instead. " *
212+
"The signature is now " *
213+
"`OrdinalPatterns{m}(τ = 1, lt::Function = ComplexityMeasures.isless_rand)`" *
214+
", so provide `lt` as a positional argument instead. " *
215215
"In this call, the given keyword `lt` is used instead of the positional `lt`."
216216
@warn msg
217217
lt = kwargs[:lt]
@@ -225,18 +225,18 @@ end
225225
function WeightedOrdinalPatterns{m}= 1, lt = isless_rand; kwargs...) where {m}
226226
if haskey(kwargs, )
227227
msg = "Keyword argument `τ` to `WeightedOrdinalPatterns` is deprecated. " *
228-
"The signature is now " *
229-
"`WeightedOrdinalPatterns{m}(τ::Int = 1, lt::F=ComplexityMeasures.isless_rand)`" *
230-
", so provide `τ` as a positional argument instead. " *
228+
"The signature is now " *
229+
"`WeightedOrdinalPatterns{m}(τ::Int = 1, lt::F=ComplexityMeasures.isless_rand)`" *
230+
", so provide `τ` as a positional argument instead. " *
231231
"In this call, the given keyword `τ` is used instead of the positional `τ`."
232232
@warn msg
233233
τ = kwargs[]
234234
end
235235
if haskey(kwargs, :lt)
236236
msg = "Keyword argument `lt` to `WeightedOrdinalPatterns` is deprecated. " *
237-
"The signature is now " *
238-
"`WeightedOrdinalPatterns{m}(τ = 1, lt::Function = ComplexityMeasures.isless_rand)`" *
239-
", so provide `lt` as a positional argument instead. " *
237+
"The signature is now " *
238+
"`WeightedOrdinalPatterns{m}(τ = 1, lt::Function = ComplexityMeasures.isless_rand)`" *
239+
", so provide `lt` as a positional argument instead. " *
240240
"In this call, the given keyword `lt` is used instead of the positional `lt`."
241241
@warn msg
242242
lt = kwargs[:lt]
@@ -248,38 +248,38 @@ function WeightedOrdinalPatterns{m}(τ = 1, lt = isless_rand; kwargs...) where {
248248
return WeightedOrdinalPatterns{m, F, I}(OrdinalPatternEncoding{m}(lt), τ)
249249
end
250250

251-
function AmplitudeAwareOrdinalPatterns{m}= 1, A = 0.5, lt = isless_rand;
251+
function AmplitudeAwareOrdinalPatterns{m}= 1, A = 0.5, lt = isless_rand;
252252
kwargs...) where {m}
253253
# because the order of the arguments is different from the other ordinal outcome spaces
254254
if A isa Function
255255
msg = "Second argument to `AmplitudeAwareOrdinalPatterns` must be a function. " *
256256
"Got a $(typeof(A)).";
257257
throw(ArgumentError(msg))
258258
end
259-
259+
260260
if haskey(kwargs, )
261261
msg = "Keyword argument `τ` to `AmplitudeAwareOrdinalPatterns` is deprecated. " *
262-
"The signature is now " *
263-
"`AmplitudeAwareOrdinalPatterns{m}(τ::Int = 1, A = 0.5, lt::F=isless_rand)`" *
264-
", so provide `τ` as a positional argument instead. " *
262+
"The signature is now " *
263+
"`AmplitudeAwareOrdinalPatterns{m}(τ::Int = 1, A = 0.5, lt::F=isless_rand)`" *
264+
", so provide `τ` as a positional argument instead. " *
265265
"In this call, the given keyword `τ` is used instead of the positional `τ`."
266266
@warn msg
267267
τ = kwargs[]
268268
end
269269
if haskey(kwargs, :lt)
270270
msg = "Keyword argument `lt` to `AmplitudeAwareOrdinalPatterns` is deprecated. " *
271-
"The signature is now " *
272-
"`AmplitudeAwareOrdinalPatterns{m}(τ::Int = 1, A = 0.5, lt::F=isless_rand)`" *
273-
", so provide `lt` as a positional argument instead. " *
271+
"The signature is now " *
272+
"`AmplitudeAwareOrdinalPatterns{m}(τ::Int = 1, A = 0.5, lt::F=isless_rand)`" *
273+
", so provide `lt` as a positional argument instead. " *
274274
"In this call, the given keyword `lt` is used instead of the positional `lt`."
275275
@warn msg
276276
lt = kwargs[:lt]
277277
end
278278
if haskey(kwargs, :A)
279279
msg = "Keyword argument `A` to `AmplitudeAwareOrdinalPatterns` is deprecated. " *
280-
"The signature is now " *
281-
"`AmplitudeAwareOrdinalPatterns{m}(τ::Int = 1, A = 0.5, lt::F=isless_rand)`" *
282-
", so provide `A` as a positional argument instead. " *
280+
"The signature is now " *
281+
"`AmplitudeAwareOrdinalPatterns{m}(τ::Int = 1, A = 0.5, lt::F=isless_rand)`" *
282+
", so provide `A` as a positional argument instead. " *
283283
"In this call, the given keyword `A` is used instead of the positional `A`."
284284
@warn msg
285285
A = kwargs[:A]
@@ -335,25 +335,9 @@ function fasthist!(πs::Vector{Int}, est::OrdinalOutcomeSpace{m}, x::AbstractSta
335335
return cts
336336
end
337337

338-
function codify(est::OrdinalOutcomeSpace{m}, x) where m
339-
if x isa AbstractVector
340-
dataset = embed(x, m, est.τ)
341-
elseif x isa AbstractStateSpaceSet && dimension(x) == 1
342-
err = "Convert your univariate time series to a subtype of `AbstractVector` to " *
343-
"codify with ordinal patterns! A `StateSpaceSet` input is assumed to be " *
344-
"already embedded in D = m >= 2 dimensional space."
345-
throw(ArgumentError(err))
346-
else
347-
dataset = x
348-
end
349-
m != dimension(dataset) && throw(ArgumentError(
350-
"Order of ordinal patterns and dimension of `StateSpaceSet` must match!"
351-
))
352-
πs = zeros(Int, length(dataset))
353-
@inbounds for (i, χ) in enumerate(dataset)
354-
πs[i] = encode(est.encoding, χ)
355-
end
356-
return πs
338+
function codify(o::OrdinalOutcomeSpace{m}, x::AbstractVector{<:Real}) where {m}
339+
emb = embed(x, m, o.τ).data
340+
return encode.(Ref(o.encoding), emb)
357341
end
358342

359343
# Special treatment for counting-based
@@ -448,8 +432,3 @@ Encode relative amplitude information of the elements of `a`.
448432
function AAPE(x, A::Real = 0.5, m::Int = length(x))
449433
(A/m)*sum(abs.(x)) + (1-A)/(m-1)*sum(abs.(diff(x)))
450434
end
451-
452-
function codify(o::OrdinalPatterns{m}, x::AbstractVector) where {m}
453-
emb = embed(x, m, o.τ).data
454-
return encode.(Ref(o.encoding), emb)
455-
end
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
using ComplexityMeasures
1+
using ComplexityMeasures, Test
2+
23
@test_throws UndefKeywordError SampleEntropy()
34

45
# Analytical examples seem to be lacking in the literature. As a next-best-test,
56
# we just check that we get a sample entropy sufficiently close to zero for a completely
67
# regular signal.
78
N = 6000
89
c = SampleEntropy(m = 2, τ = 1, r = 0.1)
9-
x = repeat([-5:5 |> collect; 4:-1:-4 |> collect], N ÷ 20);
10-
@test round(complexity(c, x), digits = 3) == round(0.0, digits = 3)
11-
@test round(complexity_normalized(c, x), digits = 3) == round(0.0, digits = 3)
10+
x = repeat([-5.0:5 |> collect; 4.0:-1:-4 |> collect], N ÷ 20);
11+
@test round(complexity(c, x), digits = 3) == 0.0
12+
@test round(complexity_normalized(c, x), digits = 3) == 0.0
1213

1314
# Conversely, a non-regular signal should result in a sample entropy
1415
# greater than zero.
1516
x = rand(N)
16-
@test round(complexity(c, x), digits = 2) > round(0.0, digits = 2)
17-
@test round(complexity_normalized(c, x), digits = 2) > round(0.0, digits = 2)
17+
@test round(complexity(c, x), digits = 2) > 0.0
18+
@test round(complexity_normalized(c, x), digits = 2) > 0.0
1819

1920
# Automatically deducing radius
20-
@test round(complexity(SampleEntropy(x, m = 2, τ = 1), x), digits = 2) > round(0.0, digits = 2)
21+
@test round(complexity(SampleEntropy(x, m = 2, τ = 1), x), digits = 2) > 0.0

test/outcome_spaces/implementations/permutation.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ end
9191
WeightedOrdinalPatterns, AmplitudeAwareOrdinalPatterns)
9292
# Codification of vector inputs (time series)
9393
x = rand(30)
94-
@test codify(S(), x) isa Vector{Int}
95-
@test_throws ArgumentError codify(S(),StateSpaceSet(x))
94+
y = rand(30)
95+
s = StateSpaceSet(x, y)
96+
c1 = codify(S(), x)
97+
@test c1 isa Vector{Int}
98+
out = codify(S(), s)
99+
@test out isa Tuple
100+
@test out[1] == c1
96101
end

0 commit comments

Comments
 (0)