asardaes / dtwclust

R Package for Time Series Clustering Along with Optimizations for DTW
https://cran.r-project.org/package=dtwclust
GNU General Public License v3.0
252 stars 29 forks source link

Specify step.pattern parameter in compare_clustering_configs #59

Closed marc-heinl closed 2 years ago

marc-heinl commented 2 years ago

Hello,

I would like to use the compare_clusterings() function with a pre-defined clustering setting. Therefore I use compare_cluster_configs respectively pdc_configs with dtw_basic as distance measure. To change step.pattern to dtw::symmetric1 for cluster-comparison I already tried to set the parameter within the dtw_basic list config e.g. dtw_basic = list(step.pattern = dtw::symmetric1) I also tried dtw_basic = list(step.pattern = "dtw::symmetric1") and dtw_basic = list(step.pattern = 1) None of this seems to work and I get different errors for each config.

If nothing is set and default step.pattern is used everything works fine.

I would appreciate any kind of help.

Here a clipping of my code:

daily_widw <- round(0.05*length(typedays_time_series))

clustering_cfg_typedays <- compare_clusterings_configs( 
  types = c("p", "h"),  
  k = 3L:6L,
  controls = list( 
    partitional = partitional_control(iter.max = 50L, symmetric = TRUE, nrep = 3),
    hierarchical = hierarchical_control(method='complete', symmetric = TRUE)    #complete linkage 
  ),
  distances = pdc_configs( 
    type ="distance",
    sbd = list(norm = "L2"),
    sbd = list(norm = "L2", znorm=TRUE),
    L2 = list(norm = "L2"),
    #5%
    dtw_basic = list(step.pattern = dtw::symmetric1, windows.size = daily_widw, norm = "L2"),
    #10%
    dtw_basic = list(step.pattern = dtw::symmetric1, windows.size = 2*daily_widw, norm = "L2"),
    share.config = c("p", "h")
  ),
  centroids = pdc_configs( 
    type = "centroid", 
    partitional = list(
      mean = list(norm = "L2"),
      pam = list(norm = "L2"),
      #5% windows for dba
      dba = list( windows.size = daily_widw, norm = "L2"),
      #10% windows for dba
      dba = list( windows.size = 2*daily_widw, norm = "L2"),
      shape = list(norm = "L2")
    ),
    hierarchical = list(
      default = list()
    )
  )
)
asardaes commented 2 years ago

Hm, it seems that's actually not possible at the moment... I never thought about that case. I think the best option would be to wrap the patterns in a list like this:

pdc_configs(
    type = "distance",
    dtw_basic = list(
        norm = c("L1", "L2"), # example
        step.pattern = list(dtw::symmetric1, dtw::symmetric2)
    )
)

But the current version of compare_clusterings will not be able to unlist that correctly, so I'll have to change the code a bit.

asardaes commented 2 years ago

I'll push an update to CRAN shortly, but if you can install from github, give it a try with list as I mentioned.

marc-heinl commented 2 years ago

I tried the new implemented functionallity with the list wrapper for step.pattern specification with dtw::symmetric1 and everything works just fine. Thank you again for the fast adjustment!