ee15a7988b2a77c00179bc518871a7cd9dd9cfcb
[epclust.git] / old_C_code / wrapper.R
1 ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL,
2 nbSeriesPerChunk, nbClusters, randomize=1, p_dissims=2)
3 {
4 args = paste(nbSeriesPerChunk," ",nbClusters," ",randomize," ",p_dissims,sep="")
5
6 command_line = paste("mpirun -np ",np," ",path,"/ppam.exe cluster",sep="")
7
8 #if data provided (as data.frame or matrix...): binarize it, and add it as first argument
9 if (!is.null(data))
10 {
11 if (!is.character(data))
12 {
13 #assuming matrix or data.frame, WITH row names
14 #( identifiers; could be line number... e.g. data <- cbind(1:nrow(data),data) )
15 write.table(data, "/tmp/data_csv", sep=",", row.names=FALSE, col.names=FALSE)
16 system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
17 } else
18 {
19 system(paste(path,"/ppam.exe serialize ",data," /tmp/data_bin 0 0",sep=""))
20 }
21 command_line = paste(command_line," /tmp/data_bin",sep="")
22 }
23
24 command_line = paste(command_line," ",args,sep="")
25 system(command_line)
26 }
27
28 #NOTE: identifiers in first column
29 getMedoids = function(path=".", xmlResult = "ppamResult.xml",
30 finalSeries = "ppamFinalSeries.bin")
31 {
32 system(paste(path,"/ppam.exe deserialize ",finalSeries," ppamFinalSeries.csv -1",sep=""))
33 curves = read.table("ppamFinalSeries.csv", sep=",")
34 library(XML)
35 ranks = as.integer( xmlToList( xmlParse(xmlResult) )$ranks )
36 return ( curves[ranks,] ) # == medoids
37 }
38
39 getDistor = function(path=".", xmlResult = "ppamResult.xml",
40 finalSeries = "ppamFinalSeries.bin")
41 {
42 system(paste(path,"/ppam.exe classif ",finalSeries," ",xmlResult,sep=""))
43 }
44
45 serialize = function(path=".", csvSeries, binSeries, byCols=0, nbSeries=0)
46 {
47 system(paste(path,"/ppam.exe serialize ",csvSeries," ",binSeries," ",byCols," ",nbSeries,
48 sep=""))
49 }
50
51 deserialize = function(path=".", binSeries, csvSeries, ranks="-1", return=TRUE)
52 {
53 system(paste(path,"/ppam.exe deserialize ",binSeries," ",csvSeries," ",ranks,sep=""))
54 if (return)
55 return ( read.table(csvSeries, sep=",") )
56 }