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
258 stars 29 forks source link

Wrong behaviour of plot command #7

Closed zdegreve closed 8 years ago

zdegreve commented 8 years ago

Hello,

Congratulations for your great job with dtwclust first !

I do not know if it is the right place to ask my question but I am beginning with dtwclust. I just noticed a wrong behaviour of the plot command on my system (Linux Mint 17.1, Rstudio 0.99.903, R version 3.3.1).

Let's say I use the command dtwclust to produce a partitional clustering of the data hold in with the command:

ClustResults_kshape <- dtwclust(Patterns, type = "partitional", k=10L, distance = "sbd",centroid="shape",control=list(trace=TRUE))

Then, when I want to plot some results, I issue the following command:

plot(ClustResults_kshape,type="sc")

and gets the following error: Error in plot.hclust(ClustResults_kshape, type = "sc") : invalid dendrogram

I get this systematically, even with the examples provided in the documentation. It seems that the "type" argument is not taken into account in my case.

Am I missing something or is it a bug ?

Thank you very much in advance.

Zacharie, Univ. of Mons

asardaes commented 8 years ago

Hi Zacharie,

Thanks a lot! What version of the package are you using? Can you verify that ClustResults_kshape@type contains "partitional"?

zdegreve commented 8 years ago

I use dtw v1.18-1, and yes, ClustResults_kshape@type contain "partitional". Thank you for your fast answer !

Regards

asardaes commented 8 years ago

But what version of dtwclust? Can you use Rstudio's "check for package updates" functionality and see if you can install a new version? I think the option is in the help menu.

zdegreve commented 8 years ago

Oh yes, sorry: dtwclust v2.2.1 My packages are up to date according Rstudio.

Thank you !

asardaes commented 8 years ago

Hmm that sounds weird indeed. I cannot reproduce it in my machine, and I doubt it's related to your data. Can you try the following?

First type showMethods(plot), you should see an entry for x="dtwclust", y="missing". If not, then for some reason your R is not detecting the appropriate plot method for dtwclust.

If it does show, you could try entering trace(plot, browser, signature = signature(x="dtwclust", y="missing")) and then running the plot command. You should be able to step through the code with F10 (but first jump into the .local function with Shift+F4) and maybe you can find out why it is not detecting/altering the value you provide for type.

zdegreve commented 8 years ago

The showMethods(plot) gives:

Function "plot":

So it seems that R does not detect the right plot method for dtwclust. I will investigate and keep you informed. Thank you !
zdegreve commented 8 years ago

Maybe this info is relevant: my version of ggplot2 package is 2.1.0

asardaes commented 8 years ago

It shouldn't be related to ggplot2. When I load dtwclust in a clean session I get:

> showMethods(plot)
Function: plot (package graphics)
x="ANY", y="ANY"
x="bootFlexclust", y="missing"
x="color", y="ANY"
x="dtwclust", y="missing"
x="kcca", y="missing"
x="kccasimple", y="missing"
x="profile.mle", y="missing"
x="projAxes", y="missing"
x="shadow", y="ANY"
x="stepFlexclust", y="missing"

I'm really not sure what could be causing your problem. Do you use other packages with custom plot methods? Have you tested those?

zdegreve commented 8 years ago

Ah maybe it is relevant: showMethods("plot") gives me this the correct output:

Function: plot (package graphics) x="ANY", y="ANY" x="bootFlexclust", y="missing" x="color", y="ANY" x="dtwclust", y="missing" x="kcca", y="missing" x="kccasimple", y="missing" x="profile.mle", y="missing" x="projAxes", y="missing" x="shadow", y="ANY" x="stepFlexclust", y="missing",

whereas showMethods(plot) yields: Function "plot": not an S4 generic function

Anyway, I am gonna try to unload each package one by one and test as you suggested.

Thank you.

asardaes commented 8 years ago

It's still kind of weird, I get the same answer with or without the double quotes. Try this:

data(uciCT)
ctrl <- new("dtwclustControl")

# Reinterpolate to same length and coerce as matrix
data <- t(sapply(CharTraj, reinterpolate, newLength = 180))

# Subset for speed
data <- data[1:20, ]

kc.l2 <- dtwclust(data, k = 4,
                  distance = "L2", centroid = "pam",
                  seed = 3247, control = ctrl)

dtwclust:::plot(kc.l2, type = "sc")
zdegreve commented 8 years ago

Hi again,

Adding dtwclust::: in front of my plot commands makes them work, thank you very much ! I still do not understand why but it works...

Thank you again !

PS: maybe I should open a new tread for that, but is it possible to "easily" (or not) enrich dtwclust with other clustering techniques ? It is indeed possible to register new distances or preprocessings, but I am wondering how far dtwclust could easily be extended with new clustering methods we are working on. What is your opinion ? Thanks !

asardaes commented 8 years ago

It seems your R is not dispatching the correct method automatically then, maybe some problem in the installation?

As for extending it, I guess it depends a lot, most proposals for new algorithms change only distances and centroids, and both can be adjusted in dtwclust (the centroid part is a bit clunky though). Many other algorithms use existing clustering approaches but change the representation of time series (SAX, wavelets, etc.), and I guess that could be done independently from dtwclust or added as a preproc function. I don't know many approaches that change the whole procedure significantly, except maybe TADPole, and things like that might indeed be more complicated to add.

zdegreve commented 8 years ago

Probably, I will reinstall it.

Thank you for your answer, I will go back to you if I find methods interesting to add to the package. Regards, Zacharie

asardaes commented 8 years ago

Sure, no problem.