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

Can't access distmat from tsclust results #72

Closed jmlammert closed 1 month ago

jmlammert commented 1 month ago

I am running the function "tsclust" on time series data and trying to access the computed distance matrix for later use in plots. An example of my code:

c <- tsclust(data, type="partitional", k=2, distance="dtw2", centroid="mean")

However, when I view c, "distmat" is NULL (c@distmat returns NULL), when I expect the distance matrix to be stored here.

Is there any way to extract the distance matrix used in the clustering after the fact? Or provide a pre-computed distance matrix to tsclust to avoid having to calculate twice? I have tried the latter option using dist() without success, but my implementation could be wrong.

Thanks for the excellent package!

asardaes commented 1 month ago

The whole distance matrix is only saved if you use "pam" centroids, but you can definitely calculate it separately, check the examples in the vignette's appendices.