- # 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)
-{
- 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=wf, 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
- })
-}
-
-# Check integer arguments with functional conditions
-.toInteger <- function(x, condition)
-{
- errWarn <- function(ignored)
- paste("Cannot convert argument' ",substitute(x),"' to integer", sep="")
- if (!is.integer(x))
- tryCatch({x = as.integer(x)[1]; if (is.na(x)) stop()},
- warning = errWarn, error = errWarn)
- if (!condition(x))
- {
- stop(paste("Argument '",substitute(x),
- "' does not verify condition ",body(condition), sep=""))
- }
- x
-}
-
-# Check logical arguments
-.toLogical <- function(x)
-{
- errWarn <- function(ignored)
- paste("Cannot convert argument' ",substitute(x),"' to logical", sep="")
- if (!is.logical(x))
- tryCatch({x = as.logical(x)[1]; if (is.na(x)) stop()},
- warning = errWarn, error = errWarn)
- x