Skip to content

Commit

Permalink
rqa can return an AbstractDict object. (#127)
Browse files Browse the repository at this point in the history
* `rqa` can return an `AbstractDict` object.

* `rqa` can return an `AbstractDict` object.

* Added info on `AbstractDict` to `rqa` docs
  • Loading branch information
rs7q5 authored Dec 6, 2021
1 parent 9273f9e commit f7819df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RecurrenceAnalysis"
uuid = "639c3291-70d9-5ea2-8c5b-839eba1ee399"
repo = "https://github.com/JuliaDynamics/RecurrenceAnalysis.jl.git"
version = "1.6.2"
version = "1.6.3"

[deps]
DelayEmbeddings = "5732040d-69e3-5649-938a-b6b4f237613f"
Expand All @@ -24,6 +24,7 @@ UnicodePlots = "0.3, 1, 2"
julia = "1.5"

[extras]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DynamicalSystemsBase = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -32,4 +33,4 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Statistics", "Test", "SparseArrays", "Random", "DynamicalSystemsBase", "LightGraphs"]
test = ["Statistics", "Test", "SparseArrays", "Random", "DynamicalSystemsBase", "LightGraphs","DataStructures"]
8 changes: 4 additions & 4 deletions src/rqa/rqa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ in order to replicate the output of different versions:
* `rqa(NamedTuple, R...)` to obtain the output of the older version (as in 1.3).
* `rqa(Dict, R...)` to obtain the output of the planned future version.
* `rqa(RQA, R...)` to obtain the default current output (same as `rqa(R...)`)
* `rqa(DT,R...)` to obtain the output as `DT` which is a subtype of `AbstractDict` (e.g. `rqa(OrderedDict,R...)` returns an `OrderedDict`)
"""
rqa(R; kwargs...) = rqa(RQA, R; kwargs...)

Expand All @@ -479,15 +479,15 @@ function rqa(::Type{RQA}, R; kwargs...)
RQA(rqa_dict)
end

function rqa(::Type{Dict}, R; onlydiagonal=false, kwargs...)
function rqa(::Type{DT}, R; onlydiagonal=false, kwargs...) where {DT<:AbstractDict}
# Parse arguments for diagonal and vertical structures
kw_d = Dict(kwargs)
haskey(kw_d, :theilerdiag) && (kw_d[:theiler] = kw_d[:theilerdiag])
haskey(kw_d, :lmindiag) && (kw_d[:lmin] = kw_d[:lmindiag])
dhist = diagonalhistogram(R; kw_d...)
rr_d = recurrencerate(R; kw_d...)
if onlydiagonal
return Dict{Symbol, Float64}(
return DT{Symbol, Float64}(
:RR => recurrencerate(R; kwargs...),
:DET => _determinism(dhist, rr_d*_rrdenominator(R; kw_d...)),
:L => _dl_average(dhist),
Expand All @@ -501,7 +501,7 @@ function rqa(::Type{Dict}, R; onlydiagonal=false, kwargs...)
haskey(kw_v, :lminvert) && (kw_v[:lmin] = kw_v[:lminvert])
vhist, rthist = verticalhistograms(R; kw_v...)
rr_v = recurrencerate(R; kw_v...)
rqa_dict = Dict{Symbol, Float64}(
rqa_dict = DT{Symbol, Float64}(
:RR => rr_d,
:DET => _determinism(dhist, rr_d*_rrdenominator(R; kw_v...)),
:L => _dl_average(dhist),
Expand Down
7 changes: 6 additions & 1 deletion test/dynamicalsystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using RecurrenceAnalysis
using DynamicalSystemsBase, Random, Statistics, SparseArrays
using LightGraphs, LinearAlgebra
using Test

using DataStructures
RA = RecurrenceAnalysis

rng = Random.seed!(194)
Expand Down Expand Up @@ -140,4 +140,9 @@ dict_keys = ["Sine wave","White noise","Hénon (chaotic)","Hénon (periodic)"]
rc2 = coordinates(rmat.data)
@test isequal(rc1[1],rc2[1])
@test isequal(rc2[2],rc2[2])


@test isa(rqa(rmat.data).data,Dict)
@test isa(rqa(Dict,rmat.data),Dict)
@test isa(rqa(OrderedDict,rmat.data),OrderedDict)
end

0 comments on commit f7819df

Please sign in to comment.