X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=epclust%2FR%2Falgorithms.R;fp=epclust%2FR%2Falgorithms.R;h=97dce901d54c3dce05f6ebb834c675fd121266d3;hb=7709d507dfab9256a401f2c77ced7bc70d90fec3;hp=0000000000000000000000000000000000000000;hpb=38aef1cbef037257bf03dd1e65fbb682a32e3f2c;p=epclust.git diff --git a/epclust/R/algorithms.R b/epclust/R/algorithms.R new file mode 100644 index 0000000..97dce90 --- /dev/null +++ b/epclust/R/algorithms.R @@ -0,0 +1,24 @@ +#NOTE: always keep ID in first column +curvesToCoeffs = function(series, wf) +{ + 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) +{ + library(cluster) + pam_output = cluster::pam(data, K) + return ( list( clusts=pam_output$clustering, medoids=pam_output$medoids, + ranks=pam_output$id.med ) ) +}