-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_visualize_convergence.R
executable file
·78 lines (60 loc) · 2.21 KB
/
run_visualize_convergence.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
#! /usr/local/bin/Rscript --vanilla
require(xtable)
# require(modeest) # Venter mode estimation
Rcpp::sourceCpp('sampler/lib/VenterMode.cpp')
Rcpp::sourceCpp('sampler/lib/VenterModeCirc.cpp')
source('configuration.R')
source('visualization.R')
source('sampler/circular_sampler.R')
source('helpers.R')
load("scenarios/three_components.RData")
pdf(file="figures/convergence.pdf", width=6, height=3)
indices <- 6006:6010
for (index in indices) {
scenario <- scenarios[[index]]
set.seed(scenario$seed)
data <- circular(SimulateParams(scenario, n=scenario$n), template="clock24")
load(paste0("results/", scenario$name, "-", index, ".RData"))
output <- results
ExpandOutput(output)
log.likelihoods <- sapply(output, function(sample) {
LogLikelihood(sample, data)
})
log.priorprobabilities <- sapply(output, function(sample) {
LogPriorProbability(sample, data)
})
log.posterior <- log.likelihoods + log.likelihoods
range <- 1:(burnin+iterations)
par(mar=c(3, 5, 1, 1))
if (index == indices[1]) {
plot(range, log.posterior[range], type='l', col=custom.colors[[which(index == indices)]], ylim=c(-10^5, 0), xlab=NA, ylab="Log posterior probability")
} else {
lines(range, log.posterior[range], col=custom.colors[[which(index == indices)]])
}
}
dev.off()
pdf(file="figures/convergence_zoomed.pdf", width=6, height=3)
indices <- 6006:6010
for (index in indices) {
scenario <- scenarios[[index]]
set.seed(scenario$seed)
data <- circular(SimulateParams(scenario, n=scenario$n), template="clock24")
load(paste0("results/", scenario$name, "-", index, ".RData"))
output <- results
ExpandOutput(output)
log.likelihoods <- sapply(output, function(sample) {
LogLikelihood(sample, data)
})
log.priorprobabilities <- sapply(output, function(sample) {
LogPriorProbability(sample, data)
})
log.posterior <- log.likelihoods + log.likelihoods
range <- (10^4):(1.5*10^4)
par(mar=c(3, 5, 1, 1))
if (index == indices[1]) {
plot(range, log.posterior[range], type='l', col=custom.colors[[which(index == indices)]], ylim=c(-8000, -4000), xlab=NA, ylab="Log posterior probability")
} else {
lines(range, log.posterior[range], col=custom.colors[[which(index == indices)]])
}
}
dev.off()