- # Return medoids as a standard matrix, since K2 series have to fit in RAM
- # (clustering algorithm 1 takes K1 > K2 of them as input)
- medoids2[,]
-}
-
-#' curvesToContribs
-#'
-#' Compute the discrete wavelet coefficients for each series, and aggregate them in
-#' energy contribution across scales as described in https://arxiv.org/abs/1101.4744v2
-#'
-#' @param series [big.]matrix of series (in columns), of size L x n
-#' @inheritParams claws
-#'
-#' @return A [big.]matrix of size log(L) x n containing contributions in columns
-#'
-#' @export
-curvesToContribs = function(series, wav_filt, contrib_type, coin=FALSE)
-{
- series = as.matrix(series) #1D serie could occur
- L = nrow(series)
- D = ceiling( log2(L) )
- nb_sample_points = 2^D
- apply(series, 2, function(x) {
- interpolated_curve = spline(1:L, x, n=nb_sample_points)$y
- W = wavelets::dwt(interpolated_curve, filter=wav_filt, D)@W
- nrj = rev( sapply( W, function(v) ( sqrt( sum(v^2) ) ) ) )
- if (contrib_type!="absolute")
- nrj = nrj / sum(nrj)
- if (contrib_type=="logit")
- nrj = - log(1 - nrj)
- nrj
- })
-}
+ # Run last clustering tasks to obtain only K2 medoids indices
+ if (verbose)
+ cat("...Run final // stage 1 + stage 2\n")
+ indices_medoids <- clusteringTask1(indices_medoids_all, getContribs, K1, algoClust1,
+ nb_items_clust, ncores_tasks*ncores_clust, verbose, parll)
+ indices_medoids <- clusteringTask2(indices_medoids, getContribs, K2, algoClust2,
+ nb_series_per_chunk,smooth_lvl,nvoice,nbytes,endian,ncores_last_stage,verbose,parll)