From 2c7ce3152d6edc4af33e611eab6d157f04eb1c49 Mon Sep 17 00:00:00 2001 From: pfistfl Date: Fri, 20 Jul 2018 10:57:26 +0200 Subject: [PATCH 1/7] add Names --- R/metricChoices.R | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/R/metricChoices.R b/R/metricChoices.R index ac0a489..d792920 100644 --- a/R/metricChoices.R +++ b/R/metricChoices.R @@ -18,17 +18,16 @@ metricChoices = function(proxy.only = FALSE) { proxy.list = proxy::pr_DB$get_entries() is_metric = unlist(BBmisc::extractSubList(proxy.list, element = "type")) == "metric" proxy_metric_names = unlist(BBmisc::extractSubList(proxy.list[is_metric], - element = "names")) + element = "names")) if (proxy.only) { return(proxy_metric_names) } else { - return(c(proxy_metric_names, - "shortEuclidean", "mean", "relAreas", - "jump", "globMax", "globMin", - "points", "custom.metric", - "amplitudeDistance", "phaseDistance", - "FisherRao", "elasticMetric", - "elasticDistance", - "dtwPath", "rucrdtw", "rucred")) + additional_metric_names = c("shortEuclidean", "mean", "relAreas", + "jump", "globMax", "globMin", "points", "custom.metric", + "amplitudeDistance", "phaseDistance", "FisherRao", "elasticMetric", + "elasticDistance", "dtwPath", "rucrdtw", "rucred") + names(additional_metric_names) = additional_metric_names + + return(c(proxy_metric_names, additional_metric_names)) } } From 1f8a6b59d8a012dbf7103740f785fd6bed3f8ca8 Mon Sep 17 00:00:00 2001 From: pfistfl Date: Fri, 27 Jul 2018 13:23:46 +0200 Subject: [PATCH 2/7] Remove ucrdtw and ucred from proxy --- R/metricChoices.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/metricChoices.R b/R/metricChoices.R index d792920..52ebb32 100644 --- a/R/metricChoices.R +++ b/R/metricChoices.R @@ -25,7 +25,7 @@ metricChoices = function(proxy.only = FALSE) { additional_metric_names = c("shortEuclidean", "mean", "relAreas", "jump", "globMax", "globMin", "points", "custom.metric", "amplitudeDistance", "phaseDistance", "FisherRao", "elasticMetric", - "elasticDistance", "dtwPath", "rucrdtw", "rucred") + "elasticDistance", "dtwPath") names(additional_metric_names) = additional_metric_names return(c(proxy_metric_names, additional_metric_names)) From 256e87727c23f64cdae9a61e6e8e7e09287760ab Mon Sep 17 00:00:00 2001 From: pfistfl Date: Fri, 27 Jul 2018 13:26:36 +0200 Subject: [PATCH 3/7] Extra file for proxyImportedMetrics --- R/computeDistMat.R | 18 ------------------ R/proxyImportedMetrics.R | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 R/proxyImportedMetrics.R diff --git a/R/computeDistMat.R b/R/computeDistMat.R index 5d537be..1643674 100644 --- a/R/computeDistMat.R +++ b/R/computeDistMat.R @@ -309,14 +309,6 @@ computeDistMat = function(x, y = NULL, ucrdtw = function(x, y, dtwwindow = 0.05, ...) { rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance } - pr_DB$set_entry(FUN = ucrdtw, names = "rucrdtw", - loop = TRUE, type = "metric", - description = "Dynamic Time Warping from UCR", - reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. - The Journal of Open Source Software URL http://doi.org/10.21105/joss.00100; - Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences - under dynamic time warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", - formula = "minimum of sum(x[xw[i]]-y[yw[i]]) over all monotonic xw, yw"); return(as.matrix(proxy::dist(x, y, method = "rucrdtw", ...))) } @@ -326,16 +318,6 @@ computeDistMat = function(x, y = NULL, ucred = function(x, y, ...) { rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance } - pr_DB$set_entry(FUN = ucred, names = "rucred", - loop = TRUE, type = "metric", - description = "Euclidean Distance from UCR", - reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. - The Journal of Open Source - Software URL http://doi.org/10.21105/joss.00100; - Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences - under dynamic time - warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", - formula = "sqrt(sum((x-y)^2))"); return(as.matrix(proxy::dist(x, y, method = "rucred", ..., PACKAGE = "rucrdtw"))) } diff --git a/R/proxyImportedMetrics.R b/R/proxyImportedMetrics.R new file mode 100644 index 0000000..d918918 --- /dev/null +++ b/R/proxyImportedMetrics.R @@ -0,0 +1,19 @@ +pr_DB$set_entry(FUN = ucrdtw, names = "rucrdtw", + loop = TRUE, type = "metric", + description = "Dynamic Time Warping from UCR", + reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. + The Journal of Open Source Software URL http://doi.org/10.21105/joss.00100; + Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences + under dynamic time warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", + formula = "minimum of sum(x[xw[i]]-y[yw[i]]) over all monotonic xw, yw"); + +pr_DB$set_entry(FUN = ucred, names = "rucred", + loop = TRUE, type = "metric", + description = "Euclidean Distance from UCR", + reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. + The Journal of Open Source + Software URL http://doi.org/10.21105/joss.00100; + Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences + under dynamic time + warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", + formula = "sqrt(sum((x-y)^2))"); From 6b44d15cfe7d5284bc66b96a9d7146ff7c0dd19b Mon Sep 17 00:00:00 2001 From: pfistfl Date: Fri, 27 Jul 2018 13:33:20 +0200 Subject: [PATCH 4/7] Make unittests pass! --- R/computeDistMat.R | 6 ------ R/proxyImportedMetrics.R | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/R/computeDistMat.R b/R/computeDistMat.R index 1643674..8652ec5 100644 --- a/R/computeDistMat.R +++ b/R/computeDistMat.R @@ -306,18 +306,12 @@ computeDistMat = function(x, y = NULL, # Dynamic Time Warping Distance from rucrdtw package if (method == "rucrdtw") { requirePackages("rucrdtw") - ucrdtw = function(x, y, dtwwindow = 0.05, ...) { - rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance - } return(as.matrix(proxy::dist(x, y, method = "rucrdtw", ...))) } # Euclidean Distance from rucrdtw package if (method == "rucred") { requirePackages("rucrdtw") - ucred = function(x, y, ...) { - rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance - } return(as.matrix(proxy::dist(x, y, method = "rucred", ..., PACKAGE = "rucrdtw"))) } diff --git a/R/proxyImportedMetrics.R b/R/proxyImportedMetrics.R index d918918..08294cf 100644 --- a/R/proxyImportedMetrics.R +++ b/R/proxyImportedMetrics.R @@ -1,3 +1,7 @@ +ucrdtw = function(x, y, dtwwindow = 0.05, ...) { + rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance +} + pr_DB$set_entry(FUN = ucrdtw, names = "rucrdtw", loop = TRUE, type = "metric", description = "Dynamic Time Warping from UCR", @@ -7,6 +11,10 @@ pr_DB$set_entry(FUN = ucrdtw, names = "rucrdtw", under dynamic time warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", formula = "minimum of sum(x[xw[i]]-y[yw[i]]) over all monotonic xw, yw"); +ucred = function(x, y, ...) { + rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance +} + pr_DB$set_entry(FUN = ucred, names = "rucred", loop = TRUE, type = "metric", description = "Euclidean Distance from UCR", From 7a6e40e61c6962562068d918eb39924373741fbe Mon Sep 17 00:00:00 2001 From: pfistfl Date: Fri, 27 Jul 2018 13:58:26 +0200 Subject: [PATCH 5/7] functions within set_entry --- R/proxyImportedMetrics.R | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/R/proxyImportedMetrics.R b/R/proxyImportedMetrics.R index 08294cf..3cf9050 100644 --- a/R/proxyImportedMetrics.R +++ b/R/proxyImportedMetrics.R @@ -1,8 +1,7 @@ -ucrdtw = function(x, y, dtwwindow = 0.05, ...) { - rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance -} - -pr_DB$set_entry(FUN = ucrdtw, names = "rucrdtw", +pr_DB$set_entry(FUN = function(x, y, dtwwindow = 0.05, ...) { + rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance + }, + names = "rucrdtw", loop = TRUE, type = "metric", description = "Dynamic Time Warping from UCR", reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. @@ -11,11 +10,11 @@ pr_DB$set_entry(FUN = ucrdtw, names = "rucrdtw", under dynamic time warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", formula = "minimum of sum(x[xw[i]]-y[yw[i]]) over all monotonic xw, yw"); -ucred = function(x, y, ...) { - rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance -} - -pr_DB$set_entry(FUN = ucred, names = "rucred", +pr_DB$set_entry( + FUN = function(x, y, ...) { + rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance + }, + names = "rucred", loop = TRUE, type = "metric", description = "Euclidean Distance from UCR", reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. From f0f01933caac24769e6d013311a8c487febeabe7 Mon Sep 17 00:00:00 2001 From: pfistfl Date: Fri, 27 Jul 2018 14:00:34 +0200 Subject: [PATCH 6/7] functions within set_entry --- R/proxyImportedMetrics.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/proxyImportedMetrics.R b/R/proxyImportedMetrics.R index 3cf9050..0d83401 100644 --- a/R/proxyImportedMetrics.R +++ b/R/proxyImportedMetrics.R @@ -1,4 +1,4 @@ -pr_DB$set_entry(FUN = function(x, y, dtwwindow = 0.05, ...) { +proxy::pr_DB$set_entry(FUN = function(x, y, dtwwindow = 0.05, ...) { rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance }, names = "rucrdtw", @@ -10,7 +10,7 @@ pr_DB$set_entry(FUN = function(x, y, dtwwindow = 0.05, ...) { under dynamic time warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", formula = "minimum of sum(x[xw[i]]-y[yw[i]]) over all monotonic xw, yw"); -pr_DB$set_entry( +proxy::pr_DB$set_entry( FUN = function(x, y, ...) { rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance }, From 5906a2985c025ace2e25ba32a7dca82b3fa46a44 Mon Sep 17 00:00:00 2001 From: pfistfl Date: Fri, 27 Jul 2018 14:12:46 +0200 Subject: [PATCH 7/7] Revert some changes --- R/computeDistMat.R | 28 ++++++++++++++++++++++++++-- R/metricChoices.R | 7 ++++--- R/proxyImportedMetrics.R | 26 -------------------------- 3 files changed, 30 insertions(+), 31 deletions(-) delete mode 100644 R/proxyImportedMetrics.R diff --git a/R/computeDistMat.R b/R/computeDistMat.R index 8652ec5..dc9940a 100644 --- a/R/computeDistMat.R +++ b/R/computeDistMat.R @@ -306,12 +306,36 @@ computeDistMat = function(x, y = NULL, # Dynamic Time Warping Distance from rucrdtw package if (method == "rucrdtw") { requirePackages("rucrdtw") - - return(as.matrix(proxy::dist(x, y, method = "rucrdtw", ...))) + proxy::pr_DB$set_entry(FUN = function(x, y, dtwwindow = 0.05, ...) { + rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance + }, + names = "rucrdtw", + loop = TRUE, type = "metric", + description = "Dynamic Time Warping from UCR", + reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. + The Journal of Open Source Software URL http://doi.org/10.21105/joss.00100; + Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences + under dynamic time warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", + formula = "minimum of sum(x[xw[i]]-y[yw[i]]) over all monotonic xw, yw"); + return(as.matrix(proxy::dist(x, y, method = "rucrdtw", ...))) } # Euclidean Distance from rucrdtw package if (method == "rucred") { requirePackages("rucrdtw") + proxy::pr_DB$set_entry( + FUN = function(x, y, ...) { + rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance + }, + names = "rucred", + loop = TRUE, type = "metric", + description = "Euclidean Distance from UCR", + reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. + The Journal of Open Source + Software URL http://doi.org/10.21105/joss.00100; + Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences + under dynamic time + warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", + formula = "sqrt(sum((x-y)^2))"); return(as.matrix(proxy::dist(x, y, method = "rucred", ..., PACKAGE = "rucrdtw"))) } diff --git a/R/metricChoices.R b/R/metricChoices.R index 52ebb32..710cfef 100644 --- a/R/metricChoices.R +++ b/R/metricChoices.R @@ -25,9 +25,10 @@ metricChoices = function(proxy.only = FALSE) { additional_metric_names = c("shortEuclidean", "mean", "relAreas", "jump", "globMax", "globMin", "points", "custom.metric", "amplitudeDistance", "phaseDistance", "FisherRao", "elasticMetric", - "elasticDistance", "dtwPath") + "elasticDistance", "dtwPath", "rucrdtw", "rucred") names(additional_metric_names) = additional_metric_names - - return(c(proxy_metric_names, additional_metric_names)) + choices = c(proxy_metric_names, additional_metric_names) + # Make sure we have unique names + return(choices[unique(names(choices))]) } } diff --git a/R/proxyImportedMetrics.R b/R/proxyImportedMetrics.R deleted file mode 100644 index 0d83401..0000000 --- a/R/proxyImportedMetrics.R +++ /dev/null @@ -1,26 +0,0 @@ -proxy::pr_DB$set_entry(FUN = function(x, y, dtwwindow = 0.05, ...) { - rucrdtw::ucrdtw_vv(x, y, skip = TRUE, dtwwindow = dtwwindow, ...)$distance - }, - names = "rucrdtw", - loop = TRUE, type = "metric", - description = "Dynamic Time Warping from UCR", - reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. - The Journal of Open Source Software URL http://doi.org/10.21105/joss.00100; - Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences - under dynamic time warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", - formula = "minimum of sum(x[xw[i]]-y[yw[i]]) over all monotonic xw, yw"); - -proxy::pr_DB$set_entry( - FUN = function(x, y, ...) { - rucrdtw::ucred_vv(data = x, query = y, skip = TRUE, ...)$distance - }, - names = "rucred", - loop = TRUE, type = "metric", - description = "Euclidean Distance from UCR", - reference = "Boersch-Supan (2016). rucrdtw: Fast time series subsequence search in R. - The Journal of Open Source - Software URL http://doi.org/10.21105/joss.00100; - Rakthanmanon et al. (2012). Searching and mining trillions of time series subsequences - under dynamic time - warping. SIGKDD URL http://doi.org/10.1145/2339530.2339576", - formula = "sqrt(sum((x-y)^2))");