Omega.jl
Omega.jl copied to clipboard
rcd example is slow
The following code from Omega Models is slow for two reasons that need to be fixed.
- We are using samplemean instead of the symbolic mean but in this case we should be able to use symbolic mean
- Even using samplemean it takes a much longer time on my machine (around minutes) than I would expect. Maybe my expectations are wrong or maybe something weird is happening. Need to profile.
using Omega
using Plots
faircoin = bernoulli(0.5, Bool)
headsbiased = bernoulli(0.5, Bool)
function weight_(ω)
weight = if faircoin(ω)
0.5
elseif headsbiased(ω)
0.6
else
0.4
end
end
weight = ciid(weight_)
coin = bernoulli(weight, Bool)
coinrcd = coin ∥ (faircoin, headsbiased)
# Compute the expectation using nsamples
meannsamples = 100000
probdist = Omega.samplemeanᵣ(coinrcd, meannsamples)
# Draw nsamples from the conditional expectation
nsamples = 100
probsamples = [rand(probdist) for i = 1:nsamples]
fig = histogram(probsamples, nbins=100, xlims=[0.0, 1.0], normalize=true, size=(400, 300), label="")
savefig(fig, "coindist.png")