From 23844f603a363475e85ed1cb4b8620f139bcffdf Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Fri, 3 Mar 2017 12:44:20 +0100
Subject: [PATCH] toward better ID+coeffs management

---
 epclust/R/computeCoeffs.R | 13 +++++--------
 epclust/R/main.R          |  1 +
 epclust/R/utils.R         |  2 +-
 3 files changed, 7 insertions(+), 9 deletions(-)

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) ) ) ) )
+	}) )
 }
diff --git a/epclust/R/main.R b/epclust/R/main.R
index 4159941..f5ad81a 100644
--- a/epclust/R/main.R
+++ b/epclust/R/main.R
@@ -68,6 +68,7 @@ epclust = function(data, K1, K2, ntasks=1, nb_series_per_chunk=50*K1, min_series
 
 	# Serialize all wavelets coefficients (+ IDs) onto a file
 	coeffs_file = ".coeffs"
+	ids_files = ".ids"
 	index = 1
 	nb_curves = 0
 	nb_coeffs = NA
diff --git a/epclust/R/utils.R b/epclust/R/utils.R
index 5c09b56..347c2c6 100644
--- a/epclust/R/utils.R
+++ b/epclust/R/utils.R
@@ -19,7 +19,7 @@ serialize = function(coeffs, file, append)
 #TODO: appendCoeffs() en C --> serialize et append to file
 }
 
-deserialize = function(file, range, serie_length)
+deserialize = function(file, range, ncoefs)
 {
 	#......
 	#C function (from file name)
-- 
2.44.0