finish simplifications on stage2.R
[epclust.git] / epclust / R / algorithms.R
CommitLineData
3465b246
BA
1#NOTE: always keep ID in first column
2curvesToCoeffs = function(series, wf)
b9f1c0c7 3{
3465b246
BA
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))
b9f1c0c7
BA
16}
17
18getClusters = function(data, K)
19{
3465b246
BA
20 library(cluster)
21 pam_output = cluster::pam(data, K)
cea14f3a
BA
22 return ( list( clusts=pam_output$clustering, medoids=pam_output$medoids,
23 ranks=pam_output$id.med ) )
b9f1c0c7 24}