Skip to content

Commit 576b119

Browse files
heliosdrmDatseris
andauthored
Fix computation of trend according to #167 (#168)
* Fix computation of trend according to #167 * fix test result of trend * fix test results of trend * Update CHANGELOG.md * Update docstring of `trend` * Update CHANGELOG.md --------- Co-authored-by: George Datseris <[email protected]>
1 parent 363b8f6 commit 576b119

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## v2.1.0
44

5+
- Bugfix: computation of `trend` is changed to use balanced distance from diagonal [(#167)](https://github.com/JuliaDynamics/RecurrenceAnalysis.jl/issues/167)
6+
7+
58
Updated to StateSpaceSets.jl v2.
69

710
## v2.0.0

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RecurrenceAnalysis"
22
uuid = "639c3291-70d9-5ea2-8c5b-839eba1ee399"
33
repo = "https://github.com/JuliaDynamics/RecurrenceAnalysis.jl.git"
4-
version = "2.1.0"
4+
version = "2.1.1"
55

66
[deps]
77
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"

src/rqa/rqa.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ the trend will have a negative value.
220220
It is calculated as:
221221
222222
```math
223-
TREND = 10^3\\frac{\\sum_{d=\\tau}^{\\tilde{N}}\\delta[d]\\left(RR[d]-\\langle RR[d]\\rangle\\right)}{\\sum_{d=\\tau}^{\\tilde{N}}\\delta[d]^2}
223+
TREND = 10^3\\frac{\\sum_{d=1+\\tau}^{\\tilde{N}}\\delta[d]\\left(RR[d]-\\langle RR[d]\\rangle\\right)}{\\sum_{d=1+\\tau}^{\\tilde{N}}\\delta[d]^2}
224224
```
225225
226226
where ``RR[d]`` is the local recurrence rate of the diagonal ``d``,
227-
``\\delta[d]`` is a balanced measure of the distance between that diagonal and the LOI,
228-
``\\tau`` is the Theiler window (number of central diagonals that are excluded), and
229-
``\\tilde{N}`` is the number of the outmost diagonal that is included.
227+
``\\tau`` is the Theiler window (number of central diagonals that are excluded),
228+
``\\tilde{N}`` is the number of the outmost diagonal that is included, and
229+
``\\delta[d]`` is a balanced measure of the distance between that diagonal and the LOI
230+
equal to ``d-(\\tilde{N}+\\tau)/2``.
230231
231232
This parameter is expressed in units of variation recurrence rate every
232233
1000 data points, hence the factor ``10^3`` in the formula [1].
@@ -282,7 +283,7 @@ function _trend(rr_τ::Vector; theiler=1, border=10, kwargs...)::Float64
282283
numerator = denominator = 0.0
283284
mean_rr = mean(@view rr_τ[a:b])
284285
for d in a:b
285-
δ = d - b/2
286+
δ = d - (b+theiler)/2
286287
numerator += δ*(rr_τ[d] - mean_rr)
287288
denominator += δ*δ
288289
end

test/rqa_rna_analytic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ rmat = CrossRecurrenceMatrix(sparse(i,j,trues(length(i))), RecurrenceThreshold(0
6868
@test rqa_params[:Lmax] == 5
6969
@test rqa_params[:DIV] == 0.2
7070
@test rqa_params[:ENTR] 0.830 atol=0.001
71-
@test rqa_params[:TREND] -12.2 atol=0.1
71+
@test rqa_params[:TREND] -17.9 atol=0.1
7272
@test rqa_params[:LAM] == 1.0
7373
@test rqa_params[:TT] == 22/15
7474
@test rqa_params[:Vmax] == 3
@@ -114,7 +114,7 @@ rmat = CrossRecurrenceMatrix(sparse(i,j,trues(length(i))), RecurrenceThreshold(0
114114
@test rqa_params[:Lmax] == 5
115115
@test rqa_params[:DIV] == 0.2
116116
@test rqa_params[:ENTR] 0.500 atol=0.001
117-
@test rqa_params[:TREND] -12.2 atol=0.1
117+
@test rqa_params[:TREND] -17.9 atol=0.1
118118
@test rqa_params[:LAM] == 12/22
119119
@test rqa_params[:TT] == 12/5
120120
@test rqa_params[:Vmax] == 3

0 commit comments

Comments
 (0)