tests/testthat/test-03-acceptance-02-gak.R

# ==================================================================================================
# setup
# ==================================================================================================

## Original objects in env
ols <- ls()

# ==================================================================================================
# symmetric gak
# ==================================================================================================

test_that("Symmetric univariate GAK distance gives expected results.", {
    D1 <- proxy::dist(data_subset, method = "gak", window.size = 18L)
    sigma <- attr(D1, "sigma")
    D2 <- proxy::dist(data_subset, data_subset, method = "gak", window.size = 18L, sigma = sigma)
    D3 <- sapply(data_subset, GAK, y = data_subset[[1L]], window.size = 18L, sigma = sigma)

    expect_equal(as.matrix(D1), unclass(D2), info = "single-double-arg", ignore_attr = TRUE)
    expect_equal(c(0, D1[1L:(length(D3) - 1L)]), D3, info = "manual-vs-proxy", ignore_attr = TRUE)
})

test_that("Symmetric multivariate GAK distance gives expected results.", {
    D1 <- proxy::dist(data_multivariate, method = "gak", window.size = 18L)
    sigma <- attr(D1, "sigma")
    D2 <- proxy::dist(data_multivariate, data_multivariate, method = "gak", window.size = 18L, sigma = sigma)
    D3 <- sapply(data_multivariate, GAK, y = data_multivariate[[1L]], window.size = 18L, sigma = sigma)

    expect_equal(as.matrix(D1), unclass(D2), info = "single-double-arg", ignore_attr = TRUE)
    expect_equal(c(0, D1[1L:(length(D3) - 1L)]), D3, info = "manual-vs-proxy", ignore_attr = TRUE)
})

# ==================================================================================================
# clean
# ==================================================================================================

rm(list = setdiff(ls(), ols))

Try the dtwclust package in your browser

Any scripts or data that you put into this service are public.

dtwclust documentation built on Sept. 11, 2024, 9:07 p.m.