improve/fix comments - TODO: debug examples, CSV and after
[epclust.git] / epclust / R / computeWerDists.R
index 061c360..568a826 100644 (file)
@@ -1,7 +1,7 @@
 #' computeWerDists
 #'
-#' Compute the WER distances between the synchrones curves (in columns), which are
-#' returned (e.g.) by \code{computeSynchrones()}
+#' Compute the WER distances between the series at specified indices, which are
+#' obtaind by \code{getSeries(indices)}
 #'
 #' @param indices Range of series indices to cluster
 #' @inheritParams claws
@@ -11,7 +11,7 @@
 #'
 #' @export
 computeWerDists <- function(indices, getSeries, nb_series_per_chunk, smooth_lvl, nvoice,
-       nbytes, endian, ncores_clust=1, verbose=FALSE, parll=TRUE)
+       nbytes, endian, ncores_clust=3, verbose=FALSE, parll=TRUE)
 {
        n <- length(indices)
        L <- length(getSeries(1)) #TODO: not very neat way to get L
@@ -29,8 +29,7 @@ computeWerDists <- function(indices, getSeries, nb_series_per_chunk, smooth_lvl,
        {
                if (parll)
                {
-                       require("bigmemory", quietly=TRUE)
-                       require("Rwave", quietly=TRUE)
+                       # parallel workers start with an empty environment
                        require("epclust", quietly=TRUE)
                }
 
@@ -61,7 +60,6 @@ computeWerDists <- function(indices, getSeries, nb_series_per_chunk, smooth_lvl,
                if (parll)
                {
                        # parallel workers start with an empty environment
-                       require("bigmemory", quietly=TRUE)
                        require("epclust", quietly=TRUE)
                        Xwer_dist <- bigmemory::attach.big.matrix(Xwer_dist_desc)
                }
@@ -78,7 +76,7 @@ computeWerDists <- function(indices, getSeries, nb_series_per_chunk, smooth_lvl,
                        cwt_j <- getCWT(j, L)
 
                        # Compute the ratio of integrals formula 5.6 for WER^2
-                       # in https://arxiv.org/abs/1101.4744v2 ยง5.3
+                       # in https://arxiv.org/abs/1101.4744v2 paragraph 5.3
                        num <- filterMA(Mod(cwt_i * Conj(cwt_j)), smooth_lvl)
                        WY <- filterMA(Mod(cwt_j * Conj(cwt_j)), smooth_lvl)
                        wer2 <- sum(colSums(num)^2) / sum(colSums(WX) * colSums(WY))
@@ -92,7 +90,11 @@ computeWerDists <- function(indices, getSeries, nb_series_per_chunk, smooth_lvl,
        if (parll)
        {
                # outfile=="" to see stderr/stdout on terminal
-               cl <- parallel::makeCluster(ncores_clust, outfile="")
+               cl <-
+                       if (verbose)
+                               parallel::makeCluster(ncores_clust, outfile="")
+                       else
+                               parallel::makeCluster(ncores_clust)
                Xwer_dist_desc <- bigmemory::describe(Xwer_dist)
                parallel::clusterExport(cl, varlist=c("parll","nb_cwt_per_chunk","n","L",
                        "Xwer_dist_desc","noctave","nvoice","getCWT"), envir=environment())