-# Cluster one full task (nb_curves / ntasks series); only step 1
-clusteringTask = function(indices, getCoefs, K1, nb_series_per_chunk, ncores)
-{
- cl = parallel::makeCluster(ncores)
- parallel::clusterExport(cl, varlist=c("getCoefs","K1"), envir=environment())
- repeat
- {
- nb_workers = max( 1, floor( length(indices) / nb_series_per_chunk ) )
- indices_workers = lapply( seq_len(nb_workers), function(i)
- indices[(nb_series_per_chunk*(i-1)+1):(nb_series_per_chunk*i)] )
- # Spread the remaining load among the workers
- rem = length(indices) %% nb_series_per_chunk
- while (rem > 0)
- {
- index = rem%%nb_workers + 1
- indices_workers[[index]] = c(indices_workers[[index]], tail(indices,rem))
- rem = rem - 1
- }
- indices = unlist( parallel::parLapply( cl, indices_workers, function(inds) {
- require("epclust", quietly=TRUE)
- inds[ computeClusters1(getCoefs(inds), K1) ]
- } ) )
- if (length(indices) == K1)
- break
- }
- parallel::stopCluster(cl)
- indices #medoids
-}
-
-# Apply the clustering algorithm (PAM) on a coeffs or distances matrix
-computeClusters1 = function(coefs, K1)
- cluster::pam(coefs, K1, diss=FALSE)$id.med
+#' Two-stage clustering, within one task (see \code{claws()})
+#'
+#' \code{clusteringTask1()} runs one full stage-1 task, which consists in iterated
+#' clustering on nb_curves / ntasks energy contributions, computed through
+#' discrete wavelets coefficients.
+#' \code{clusteringTask2()} runs a full stage-2 task, which consists in WER distances
+#' computations between medoids (indices) output from stage 1, before applying
+#' the second clustering algorithm on the distances matrix.
+#'
+#' @param getContribs Function to retrieve contributions from initial series indices:
+#' \code{getContribs(indices)} outputs a contributions matrix, in columns
+#' @inheritParams claws
+#' @inheritParams computeSynchrones
+#' @inheritParams computeWerDists
+#'
+#' @return The indices of the computed (resp. K1 and K2) medoids.
+#'
+#' @name clustering
+#' @rdname clustering
+#' @aliases clusteringTask1 clusteringTask2
+NULL