| 1 | computeClusters |
| 2 | computeSynchrones |
| 3 | |
| 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) |
| 7 | { |
| 8 | cl = parallel::makeCluster(ncores) |
| 9 | repeat |
| 10 | { |
| 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] |
| 16 | }) |
| 17 | indices = unlist( parallel::parLapply(cl, indices_workers, function(inds) |
| 18 | computeClusters1(inds, getCoefs, K1)) ) |
| 19 | if (length(indices_clust) == K1) |
| 20 | break |
| 21 | } |
| 22 | parallel::stopCluster(cl) |
| 23 | if (K2 == 0) |
| 24 | return (indices) |
| 25 | computeClusters2(indices, K2, getSeries, getSeriesForSynchrones, to_file, |
| 26 | nb_series_per_chunk,ftype) |
| 27 | vector("integer",0) |
| 28 | } |
| 29 | |
| 30 | # Apply the clustering algorithm (PAM) on a coeffs or distances matrix |
| 31 | computeClusters1 = function(indices, getCoefs, K1) |
| 32 | { |
| 33 | coefs = getCoefs(indices) |
| 34 | indices[ cluster::pam(coefs, K1, diss=FALSE)$id.med ] |
| 35 | } |
| 36 | |
| 37 | # Cluster a chunk of series inside one task (~max nb_series_per_chunk) |
| 38 | computeClusters2 = function(indices, K2, getSeries, getSeriesForSynchrones, to_file, |