a01385ee55bf46bbcc1659d74e43f15dd7042121
[epclust.git] / code / draft_R_pkg / R / main.R
1 #TODO: setRefClass... to avoid copy data !!
2 #http://stackoverflow.com/questions/2603184/r-pass-by-reference
3
4 #fields: data (can be NULL or provided by user), coeffs (will be computed
5 #con can be a character string naming a file; see readLines()
6 #data can be in DB format, on one column : TODO: guess (from header, or col. length...)
7
8
9 writeTmp(curves [uncompressed coeffs, limited number - nbSeriesPerChunk], last=FALSE) #if last=TRUE, close the conn
10 readTmp(..., from index, n curves) #careful: connection must remain open
11 #TODO: write read/write tmp reference ( on file in .tmp/ folder ... )
12
13 epclust = function(data=NULL, K, nbPerChunk, ..., writeTmp=ref_writeTmp, readTmp=ref_readTmp) #where to put/retrieve intermediate results; if not provided, use file on disk
14 {
15
16
17 #on input: can be data or con; data handled by writing it to file (ascii or bin ?!),
18 #data: con or matrix or DB
19
20 #1) acquire data (process curves, get as coeffs)
21 if (is.numeric(data))
22 {
23 #full data matrix
24 index = 1
25 n = nrow(data)
26 while (index < n)
27 {
28 writeTmp( getCoeffs(data) )
29 index = index + nbSeriesPerChunk
30 }
31 } else if (is.function(data))
32 {
33 #custom user function to retrieve next n curves, probably to read from DB
34 writeTmp( getCoeffs( data(nbPerChunk) ) )
35 } else
36 {
37 #incremental connection
38 #read it one by one and get coeffs until nbSeriesPerChunk
39 #then launch a clustering task............
40 ascii_lines = readLines(data, nbSeriesPerChunk)
41 seriesChunkFile = ".tmp/seriesChunk" #TODO: find a better way
42 writeLines(ascii_lines, seriesChunkFile)
43 writeTmp( getCoeffs( read.csv(seriesChunkFile) ) )
44 } else
45 stop("Unrecognizable 'data' argument (must be numeric, functional or connection)")
46
47 #2) process coeffs (by nbSeriesPerChunk) and cluster in parallel (just launch async task, wait for them to complete, and re-do if necessary)
48
49
50 #3) apply stage 2 (in parallel ? inside task 2) ?)
51 }
52
53 getCoeffs = function(series)
54 {
55 #... return wavelets coeffs : compute in parallel !
56 }