-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken argument in windowed function (#150)
* Fix broken argument in windowed function Hopefully this one fixes both the function and the associated docs * Revert formatting * Replace all SparseMatrixCSC with AbstractMatrix * Remove more SparseMatrixCSC * Added condition for recurrence counts depending on a type of argument * Removed views from windowed function * SparseMatrix to SparseMatrixCSC * A small fix to how windowing works * Added some argtype declarations * A couple of sanity checks * Some more argtype declaration * Tests for windowed function * 2.0.4 => 2.0.5
- Loading branch information
1 parent
3bf94b5
commit 918167a
Showing
6 changed files
with
78 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
""" | ||
windowed(rmat, f, windth, step = 1; kwargs...) | ||
windowed(rmat, f, width, step = 1; kwargs...) | ||
A convenience function that applies the RQA function `f`, such as `determinism`, | ||
to windowed views of the given recurrence matrix `rmat` with given window `width` | ||
and `step`. The `kwargs...` are propagated to the call `f(rmat_view; kwargs...)`. | ||
""" | ||
function windowed(rmat, f, windth, step = 1; kwargs...) | ||
windows = 1:step:(size(rmat, 1)-width) | ||
map(1:length(windows)) do i | ||
rmat_view = view( | ||
rmat, | ||
windows[i]:(windows[i]+width), | ||
windows[i]:(windows[i]+width) | ||
) | ||
f(rmat_view; kwargs...) | ||
end | ||
end | ||
|
||
function windowed(rmat::Union{ARM,AbstractMatrix}, f::Function, width::Integer, step=1::Integer; kwargs...) | ||
(width < 2) && throw(ErrorException( | ||
"Window width must be must be greater than or equal to 2")) | ||
(step < 1) && throw(ErrorException( | ||
"Step size must be greater than or equal to 1")) | ||
windows = 1:step:(size(rmat, 1)-width+1) | ||
map(1:length(windows)) do i | ||
f(rmat[windows[i]:(windows[i]+width-1), windows[i]:(windows[i]+width-1)]; kwargs...) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using RecurrenceAnalysis, Test | ||
|
||
t = range(0, 2π; length = 300) # length is crucial and decides distance and thresholds | ||
c = cos.(t) | ||
s = sin.(t) | ||
X = StateSpaceSet(c, s) | ||
|
||
dmat = distancematrix(X) | ||
threshold = dmat[1, 2] + 0.01 # distance between two points | ||
|
||
@testset "window function" begin | ||
|
||
rec = RecurrenceMatrix(X, threshold) | ||
|
||
#classical | ||
|
||
@test length(windowed(rec, recurrencerate, 30, 30)) == 10 | ||
@test length(windowed(rec, determinism, 30, 30)) == 10 | ||
@test length(windowed(rec, dl_average, 30, 30)) == 10 | ||
@test length(windowed(rec, dl_max, 30, 30)) == 10 | ||
@test length(windowed(rec, dl_entropy, 30, 30)) == 10 | ||
@test length(windowed(rec, divergence, 30, 30)) == 10 | ||
@test length(windowed(rec, trend, 30, 30)) == 10 | ||
|
||
#extended | ||
|
||
@test length(windowed(rec, laminarity, 30, 30)) == 10 | ||
@test length(windowed(rec, trappingtime, 30, 30)) == 10 | ||
@test length(windowed(rec, vl_average, 30, 30)) == 10 | ||
@test length(windowed(rec, vl_max, 30, 30)) == 10 | ||
@test length(windowed(rec, vl_entropy, 30, 30)) == 10 | ||
|
||
#recurrence time | ||
|
||
@test length(windowed(rec, meanrecurrencetime, 30, 30)) == 10 | ||
@test length(windowed(rec, nmprt, 30, 30)) == 10 | ||
@test length(windowed(rec, rt_entropy, 30, 30)) == 10 | ||
@test length(windowed(rec, rt_average, 30, 30)) == 10 | ||
|
||
#check if reacts to changes in width and step | ||
@test length(windowed(rec, recurrencerate, 30, 1)) == 271 | ||
@test length(windowed(rec, recurrencerate, 10, 1)) == 291 | ||
end |