X-Git-Url: https://git.auder.net/?p=epclust.git;a=blobdiff_plain;f=epclust%2FR%2FcomputeCoeffs.R;h=fca3b9188d3ceda45281070211e98adfc1adfb00;hp=6ca55ee8ad586118d6db92c454097fd63720614a;hb=23844f603a363475e85ed1cb4b8620f139bcffdf;hpb=c33af7e44b802c182ea92c79b56a72cae3007301 diff --git a/epclust/R/computeCoeffs.R b/epclust/R/computeCoeffs.R index 6ca55ee..fca3b91 100644 --- a/epclust/R/computeCoeffs.R +++ b/epclust/R/computeCoeffs.R @@ -27,20 +27,17 @@ computeCoeffs = function(data, index, nb_series_per_chunk, wf) coeffs_chunk } -#NOTE: always keep ID in first column (...? is it good ?!) curvesToCoeffs = function(series, wf) { if (!require(wavelets, quietly=TRUE)) stop("Couldn't load wavelets library") L = length(series[1,]) - D = ceiling( log2(L-1) ) + D = ceiling( log2(L) ) nb_sample_points = 2^D #TODO: parallel::parApply() ?! - res = apply(series, 1, function(x) { - interpolated_curve = spline(1:(L-1), x[2:L], n=nb_sample_points)$y + as.data.frame( apply(series, 1, function(x) { + interpolated_curve = spline(1:L, x, n=nb_sample_points)$y W = wavelets::dwt(interpolated_curve, filter=wf, D)@W - nrj_coeffs = rev( sapply( W, function(v) ( sqrt( sum(v^2) ) ) ) ) - return ( c(x[1], nrj_coeffs) ) - }) - return (as.data.frame(res)) + rev( sapply( W, function(v) ( sqrt( sum(v^2) ) ) ) ) + }) ) }