| 1 | toInteger <- function(x, condition) |
| 2 | { |
| 3 | if (!is.integer(x)) |
| 4 | tryCatch( |
| 5 | {x = as.integer(x)[1]}, |
| 6 | error = function(e) paste("cannot convert argument",substitute(x),"to integer") |
| 7 | ) |
| 8 | if (!condition(x)) |
| 9 | stop(paste("argument",substitute(x),"does not verify condition",body(condition))) |
| 10 | x |
| 11 | } |
| 12 | |
| 13 | writeCoeffs = function(coeffs) |
| 14 | { |
| 15 | file = ".coeffs" |
| 16 | #......... |
| 17 | #C function (from data.frame, type of IDs ??! force integers ? [yes]) |
| 18 | #return raw vector |
| 19 | #take raw vector, append it (binary mode) to a file |
| 20 | #TODO: appendCoeffs() en C --> serialize et append to file |
| 21 | } |
| 22 | |
| 23 | readCoeffs = function(indices) |
| 24 | { |
| 25 | #...... |
| 26 | file = ".coeffs" |
| 27 | #C function (from file name) |
| 28 | } |
| 29 | |
| 30 | getSeries(data, rank=NULL, id=NULL) |
| 31 | { |
| 32 | #TODO: |
| 33 | } |
| 34 | |
| 35 | curvesToCoeffs = function(series, wf) |
| 36 | { |
| 37 | L = length(series[1,]) |
| 38 | D = ceiling( log2(L) ) |
| 39 | nb_sample_points = 2^D |
| 40 | apply(series, 1, function(x) { |
| 41 | interpolated_curve = spline(1:L, x, n=nb_sample_points)$y |
| 42 | W = wavelets::dwt(interpolated_curve, filter=wf, D)@W |
| 43 | rev( sapply( W, function(v) ( sqrt( sum(v^2) ) ) ) ) |
| 44 | }) |
| 45 | } |