Skip to content

Commit

Permalink
Merge branch 'rqa'
Browse files Browse the repository at this point in the history
  • Loading branch information
constantino-garcia committed Apr 1, 2024
2 parents d95a8f4 + 394671b commit 41713b6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/RQA.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ getHistograms = function(neighs, ntakens, lmin, vmin){
# 2) sort
# 3) substract 1 to get C-like indexes for neighbors
cneighs = mapply(
function(ith_neighs, i) as.integer(sort(c(i, ith_neighs) - 1)),
function(ith_neighs, i) list(sort(as.integer(c(i, ith_neighs)) - 1)),
neighs,
seq_along(neighs)
)
Expand Down
28 changes: 27 additions & 1 deletion tests/testthat/test_rqa.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
library(nonlinearTseries)
context("RQA")

test_that("test rqa", {
test_that("empty RQA", {
ts = seq(0, 10)
ts_rqa = rqa(time.series = ts, embedding.dim = 2, time.lag = 1, radius = 0.1)
rmatrix = as.matrix(ts_rqa$recurrence.matrix)
expect_true(all(rmatrix == diag(ncol(rmatrix))))
expect_true(
all(head(ts_rqa$diagonalHistogram, -1) == 0)
)
})

test_that("full RQA", {
ts = seq(0, 10)
ts_rqa = rqa(time.series = ts, embedding.dim = 2, time.lag = 1, radius = 10,
lmin = 1)
rmatrix = as.matrix(ts_rqa$recurrence.matrix)
expect_true(all(rmatrix == 1))
# expected_diag = c(2,2,2,..., 1)
expected_diag = rep(2, ncol(rmatrix))
expected_diag[length(expected_diag)] = 1
expect_equal(ts_rqa$diagonalHistogram, expected_diag)
expected_vertical = rep(0, ncol(rmatrix))
expected_vertical[ncol(rmatrix)] = ncol(rmatrix)
expect_equal(ts_rqa$verticalHistogram, expected_vertical)
})


test_that("handmade RQA", {
skip_on_cran()
set.seed(1)
# Test 1
Expand Down

0 comments on commit 41713b6

Please sign in to comment.