X-Git-Url: https://git.auder.net/assets/current/gitweb.css?a=blobdiff_plain;f=code%2Fdraft_R_pkg%2FR%2Falgorithms.R;h=97dce901d54c3dce05f6ebb834c675fd121266d3;hb=3465b246a0b16fb48e44d43345c187fe6d4073df;hp=eda05e5f52e28385c2e5f395312ee53d25c9f7e6;hpb=cea14f3a36d329311d08b6c723c0102400f9bb6f;p=epclust.git diff --git a/code/draft_R_pkg/R/algorithms.R b/code/draft_R_pkg/R/algorithms.R index eda05e5..97dce90 100644 --- a/code/draft_R_pkg/R/algorithms.R +++ b/code/draft_R_pkg/R/algorithms.R @@ -1,17 +1,24 @@ -curvesToCoeffs = function(series) +#NOTE: always keep ID in first column +curvesToCoeffs = function(series, wf) { - #... return wavelets coeffs : compute in parallel ! - #TODO: always keep ID in first column -} - -coeffsToCurves = function(coeffs) -{ - #re-expand on wavelet basis + library(wavelets) + L = length(series[1,]) + D = ceiling( log(L-1) ) + 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 + 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)) } getClusters = function(data, K) { - pam_output = pam(data, K) + library(cluster) + pam_output = cluster::pam(data, K) return ( list( clusts=pam_output$clustering, medoids=pam_output$medoids, ranks=pam_output$id.med ) ) }