This repository has been archived by the owner on Oct 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_GenerateDist.R
97 lines (71 loc) · 2.78 KB
/
01_GenerateDist.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
rm(list=ls())
library(igraph)
library(reshape2)
library(ggplot2)
library(gridExtra)
library(RColorBrewer)
library(data.table)
library(Matrix)
library(plyr)
library(gdata)
library(TDA)
library(plyr)
library(stringr)
library(dplyr)
### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
### test ####
dtest <- read.csv("data/test.csv")
gtest <- graph.data.frame(dtest,directed = F)
plot(gtest)
E(gtest)$weight <- dtest[,3]
DD = distances(gtest, v = V(gtest), to = V(gtest), mode = c("all"), weights = NULL, algorithm = c("automatic"))
DD
gtest <- simplify(gtest,remove.multiple = T,edge.attr.comb = list(weight="mean","ignore"))
plot(gtest)
DD = distances(gtest, v = V(gtest), to = V(gtest), mode = c("all"), weights = NULL, algorithm = c("automatic"))
DD
### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
### pre data ####
rm(list=ls())
modelName <- "kyber"
dat <- read.csv(paste0("data/",modelName,".csv"))
dat <- dat[1:2000,]
head(dat)
#sort(dat$value)[1:100]
#sort(dat$value,decreasing = T)[1:100]
A = 1e+15
B = 0.5e+23
a = 1;b=10
dat <- dat %>% subset(.,value>A) %>% subset(.,value<B)
dat$value2 <- lapply(dat$value, function(x){1+ (x-A)*(b-a)/(B-A)}) %>% as.numeric() %>% round(.,digits = 4)
head(dat)
### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
### main program ####
g2 <- graph.data.frame(dat[,2:3],directed = F)
#plot(g2,vertex.size=1,vertex.label=NA)
E(g2)$weight <- dat$value2
g2 <- simplify(g2,remove.multiple = T,edge.attr.comb = list(weight="mean","ignore"))
DD = distances(g2, v = V(g2), to = V(g2), mode = c("all"), weights = NULL, algorithm = c("automatic"))
Ind <- DD ==Inf
DD[Ind] <- vcount(g2)
write.table(DD,file=paste0(modelName,"_dist.csv"),sep = ";",row.names = FALSE,col.names = FALSE,eol = ";\n",append = FALSE)
# print(table(DD))
max(dat$value2)
### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
### plot ####
plot(g2,vertex.size=1,vertex.label=NA)
qplot(DD[DD<11])
### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
### GUDHI Run ####
f <- "kyber_dist.csv"
batFile <- paste0("Model_",modelName,".bat")
if (file.exists(batFile)) {
file.remove(batFile)
}
for (j in 2:6) {
cmd = paste("rips_distance_matrix_persistence.exe -o",gsub(".csv",paste0("MD",j,".txt"),f))
op = paste(" -r",j,"-d 4 -p 2 ")
cmd = paste0(cmd,op,f)
cat(cmd,sep="",file=batFile,append = T)
cat("\npause\n",file = batFile,append = T )
}