avancée sur compréhension de epclust/R/stage2.R
[epclust.git] / epclust / R / algorithms.R
1 #NOTE: always keep ID in first column
2 curvesToCoeffs = function(series, wf)
3 {
4 library(wavelets)
5 L = length(series[1,])
6 D = ceiling( log(L-1) )
7 nb_sample_points = 2^D
8 #TODO: parallel::parApply() ?!
9 res = apply(series, 1, function(x) {
10 interpolated_curve = spline(1:(L-1), x[2:L], n=nb_sample_points)$y
11 W = wavelets::dwt(interpolated_curve, filter=wf, D)@W
12 nrj_coeffs = rev( sapply( W, function(v) ( sqrt( sum(v^2) ) ) ) )
13 return ( c(x[1], nrj_coeffs) )
14 })
15 return (as.data.frame(res))
16 }
17
18 getClusters = function(data, K)
19 {
20 library(cluster)
21 pam_output = cluster::pam(data, K)
22 return ( list( clusts=pam_output$clustering, medoids=pam_output$medoids,
23 ranks=pam_output$id.med ) )
24 }