Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
update tests, checks version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ha0ye committed Oct 17, 2019
1 parent 894b6bb commit e3f2ad6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rEDM
Type: Package
Title: Applications of Empirical Dynamic Modeling from Time Series
Version: 0.7.4
Version: 0.7.5
Authors@R: c(person("Hao", "Ye", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-8630-1458")),
Expand Down
16 changes: 14 additions & 2 deletions R/block_GP.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,14 @@ block_gp <- function(block, lib = c(1, NROW(block)), pred = lib,
x_pred = x_pred, ...)

# compute stats for mean predictions
stats <- compute_stats(y_pred, out_gp$mean_pred)

if (silent)
{
suppressWarnings(stats <- compute_stats(y_pred, out_gp$mean_pred)
)
} else {
stats <- compute_stats(y_pred, out_gp$mean_pred)
}

# prepare output (default is param settings and stats)
out_df <- data.frame(embedding = paste(embedding, sep = "",
collapse = ", "),
Expand Down Expand Up @@ -473,6 +479,12 @@ compute_gp <- function(x_lib, y_lib,
K_lib_lib <- eta_scaled * exp(-phi ^ 2 * squared_dist_lib_lib)
Sigma <- K_lib_lib + v_e_scaled * diag(NROW(x_lib))

# error checking on Sigma
if (any(!is.finite(Sigma)) || !all(Sigma > 0))
{
stop("Distance matrix is not positive-definite; Is the input data degenerate?")
}

# cholesky algorithm from Rasmussen & Williams (2006, algorithm 2.1)
R <- chol(Sigma)
alpha <- backsolve(R, forwardsolve(t(R), y_lib - mean_y))
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test_10_tde_gp.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ test_that("tde_gp works on time series", {
attributes(output) <- attributes(output)[sort(names(attributes(output)))]
expect_equal(digest::digest(output), "5c59eef4c687a6bd589f72a64d35c5f8")
})


test_that("Error checking works", {
ts_1 <- rep.int(0, 30)
ts_2 <- sample(c(0, 1), 30, replace = TRUE)
ts_3 <- rep.int(1, 30)

expect_error(out_1 <- tde_gp(ts_1, E = 1:3),
"Distance matrix is not positive-definite; Is the input data degenerate?")
expect_error(out_2 <- tde_gp(ts_2, E = 1:3),
NA)
expect_error(out_3 <- tde_gp(ts_3, E = 1:3),
"Distance matrix is not positive-definite; Is the input data degenerate?")
})

0 comments on commit e3f2ad6

Please sign in to comment.