-
Notifications
You must be signed in to change notification settings - Fork 0
/
xiaolinzhuo_1router_all_times_uniform.R
72 lines (51 loc) · 1.43 KB
/
xiaolinzhuo_1router_all_times_uniform.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
### stat221 problem set 4
### Xiaolin Zhuo
library(coda)
library(networkTomography)
source("xiaolinzhuo_mcmc.R")
# get time point (== slurm job task ID)
t <- as.integer(Sys.getenv('SLURM_ARRAY_TASK_ID'))
t
# read data
#dat <- read.csv("1router_allcount.dat")
data(bell.labs)
A <- bell.labs$A
reorder <- qr(A)$pivot
matX <- bell.labs$X # OD flows in matrix form
matY <- bell.labs$Y # link loads in matrix form
r <- nrow(A)
c <- ncol(A)
# use data from time point t
Y <- matY[t, ]
# draw ten chains
dataX <- NA
dataL <- NA
for (i in 1:10) {
print(paste("chain", i))
set.seed(i)
#res <- network_mcmc(Y, A, list(a=0, b=0))
res <- twMCMC(Y, A, list(a=0, b=0))
# combine chains
if (is.na(dataX)) {
dataX <- res[["XDraws"]]
dataL <- res[["lambdaDraws"]]
} else {
dataX <- rbind(dataX, res[["XDraws"]])
dataL <- rbind(dataL, res[["lambdaDraws"]])
}
print("========")
}
output <- matrix(NA, nrow=c, ncol=6)
for (j in 1:c) {
print(j)
sum(is.na(dataX[, j]))
sum(is.na(dataL[, j]))
output[j, ] <- c(median(dataX[, j], na.rm=T),
quantile(dataX[, j], 0.025, na.rm=T),
quantile(dataX[, j], 0.975, na.rm=T),
median(dataL[, j], na.rm=T),
quantile(dataL[, j], 0.025, na.rm=T),
quantile(dataL[, j], 0.975, na.rm=T))
print("======")
}
write.csv(output, paste("uniform_time_", t, "_output.csv", sep=""), row.names=F)