Skip to content

Instantly share code, notes, and snippets.

@seantalts
Created August 8, 2017 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seantalts/c4a1de131f5dfc8f5b71c5c54b272617 to your computer and use it in GitHub Desktop.
Save seantalts/c4a1de131f5dfc8f5b71c5c54b272617 to your computer and use it in GitHub Desktop.
dans.rng = function(N_samp, n_eff, planck_length) {
pnorm(rnorm(N_samp, sd=1 + runif(N_samp, -1/sqrt(n_eff), 1/sqrt(n_eff))))
}
discrete.dan = function(N_samp, n_eff, pl) {
round(pnorm(rnorm(N_samp, sd=1 + runif(N_samp, -1/sqrt(n_eff), 1/sqrt(n_eff)))) * pl) / pl
}
linear_neff_plots = function(xlab, gen_data, n_samp, n_eff, planck_length) {
data = gen_data(n_samp, n_eff, planck_length)
bins <- n_eff * c(0.5, 1, 2, 3, 10, 50)
par(mfrow=c(3, 2))
#par(mar=c(4,2,2,1)+0.1)
for (num_bins in bins) {
label = paste0(#"N_samp: ", n_samp,
" n_eff:", n_eff,
" bins: n_eff*", num_bins / n_eff)
hist(data, breaks = num_bins, main=label, xlab=xlab)
}
}
sqrt_neff_plots = function(xlab, gen_data, n_samp, n_eff, planck_length) {
data = gen_data(n_samp, n_eff, planck_length)
bins <- sqrt(n_eff) * c(1, 2, 3, 5, 10, 20)
bins = bins[bins > 1]
par(mfrow=c(3, 2))
#par(mar=c(4,2,2,1)+0.1)
for (num_bins in bins) {
label = paste0(#"N_samp: ", n_samp,
", n_eff:", n_eff,
", bins: sqrt(n_eff)*", num_bins / sqrt(n_eff),
", pl: ", planck_length)
hist(data, breaks = num_bins, main=label, xlab=xlab)
}
}
pdf("linear_n_eff.pdf")
linear_neff_plots("Dan's RNG", dans.rng, 1e5, 26, 1000)
for (i in c(1e3, 1e4, 1e5)) {
linear_neff_plots("Discretized Dan RNG", discrete.dan, 1e5, 26, i)
}
for (i in c(100, 1e3, 1e4)) {
linear_neff_plots("Discretized Dan RNG", discrete.dan, 1e5, i, 1000)
}
dev.off()
pdf("sqrt_n_eff.pdf")
sqrt_neff_plots("Dan's RNG", dans.rng, 1e5, 26, 1000)
for (i in c(1e3, 1e4, 1e5)) {
sqrt_neff_plots("Discretized Dan RNG", discrete.dan, 1e5, 26, i)
}
for (i in c(100, 1e3, 1e4)) {
sqrt_neff_plots("Discretized Dan RNG", discrete.dan, 1e5, i, 1000)
}
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment