Skip to content

Commit

Permalink
Adds test data for twdtw-knn1
Browse files Browse the repository at this point in the history
  • Loading branch information
vwmaus committed Dec 26, 2023
1 parent 86fa83c commit d740a38
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# twdtw-1.1-0

* Implements twdtw-knn1

* Adds larger test set


# twdtw-1.0-1

* Fixes error:
Expand Down
Binary file added inst/sits/modis_mod13q1_999ts.rds
Binary file not shown.
Binary file added inst/sits/modis_mod13q1_patterns.rds
Binary file not shown.
Binary file added inst/sits/modis_mod13q1_results.rds
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/testthat/test-twdtw_knn1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ts_x <- readRDS(system.file("sits/modis_mod13q1_999ts.rds", package = "twdtw"))
ts_y <- readRDS(system.file("sits/modis_mod13q1_patterns.rds", package = "twdtw"))
expected_vector <- readRDS(system.file("sits/modis_mod13q1_results.rds", package = "twdtw"))

test_that("Nearest neighbor calculation is correct", {
# Compute TWDTW distances
distances <- sapply(ts_y[[2]], function(pattern) {
sapply(ts_x[[3]], function(ts) {
twdtw(x = as.data.frame(ts), y = as.data.frame(pattern), cycle_length = 'year', time_scale = 'day', time_weight = c(steepness = 0.1, midpoint = 50))
})
})

# Find the nearest neighbor for each observation in newdata
nearest_neighbor <- apply(distances, 1, which.min)

# Test if nearest_neighbor is equal to the expected vector
expect_equal(nearest_neighbor, expected_vector)
})


0 comments on commit d740a38

Please sign in to comment.