-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCIMain.R
120 lines (87 loc) · 3.51 KB
/
CIMain.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
###CIMain.R
####################################Synthetic Dataset###############################################
setwd("~/Rscript")
source("simdata_causal.R")
source("MMD.R")
source("Causeffect.R")
library(umap)
library(future.apply)
library(MatchIt)
library(marginaleffects)
start = proc.time()
future::plan(future::multisession, workers = 20)
span = 1 # Interval
MMD = future_lapply(1:100, future.seed=TRUE, FUN=function(x) {
compute_min_MMD(x, is.synthetic=TRUE, interval=span)
})
future::plan(future::sequential)
MMD = MMD[!sapply(MMD, is.null)] # Remove empty elements
# future_lapply parallel
dimension = c(2, 6, seq(10, 100, by=10))
future::plan(future::multisession)
result1 = future_lapply(c('euclidean', 'mahalanobis', 'psm'), future.seed=TRUE, FUN=function(m) {
estimate_ATT(method = m, replace=TRUE, B=100)
})
result2 = future_lapply(dimension, future.seed=TRUE, FUN=function(d) {
estimate_ATT(method = 'pca', d = d, replace=TRUE, B=100)
})
result3 = future_lapply(dimension, future.seed=TRUE, FUN=function(d) {
estimate_ATT(method = 'umap', d = d, replace=TRUE, B=100)
})
result1 = do.call(rbind, result1)
result2 = do.call(rbind, result2)
result3 = do.call(rbind, result3)
result = rbind(result1, result2, result3)
write.csv(result, "~/Rdata/Causeffect_Synthetic123.csv", row.names=F)
result4 = future_lapply(dimension, future.seed=TRUE, FUN=function(d) {
estimate_ATT(method = 'kdrm', d = d, replace=TRUE, B=100, MMD=MMD)
})
future::plan(future::sequential) # Close process
result4 = do.call(rbind, result4)
result = rbind(result, result4)
write.csv(result, "~/Rdata/Causeffect_Synthetic.csv", row.names=F)
diftime = proc.time() - start
print(paste("Execution time:", round(diftime[3]/60, 2), "minutes"))
####################################Austin2009 Dataset###############################################
setwd("~/Rscript")
source("simdata_causal.R")
source("MMD.R")
source("Causeffect.R")
library(umap)
library(future.apply)
library(MatchIt)
library(marginaleffects)
start = proc.time()
future::plan(future::multisession, workers = 20)
span = 1 # Interval
MMD = future_lapply(1:100, future.seed=TRUE, FUN=function(x) {
compute_min_MMD(x, is.synthetic=FALSE, interval=span)
})
future::plan(future::sequential)
MMD = MMD[!sapply(MMD, is.null)] # Remove empty elements
# future_lapply parallel
dimension = 2:7
future::plan(future::multisession)
result1 = future_lapply(c('euclidean', 'mahalanobis', 'psm'), future.seed=TRUE, FUN=function(m) {
error_ATT(method = m, replace=FALSE, B=100)
})
result2 = future_lapply(dimension, future.seed=TRUE, FUN=function(d) {
error_ATT(method = 'pca', d = d, replace=FALSE, B=100)
})
result3 = future_lapply(dimension, future.seed=TRUE, FUN=function(d) {
error_ATT(method = 'umap', d = d, replace=FALSE, B=100)
})
result1 = do.call(rbind, result1)
result2 = do.call(rbind, result2)
result3 = do.call(rbind, result3)
result = rbind(result1, result2, result3)
write.csv(result, "~/Rdata/Causeffect_Austin123.csv", row.names=F)
result4 = future_lapply(dimension, future.seed=TRUE, FUN=function(d) {
error_ATT(method = 'kdrm', d = d, replace=FALSE, B=100, MMD=MMD)
})
future::plan(future::sequential) # Close process
result4 = do.call(rbind, result4)
result = rbind(result, result4)
write.csv(result, "~/Rdata/Causeffect_Austin.csv", row.names=F)
diftime = proc.time() - start
print(paste("Execution time:", round(diftime[3]/60, 2), "minutes"))