Skip to content

Commit e0bac8a

Browse files
authored
sssets v2 (#137)
* move to v2 * dont use `size` in docs * all tests pass * make changelog entry
1 parent 96e59ed commit e0bac8a

19 files changed

+82
-58
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.8
2+
3+
Updated to StateSpaceSets.jl v2: the name `Dataset` no longer exists.
4+
15
# v2.7 - Refactoring release
26

37
The package has also been updated to all new names used in DynamicalSystems.jl v3.0,

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DelayEmbeddings"
22
uuid = "5732040d-69e3-5649-938a-b6b4f237613f"
33
repo = "https://github.com/JuliaDynamics/DelayEmbeddings.jl.git"
4-
version = "2.7.4"
4+
version = "2.8.0"
55

66
[deps]
77
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
@@ -19,6 +19,6 @@ Distances = "0.10"
1919
Distributions = "0.25"
2020
Neighborhood = "0.2"
2121
Reexport = "1"
22-
StateSpaceSets = "1"
22+
StateSpaceSets = "2"
2323
StatsBase = "0.24, 0.32, 0.33, 0.34"
2424
julia = "1.5"

docs/src/separated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ for (i, method) in enumerate(["afnn", "fnn", "f1nn", "ifnn"])
6161
# as well as the automated output embedding
6262
𝒟, τ, E = optimal_separated_de(x, method; dmax)
6363
lines!(ax, 1:dmax, E; label = method, marker = :circle, color = Cycled(i))
64-
optimal_d = size(𝒟, 2)
64+
optimal_d = dimension(𝒟)
6565
## Scatter the optimal embedding dimension as a lager marker
6666
scatter!(ax, [optimal_d], [E[optimal_d]];
6767
color = Cycled(i), markersize = 30

docs/src/unified.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,17 @@ Random.seed!(1234)
145145
d1 = randn(1000)
146146
d2 = rand(1000)
147147
Tmax = 100
148-
dummy_set = Dataset(d1,d2)
148+
dummy_set = StateSpaceSet(d1,d2)
149149
150150
w1 = estimate_delay(d1, "mi_min")
151151
w2 = estimate_delay(d2, "mi_min")
152152
theiler = min(w1, w2)
153153
154-
Y_d, τ_vals_d, ts_vals_d, Ls_d , ε★_d = pecuzal_embedding(dummy_set; τs = 0:Tmax , w = theiler, econ = true)
154+
Y_d, τ_vals_d, ts_vals_d, Ls_d , ε★_d = pecuzal_embedding(
155+
dummy_set; τs = 0:Tmax , w = theiler, econ = true
156+
)
155157
156-
size(Y_d)
158+
(length(Y_d), dimension(Y_d))
157159
```
158160

159161
So, no (proper) embedding is done.

src/DelayEmbeddings.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ end DelayEmbeddings
1010
using Reexport
1111
@reexport using StateSpaceSets
1212

13+
# for backwards compatibility with SSSets.jl v1
14+
# TODO: Cleanup: go through the instances in the codebase
15+
# where `oldsize` is called: replace it with `size` if the
16+
# input is a `Matrix`, and with `dimension` if the input is a `StateSpaceSet`.
17+
oldsize(s::AbstractStateSpaceSet) = (length(s), dimension(s))
18+
oldsize(s) = size(s)
19+
oldsize(s, i::Int) = oldsize(s)[i]
20+
1321
include("embeddings/embed.jl")
1422
include("embeddings/genembed.jl")
1523
include("utils.jl")

src/separated_de/automated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using the *separated* approach of first finding an optimal (and constant) delay
88
time using [`estimate_delay`](@ref) with the given `dmethod`, and then an optimal
99
embedding dimension, by calculating an appropriate statistic for each dimension `d ∈ 1:dmax`.
1010
Return the embedding `𝒟`, the optimal delay time `τ`
11-
(the optimal embedding dimension `d` is just `size(𝒟, 2)`) and the actual
11+
(the optimal embedding dimension `d` is just `dimension(𝒟)`) and the actual
1212
statistic `E` used to estimate optimal `d`.
1313
1414
Notice that `E` is a function of the embedding dimension, which ranges from 1 to `dmax`.

src/unified_de/MDOP.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function mdop_embedding(Y::AbstractStateSpaceSet{D, T};
122122
τ_vals = Int64[0]
123123
ts_vals = Int64[]
124124
FNNs = Float64[]
125-
βS = fill(zeros(T, length(τs), size(Y,2)), 1, max_num_of_cycles)
125+
βS = fill(zeros(T, length(τs), oldsize(Y,2)), 1, max_num_of_cycles)
126126

127127
# loop over increasing embedding dimensions until some break criterion will
128128
# tell the loop to stop/break
@@ -179,13 +179,13 @@ function mdop_multivariate_embedding_cycle!(
179179
FNNs, fnn_thres, ts_vals, NNdist_old
180180
)
181181

182-
M = size(Ys,2)
183-
# in the 1st cycle we have to check all (size(Y,2)^2 combinations
182+
M = oldsize(Ys,2)
183+
# in the 1st cycle we have to check all (oldsize(Y,2)^2 combinations
184184
if counter == 1
185185
Y_act, NNdist_new = first_embedding_cycle_MDOP!(M, Ys, τs, w, τ_vals,
186186
ts_vals, βS, metric, FNNs, r)
187187

188-
# in all other cycles we just have to check (size(Y,2)) combinations
188+
# in all other cycles we just have to check (oldsize(Y,2)) combinations
189189
else
190190

191191
Y_act, NNdist_new = embedding_cycle_MDOP!(Y_act, counter, NNdist_old, M, Ys, τs, w,
@@ -281,7 +281,7 @@ corresponding to that maximum of maxima. In this first embedding cycle it also
281281
returns the time series number, which act as Y_act.
282282
"""
283283
function choose_optimal_tau1(βs::Array{T, 2}, M::Int) where {T}
284-
NN = size(βs,2)
284+
NN = oldsize(βs,2)
285285
maxis = zeros(T, NN)
286286
max_idx = zeros(Int, NN)
287287
for i = 1:NN
@@ -303,7 +303,7 @@ maxima. It returns the index of this maximum as well as the time series number
303303
corresponding to that maximum of maxima.
304304
"""
305305
function choose_optimal_tau2(βs::Array{T, 2}) where {T}
306-
NN = size(βs,2)
306+
NN = oldsize(βs,2)
307307
maxis = zeros(T, NN)
308308
max_idx = zeros(Int, NN)
309309
for i = 1:NN
@@ -413,7 +413,7 @@ considered in the computation of `L` (see [`uzal_cost`](@ref)). When this
413413
statistic reaches its global minimum the maximum delay value `τ_max` gets
414414
returned. When `s` is a multivariate `StateSpaceSet`, `τ_max` will becomputed for all
415415
timeseries of that StateSpaceSet and the maximum value will be returned. The returned
416-
`L`-statistic has size `(length(tw), size(s,2))`.
416+
`L`-statistic has size `(length(tw), oldsize(s,2))`.
417417
418418
[^Nichkawde2013]: Nichkawde, Chetan (2013). [Optimal state-space reconstruction using derivatives on projected manifold. Physical Review E 87, 022905](https://doi.org/10.1103/PhysRevE.87.022905).
419419
[^Uzal2011]: Uzal, L. C., Grinblat, G. L., Verdes, P. F. (2011). [Optimal reconstruction of dynamical systems: A noise amplification approach. Physical Review E 84, 016223](https://doi.org/10.1103/PhysRevE.84.016223).

src/unified_de/garcia_almeida.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function garcia_almeida_embedding(Y::AbstractStateSpaceSet{D, F}; τs = 0:50 , w
131131
τ_vals = Int64[0]
132132
ts_vals = Int64[1]
133133
FNNs = Float64[]
134-
NS = fill(zeros(F, length(τs), size(Y,2)), 1, max_num_of_cycles)
134+
NS = fill(zeros(F, length(τs), oldsize(Y,2)), 1, max_num_of_cycles)
135135

136136
# loop over increasing embedding dimensions until some break criterion will
137137
# tell the loop to stop/break
@@ -282,14 +282,14 @@ function garcia_multivariate_embedding_cycle!(
282282
FNNs, fnn_thres, ts_vals, NNdist_old
283283
)
284284

285-
M = size(Ys,2)
286-
# in the 1st cycle we have to check all (size(Y,2)^2 combinations
285+
M = oldsize(Ys,2)
286+
# in the 1st cycle we have to check all (oldsize(Y,2)^2 combinations
287287
if counter == 1
288288
Y_act, NNdist_new = first_embedding_cycle!(M, Ys, τs, r1, r2, T, w,
289289
metric, τ_vals, ts_vals,
290290
NS, FNNs)
291291

292-
# in all other cycles we just have to check (size(Y,2)) combinations
292+
# in all other cycles we just have to check (oldsize(Y,2)) combinations
293293
else
294294
Y_act, NNdist_new = embedding_cycle!(Y_act, M, counter, Ys, τs, r1, r2, T, w,
295295
metric, NNdist_old, τ_vals, ts_vals,
@@ -386,7 +386,7 @@ time series number corresponding to that 1st minimum of all 1st minima. In this
386386
first embedding cycle it also returns the time series number, which act as Y_act.
387387
"""
388388
function choose_optimal_tau1_garcia(Ns::Array{T, 2}, M::Int) where {T}
389-
NN = size(Ns,2)
389+
NN = oldsize(Ns,2)
390390
min_idx = zeros(Int, NN)
391391
for i = 1:NN
392392
# determine optimal tau value and minimum vals from all N-statistic's
@@ -408,7 +408,7 @@ of the N-statistics. It returns the index of this 1st minimum as well as the
408408
time series number corresponding to that 1st minimum of the 1st minima.
409409
"""
410410
function choose_optimal_tau2_garcia(Ns::Array{T, 2}) where {T}
411-
NN = size(Ns,2)
411+
NN = oldsize(Ns,2)
412412
min_idx = zeros(Int, NN)
413413
for i = 1:NN
414414
# determine optimal tau value and minimum vals from all N-statistic's

src/unified_de/pecora.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ function pecora(
252252
return all_ε★, all_Γ
253253
end
254254

255-
maxdimspan(s) = 1:size(s)[2]
256-
maxdimspan(s::AbstractVector) = 1
255+
maxdimspan(s) = 1:oldsize(s)[2]
256+
maxdimspan(s::AbstractVector{<:Real}) = 1
257257

258258
function continuity_per_timeseries(x::AbstractVector, ns, allNNidxs, delays, K, α, p)
259-
avrg_ε★ = zeros(size(delays))
259+
avrg_ε★ = zeros(oldsize(delays))
260260
Ks = [k for k in 8:K]
261261
δ_to_ε_amount = get_binomial_table(p, α; trial_range = length(Ks))
262262
for (ι, τ) in enumerate(delays) # Loop over the different delays
@@ -293,7 +293,7 @@ end
293293
# Undersampling statistic code
294294
##########################################################################################
295295
function undersampling_per_timeseries(x, vspace, ns, uidxs, udist, JS, delays, ρs)
296-
avrg_Γ = zeros(size(delays))
296+
avrg_Γ = zeros(oldsize(delays))
297297
for (ι, τ) in enumerate(delays) # loop over delay times
298298
println("τ = ")
299299
c = 0

src/unified_de/pecuzal.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function pecuzal_embedding(Y::StateSpaceSet{D, T}; τs = 0:50 , w::Int = 1,
161161
τ_vals = Int64[0]
162162
ts_vals = Int64[]
163163
Ls = Float64[]
164-
ε★s = fill(zeros(T, length(τs), size(Y,2)), 1, max_cycles)
164+
ε★s = fill(zeros(T, length(τs), oldsize(Y,2)), 1, max_cycles)
165165

166166
# loop over increasing embedding dimensions until some break criterion will
167167
# tell the loop to stop/break
@@ -223,13 +223,13 @@ function pecuzal_multivariate_embedding_cycle!(Y_act, flag::Bool,
223223
samplesize::Real, K::Int, α::Real, p::Real, KNN::Int, econ::Bool
224224
)
225225

226-
M = size(Ys,2)
227-
# in the 1st cycle we have to check all (size(Y,2)^2 combinations and pick
226+
M = oldsize(Ys,2)
227+
# in the 1st cycle we have to check all (oldsize(Y,2)^2 combinations and pick
228228
# the tau according to maximum L-statistic decrease)
229229
if counter == 1
230230
Y_act = first_embedding_cycle_pecuzal!(Ys, M, τs, w, samplesize, K,
231231
metric, α, p, KNN, τ_vals, ts_vals, Ls, ε★s, econ)
232-
# in all other cycles we just have to check (size(Y,2)) combinations and pick
232+
# in all other cycles we just have to check (oldsize(Y,2)) combinations and pick
233233
# the tau according to maximum L-statistic decrease
234234
else
235235
Y_act = embedding_cycle_pecuzal!(Y_act, Ys, counter, M, τs, w, samplesize,
@@ -257,6 +257,7 @@ function first_embedding_cycle_pecuzal!(Ys::StateSpaceSet{D, T}, M::Int, τs, w:
257257
ε★[:,1+(M*(ts-1)):M*ts], _ = pecora(Ys, (0,), (ts,); delays = τs,
258258
w = w, samplesize = samplesize, K = K, metric = metric,
259259
α = α, p = p, undersampling = false)
260+
260261
L_min[ts], L_min_idx[ts], idx[ts] = choose_right_embedding_params(
261262
ε★[:,1+(M*(ts-1)):M*ts], Ys[:,ts],
262263
Ys, τs, KNN, w, samplesize,
@@ -308,9 +309,9 @@ function choose_right_embedding_params!(ε★::AbstractMatrix, Y_act,
308309
Ls::Vector{T}, ε★s::AbstractMatrix, counter::Int, τs, KNN::Int,
309310
w::Int, samplesize::Real, metric, econ::Bool) where {D, T}
310311

311-
L_min_ = zeros(size(Ys,2))
312-
τ_idx = zeros(Int,size(Ys,2))
313-
for ts = 1:size(Ys,2)
312+
L_min_ = zeros(oldsize(Ys,2))
313+
τ_idx = zeros(Int,oldsize(Ys,2))
314+
for ts = 1:oldsize(Ys,2)
314315
# zero-padding of ⟨ε★⟩ in order to also cover τ=0 (important for the multivariate case)
315316
# get the L-statistic for each peak in ⟨ε★⟩ and take the one according to L_min
316317
L_trials_, max_idx_ = local_L_statistics(vec([0; ε★[:,ts]]), Y_act, Ys[:,ts],
@@ -336,9 +337,9 @@ the chosen peak `τ_idx` and the number of the chosen time series to start with
336337
function choose_right_embedding_params(ε★::AbstractMatrix, Y_act,
337338
Ys::StateSpaceSet{D, T}, τs, KNN::Int, w::Int, samplesize::Real, metric,
338339
econ::Bool) where {D, T}
339-
L_min_ = zeros(size(Ys,2))
340-
τ_idx = zeros(Int,size(Ys,2))
341-
for ts = 1:size(Ys,2)
340+
L_min_ = zeros(oldsize(Ys,2))
341+
τ_idx = zeros(Int,oldsize(Ys,2))
342+
for ts = 1:oldsize(Ys,2)
342343
# zero-padding of ⟨ε★⟩ in order to also cover τ=0 (important for the multivariate case)
343344
# get the L-statistic for each peak in ⟨ε★⟩ and take the one according to L_min
344345
L_trials_, max_idx_ = local_L_statistics(vec([0; ε★[:,ts]]), StateSpaceSet(Y_act), Ys[:,ts],
@@ -585,7 +586,7 @@ function comp_Ek2!(ϵ_ball::Array{P, 2}, u_k::Vector{P}, Y::StateSpaceSet{D, P},
585586
end
586587

587588
# compute center of mass
588-
@inbounds for i in 1:size(Y)[2]; u_k[i] = sum(view(ϵ_ball, :, i))/(K+1); end # Eq. 14
589+
@inbounds for i in 1:oldsize(Y)[2]; u_k[i] = sum(view(ϵ_ball, :, i))/(K+1); end # Eq. 14
589590

590591
E²_sum = 0
591592
@inbounds for j = 1:K+1

0 commit comments

Comments
 (0)