4 # Cluster one full task (nb_curves / ntasks series)
5 clusteringTask = function(indices,getSeries,getSeriesForSynchrones,synchrones_file,
6 getCoefs,K1,K2,nb_series_per_chunk,ncores,to_file,ftype)
8 cl = parallel::makeCluster(ncores)
11 nb_workers = max( 1, round( length(indices) / nb_series_per_chunk ) )
12 indices_workers = lapply(seq_len(nb_workers), function(i) {
13 upper_bound = ifelse( i<nb_workers,
14 min(nb_series_per_chunk*i,length(indices)), length(indices) )
15 indices[(nb_series_per_chunk*(i-1)+1):upper_bound]
17 indices = unlist( parallel::parLapply(cl, indices_workers, function(inds)
18 computeClusters1(inds, getCoefs, K1)) )
19 if (length(indices_clust) == K1)
22 parallel::stopCluster(cl)
25 computeClusters2(indices, K2, getSeries, getSeriesForSynchrones, to_file,
26 nb_series_per_chunk,ftype)
30 # Apply the clustering algorithm (PAM) on a coeffs or distances matrix
31 computeClusters1 = function(indices, getCoefs, K1)
33 coefs = getCoefs(indices)
34 indices[ cluster::pam(coefs, K1, diss=FALSE)$id.med ]
37 # Cluster a chunk of series inside one task (~max nb_series_per_chunk)
38 computeClusters2 = function(indices, K2, getSeries, getSeriesForSynchrones, to_file,