3 #dans old_C_code/build :
7 #dans data/, lancer R puis :
8 #source("../old_C_code/wrapper.R")
9 #serialize("../old_C_code/build", "2009.csv","2009.bin",1)
12 #nbSeriesPerChunk = 3000
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")
19 ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL,
20 nbSeriesPerChunk, nbClusters, randomize=1, p_dissims=2)
22 args = paste(nbSeriesPerChunk," ",nbClusters," ",randomize," ",p_dissims,sep="")
24 command_line = paste("mpirun -np ",np," ",path,"/ppam.exe cluster",sep="")
26 #if data provided (as data.frame or matrix...): binarize it, and add it as first argument
29 if (!is.character(data))
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)
34 system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
37 system(paste(path,"/ppam.exe serialize ",data," /tmp/data_bin 0 0",sep=""))
39 command_line = paste(command_line," /tmp/data_bin",sep="")
42 command_line = paste(command_line," ",args,sep="")
46 #NOTE: identifiers in first column
47 getMedoids = function(path=".", xmlResult = "ppamResult.xml",
48 finalSeries = "ppamFinalSeries.bin")
50 system(paste(path,"/ppam.exe deserialize ",finalSeries," ppamFinalSeries.csv -1",sep=""))
51 curves = read.table("ppamFinalSeries.csv", sep=",")
53 ranks = as.integer( xmlToList( xmlParse(xmlResult) )$ranks )
54 return ( curves[ranks,] ) # == medoids
57 getDistor = function(path=".", xmlResult = "ppamResult.xml",
58 finalSeries = "ppamFinalSeries.bin")
60 system(paste(path,"/ppam.exe classif ",finalSeries," ",xmlResult,sep=""))
63 serialize = function(path=".", csvSeries, binSeries, byCols=0, nbSeries=0)
65 system(paste(path,"/ppam.exe serialize ",csvSeries," ",binSeries," ",byCols," ",nbSeries,
69 deserialize = function(path=".", binSeries, csvSeries, ranks="-1", return=TRUE)
71 system(paste(path,"/ppam.exe deserialize ",binSeries," ",csvSeries," ",ranks,sep=""))
73 return ( read.table(csvSeries, sep=",") )