inst/tests/test.kmedoids.R

test_that("Test that KMedoids function works properly", {
  
  # We create a database with two series, each one replicated 5 times: 

  x <- cumsum(rnorm(50))
  y <- sin(seq(0, pi, length.out=50))
  
  data <- rbind(x, x, x, x, x, y, y, y, y, y)
  classes <- c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)
  
  clustering <- KMedoids(data, k=2, classes, "euclidean")
  
  #Such easy database is always clustered perfectly F=1. 
  expect_equal(clustering$F, 1)
  
  #If we don't define a ground truth, we only get the clustering value
  clustering <- as.numeric(KMedoids(data, k=2, "euclidean"))
  expect_equal(clustering, classes)
  
  # LCSS is not a distance measure, but a similarity, so a different treatment
  # is necessary 
  clustering <- as.numeric(KMedoids(data, k=2, "lcss", epsilon=1))
  expect_equal(clustering, classes)


})

Try the TSdist package in your browser

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

TSdist documentation built on Aug. 31, 2022, 5:09 p.m.