separate TODO and wrapper example
[epclust.git] / old_C_code / wrapper.R
CommitLineData
65bd7506
BA
1#Exemple :
2#
3#dans old_C_code/build :
4#cmake ../stage1/src
5#make
6#
7#dans data/, lancer R puis :
8#source("../old_C_code/wrapper.R")
9#serialize("../old_C_code/build", "2009.csv","2009.bin",1)
10#library(parallel)
11#np = detectCores()
12#nbSeriesPerChunk = 3000
13#nbClusters = 20
14#ppam_exe("../old_C_code/build",np,"2009.bin",nbSeriesPerChunk,nbClusters)
15#C = getMedoids("../old_C_code/build", "ppamResult.xml", "ppamFinalSeries.bin")
16#first100series = deserialize("../old_C_code/build", "2009.bin", "2009.csv.part", "1-100")
17#distor = getDistor("../old_C_code/build", "ppamResult.xml", "2009.bin")
18
73d68777 19ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL,
14cb6cf8 20 nbSeriesPerChunk, nbClusters, randomize=1, p_dissims=2)
f1fea222 21{
14cb6cf8
BA
22 args = paste(nbSeriesPerChunk," ",nbClusters," ",randomize," ",p_dissims,sep="")
23
687aed4f 24 command_line = paste("mpirun -np ",np," ",path,"/ppam.exe cluster",sep="")
ebf1280e
BA
25
26 #if data provided (as data.frame or matrix...): binarize it, and add it as first argument
27 if (!is.null(data))
28 {
f9f51b6a
BA
29 if (!is.character(data))
30 {
73d68777
BA
31 #assuming matrix or data.frame, WITH row names
32 #( identifiers; could be line number... e.g. data <- cbind(1:nrow(data),data) )
33 write.table(data, "/tmp/data_csv", sep=",", row.names=FALSE, col.names=FALSE)
f9f51b6a
BA
34 system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
35 } else
36 {
37 system(paste(path,"/ppam.exe serialize ",data," /tmp/data_bin 0 0",sep=""))
38 }
39 command_line = paste(command_line," /tmp/data_bin",sep="")
ebf1280e
BA
40 }
41
42 command_line = paste(command_line," ",args,sep="")
f1fea222
BA
43 system(command_line)
44}
73d68777
BA
45
46#NOTE: identifiers in first column
47getMedoids = function(path=".", xmlResult = "ppamResult.xml",
48 finalSeries = "ppamFinalSeries.bin")
49{
50 system(paste(path,"/ppam.exe deserialize ",finalSeries," ppamFinalSeries.csv -1",sep=""))
51 curves = read.table("ppamFinalSeries.csv", sep=",")
52 library(XML)
53 ranks = as.integer( xmlToList( xmlParse(xmlResult) )$ranks )
54 return ( curves[ranks,] ) # == medoids
55}
7709d507 56
7709d507
BA
57getDistor = function(path=".", xmlResult = "ppamResult.xml",
58 finalSeries = "ppamFinalSeries.bin")
59{
60 system(paste(path,"/ppam.exe classif ",finalSeries," ",xmlResult,sep=""))
61}
5edda192
BA
62
63serialize = function(path=".", csvSeries, binSeries, byCols=0, nbSeries=0)
64{
65 system(paste(path,"/ppam.exe serialize ",csvSeries," ",binSeries," ",byCols," ",nbSeries,
66 sep=""))
67}
68
14cb6cf8 69deserialize = function(path=".", binSeries, csvSeries, ranks="-1", return=TRUE)
5edda192
BA
70{
71 system(paste(path,"/ppam.exe deserialize ",binSeries," ",csvSeries," ",ranks,sep=""))
14cb6cf8
BA
72 if (return)
73 return ( read.table(csvSeries, sep=",") )
5edda192 74}