Skip to content

Commit 0db7b80

Browse files
authored
Export RT parameters and add them in rqa (#40)
use new function names and complete in @windowed extend tests
1 parent 22539b5 commit 0db7b80

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

src/RecurrenceAnalysis.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export embed,
2626
laminarity,
2727
trappingtime,
2828
maxvert,
29+
meanrecurrencetime,
30+
nmprt,
2931
rqa,
3032
sorteddistances,
3133
@windowed

src/rqa.jl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ nmprt(x::ARM; kwargs) = maximum(verticalhistograms(x; kwargs...)[2])
200200
rqa(x; kwargs...)
201201
202202
Calculate all RQA parameters of a recurrence matrix. See the functions
203-
`recurrencerate`, `determinism`, `dl_average`, `dl_max`, `divergence`, `dl_entropy`,
204-
`trend`, `laminarity`, `trappingtime` and `vl_max` for the definition of
203+
referred to below for the definition of
205204
the different parameters and the default values of the arguments.
206205
Using this function is much more efficient than calling all individual functions
207206
one by one.
@@ -214,16 +213,19 @@ structures.
214213
215214
The returned value is a dictionary with the following keys:
216215
217-
* "RR": recurrence rate (see `recurrencerate`)
218-
* "DET": determinsm (see `determinism`)
219-
* "L": average length of diagonal structures (see `dl_average`)
220-
* "Lmax": maximum length of diagonal structures (see `dl_max`)
221-
* "DIV": divergence (see `divergence`)
222-
* "ENTR": entropy of diagonal structures (see `dl_entropy`)
223-
* "TREND": trend of recurrences (see `trend`)
224-
* "LAM": laminarity (see `laminarity`)
225-
* "TT": trapping time (see `trappingtime`)
226-
* "Vmax": maximum length of vertical structures (`see `vl_max`)
216+
* "RR": recurrence rate (see [`recurrencerate`](@ref))
217+
* "DET": determinsm (see [`determinism`](@ref))
218+
* "L": average length of diagonal structures (see [`dl_average`](@ref))
219+
* "Lmax": maximum length of diagonal structures (see [`dl_max`](@ref))
220+
* "DIV": divergence (see [`divergence`](@ref))
221+
* "ENTR": entropy of diagonal structures (see [`dl_entropy`](@ref))
222+
* "TREND": trend of recurrences (see [`trend`](@ref))
223+
* "LAM": laminarity (see [`laminarity`](@ref))
224+
* "TT": trapping time (see [`trappingtime`](@ref))
225+
* "Vmax": maximum length of vertical structures (see [`vl_max`](@ref))
226+
* "MRT": mean recurrence time (see [`meanrecurrencetime`](@ref))
227+
* "RTE" recurrence time entropy (see [`rt_entropy`](@ref))
228+
* "NMPRT": number of the most probable recurrence time (see [`nmprt`](@ref))
227229
228230
The keyword argument `onlydiagonal` (`false` by default) can be set to `true`
229231
in order to restrict the analysis to the recurrence rate and the parameters related
@@ -248,18 +250,21 @@ function rqa(x; onlydiagonal=false, kwargs...)
248250
kw_v = Dict(kwargs)
249251
haskey(kw_v, :theilervert) && (kw_v[:theiler] = kw_v[:theilervert])
250252
haskey(kw_v, :lminvert) && (kw_v[:lmin] = kw_v[:lminvert])
251-
vhist = verticalhistograms(x; kw_v...)[1]
253+
vhist, rthist = verticalhistograms(x; kw_v...)
252254
rr_v = recurrencerate(x; kw_v...)
253255
return Dict("RR" => recurrencerate(x; kwargs...),
254256
"DET" => _determinism(dhist, rr_d*length(x)),
255257
"L" => _dl_average(dhist),
256258
"Lmax" => _dl_max(dhist),
257259
"DIV" => 1.0/_dl_max(dhist),
258260
"ENTR" => _dl_entropy(dhist),
259-
"TREND" => trend(x; kw_d...),
261+
"TREND" => trend(x; kw_d...),
260262
"LAM" => _laminarity(vhist, rr_v*length(x)),
261263
"TT" => _vl_average(vhist),
262-
"Vmax" => _vl_max(vhist)
264+
"Vmax" => _vl_max(vhist),
265+
"MRT" => _rt_average(rthist),
266+
"RTE" => _rt_entropy(rthist),
267+
"NMPRT" => maximum(rthist)
263268
)
264269
end
265270
end

src/windowed.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
const rqa_funs = [
22
:recurrencerate,
33
:determinism,
4-
:avgdiag,
5-
:maxdiag,
4+
:dl_average,
5+
:dl_max,
66
:divergence,
7-
:rqaentropy,
7+
:dl_entropy,
88
:trend,
99
:laminarity,
10+
:vl_average,
11+
:vl_max,
12+
:vl_entropy,
1013
:trappingtime,
11-
:maxvert
14+
:rt_average,
15+
:rt_max,
16+
:rt_entropy,
17+
:meanrecurrencetime,
18+
:nmprt
1219
]
1320

1421
const rqa_types = Dict(
@@ -155,7 +162,10 @@ macro windowed(ex, options...)
155162
"TREND" => zeros(Float64,ni),
156163
"LAM" => zeros(Float64,ni),
157164
"TT" => zeros(Float64,ni),
158-
"Vmax" => zeros(Int,ni)
165+
"Vmax" => zeros(Int,ni),
166+
"MRT" => zeros(Float64,ni),
167+
"RTE" => zeros(Float64,ni),
168+
"NMPRT" => zeros(Int,ni)
159169
)
160170
for i=1:ni
161171
local rqa_i = $ex

test/smallmatrix.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ rmat = CrossRecurrenceMatrix(sparse(i,j,trues(length(i))))
4545
@test rqa_params["LAM"] == 1.0
4646
@test rqa_params["TT"] == 33/23
4747
@test rqa_params["Vmax"] == 3
48+
@test rqa_params["MRT"] == 33/12
49+
@test rqa_params["RTE"] 1.286 atol=0.001
50+
@test rqa_params["NMPRT"] == 4
4851
end
4952
@testset "With Theiler window" begin
5053
histograms = recurrencestructures(rmat, theiler=2)
@@ -64,6 +67,9 @@ rmat = CrossRecurrenceMatrix(sparse(i,j,trues(length(i))))
6467
@test rqa_params["LAM"] == 1.0
6568
@test rqa_params["TT"] == 22/15
6669
@test rqa_params["Vmax"] == 3
70+
@test rqa_params["MRT"] == 24/6
71+
@test rqa_params["RTE"] 1.011 atol=0.001
72+
@test rqa_params["NMPRT"] == 3
6773
end
6874
@testset "With minimum line" begin
6975
histograms = recurrencestructures(rmat, lmin=2)
@@ -83,6 +89,9 @@ rmat = CrossRecurrenceMatrix(sparse(i,j,trues(length(i))))
8389
@test rqa_params["LAM"] == 18/33
8490
@test rqa_params["TT"] == 18/8
8591
@test rqa_params["Vmax"] == 3
92+
@test rqa_params["MRT"] == 15/3
93+
@test rqa_params["RTE"] 0.637 atol=0.001
94+
@test rqa_params["NMPRT"] == 2
8695
end
8796
@testset "Theiler and minimum line" begin
8897
histograms = recurrencestructures(rmat, theiler=2, lmin=2)
@@ -102,6 +111,9 @@ rmat = CrossRecurrenceMatrix(sparse(i,j,trues(length(i))))
102111
@test rqa_params["LAM"] == 12/22
103112
@test rqa_params["TT"] == 12/5
104113
@test rqa_params["Vmax"] == 3
114+
@test rqa_params["MRT"] == 7.0
115+
@test rqa_params["RTE"] 0.0 atol=0.001
116+
@test rqa_params["NMPRT"] == 1
105117
end
106118
end
107119

0 commit comments

Comments
 (0)