Skip to content

Commit

Permalink
Warn if symmetric soft-DTW is calculated through proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
asardaes committed Jul 5, 2024
1 parent b7295e4 commit b16581d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions R/DISTANCES-sdtw.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#' Cuturi, M., & Blondel, M. (2017). Soft-DTW: a Differentiable Loss Function for Time-Series. arXiv
#' preprint arXiv:1703.01541.
#'
sdtw <- function(x, y, gamma = 0.01, ..., error.check = TRUE)
{
sdtw <- function(x, y, gamma = 0.01, ..., error.check = TRUE) {
if (error.check) {
check_consistency(x, "ts")
check_consistency(y, "ts")
Expand Down Expand Up @@ -81,6 +80,8 @@ sdtw_proxy <- function(x, y = NULL, gamma = 0.01, ..., error.check = TRUE, pairw
class(D) <- "pairdist"
}
else if (symmetric) {
warning("The distance between a series and itself is not always 0 with soft-DTW,",
" and this will be hidden in the 'dist' object that only includes lower triangular values.")
dim(D) <- NULL
class(D) <- "dist"
attr(D, "Size") <- length(x)
Expand Down
3 changes: 2 additions & 1 deletion R/S4-SparseDistmat.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ SparseDistmat <- methods::setRefClass(
distmat_indices <<- .Call(C_SparseDistmatIndices__new,
nrow(distmat),
PACKAGE = "dtwclust")

sapply(1L:length(series), function(id) {
.Call(C_SparseDistmatIndices__getNewIndices,
distmat_indices, id, id, symmetric,
PACKAGE = "dtwclust")
})
# return

invisible(NULL)
}
)
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/integration/proxy.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ x <- data_reinterpolated[3L:8L]

test_that("Included proxy distances can be called and give expected dimensions.", {
for (distance in dtwclust:::distances_included) {
d <- proxy::dist(x, method = distance, window.size = 15L, sigma = 100, normalize = TRUE)
suppressWarnings(
d <- proxy::dist(x, method = distance, window.size = 15L, sigma = 100, normalize = TRUE)
)
expect_identical(dim(d), c(length(x), length(x)), info = paste(distance, "single-arg"))

d2 <- proxy::dist(x, x, method = distance, window.size = 15L, sigma = 100, normalize = TRUE)
Expand Down
8 changes: 5 additions & 3 deletions tests/testthat/system/comparisons.R
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,11 @@ test_that("Compare clusterings works for the minimum set with all possibilities.
score.clus = score_fun)
})

sdtwc_comparison <- compare_clusterings(data_subset, "h",
configs = cfgs_sdtwc, seed = 3290L,
score.clus = score_fun)
suppressWarnings(
sdtwc_comparison <- compare_clusterings(data_subset, "h",
configs = cfgs_sdtwc, seed = 3290L,
score.clus = score_fun)
)

## rds
all_comparisons$pick$object <- reset_nondeterministic(all_comparisons$pick$object)
Expand Down

0 comments on commit b16581d

Please sign in to comment.