- indices_workers = .spreadIndices(indices, nb_series_per_chunk)
- if (parll)
- indices = unlist( parallel::parLapply(cl, indices_workers, wrapComputeClusters1) )
- else
- indices = unlist( lapply(indices_workers, wrapComputeClusters1) )
- }
- if (parll)
- parallel::stopCluster(cl)
-
- indices #medoids
-}
-
-#' @rdname clustering
-#' @export
-computeClusters1 = function(contribs, K1)
- cluster::pam(contribs, K1, diss=FALSE)$id.med
-
-#' @rdname clustering
-#' @export
-computeClusters2 = function(medoids, K2,
- getRefSeries, nb_ref_curves, nb_series_per_chunk, ncores_clust=1,verbose=FALSE,parll=TRUE)
-{
- synchrones = computeSynchrones(medoids,
- getRefSeries, nb_ref_curves, nb_series_per_chunk, ncores_clust, verbose, parll)
- distances = computeWerDists(synchrones, ncores_clust, verbose, parll)
- medoids[ cluster::pam(distances, K2, diss=TRUE)$medoids , ]
-}
-
-#' computeSynchrones
-#'
-#' Compute the synchrones curves (sum of clusters elements) from a matrix of medoids,
-#' using L2 distances.
-#'
-#' @param medoids Matrix of medoids (curves of same legnth as initial series)
-#' @param getRefSeries Function to retrieve initial series (e.g. in stage 2 after series
-#' have been replaced by stage-1 medoids)
-#' @param nb_ref_curves How many reference series? (This number is known at this stage)
-#' @inheritParams claws
-#'
-#' @export
-computeSynchrones = function(medoids, getRefSeries,
- nb_ref_curves, nb_series_per_chunk, ncores_clust=1,verbose=FALSE,parll=TRUE)
-{
- computeSynchronesChunk = function(indices)
- {
- ref_series = getRefSeries(indices)
- #get medoids indices for this chunk of series
- for (i in seq_len(nrow(ref_series)))
- {
- j = which.min( rowSums( sweep(medoids, 2, ref_series[i,], '-')^2 ) )