- }
- if (parll)
- parallel::stopCluster(cl)
-
- indices #medoids
-}
-
-#' @rdname clustering
-#' @export
-clusteringTask2 = function(medoids, K2, algoClust2, getRefSeries, nb_ref_curves,
- nb_series_per_chunk, sync_mean, nbytes,endian,ncores_clust=1,verbose=FALSE,parll=TRUE)
-{
- if (verbose)
- cat(paste("*** Clustering task 2 on ",ncol(medoids)," synchrones\n", sep=""))
-
- if (ncol(medoids) <= K2)
- return (medoids)
- synchrones = computeSynchrones(medoids, getRefSeries, nb_ref_curves,
- nb_series_per_chunk, sync_mean, ncores_clust, verbose, parll)
- distances = computeWerDists(synchrones, nbytes, endian, ncores_clust, verbose, parll)
- if (verbose)
- cat(paste(" algoClust2() on ",nrow(distances)," items\n", sep=""))
- medoids[ algoClust2(distances,K2), ]
-}
-
-#' computeSynchrones
-#'
-#' Compute the synchrones curves (sum of clusters elements) from a matrix of medoids,
-#' using L2 distances.
-#'
-#' @param medoids big.matrix of medoids (curves of same length 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
-#'
-#' @return A big.matrix of size L x K1 where L = length of a serie
-#'
-#' @export
-computeSynchrones = function(medoids, getRefSeries, nb_ref_curves,
- nb_series_per_chunk, sync_mean, ncores_clust=1,verbose=FALSE,parll=TRUE)
-{
- computeSynchronesChunk = function(indices)
- {
- if (parll)
- {
- require("bigmemory", quietly=TRUE)
- requireNamespace("synchronicity", quietly=TRUE)
- require("epclust", quietly=TRUE)
- synchrones <- bigmemory::attach.big.matrix(synchrones_desc)
- if (sync_mean)
- counts <- bigmemory::attach.big.matrix(counts_desc)
- medoids <- bigmemory::attach.big.matrix(medoids_desc)
- m <- synchronicity::attach.mutex(m_desc)
- }
-
- ref_series = getRefSeries(indices)
- nb_series = nrow(ref_series)
-
- # Get medoids indices for this chunk of series
- mi = computeMedoidsIndices(medoids@address, ref_series)
-
- for (i in seq_len(nb_series))