Skip to content

Instantly share code, notes, and snippets.

@zenna
Created September 23, 2019 22:19
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 zenna/5f9deffa5dcd271fad2c784a6355582f to your computer and use it in GitHub Desktop.
Save zenna/5f9deffa5dcd271fad2c784a6355582f to your computer and use it in GitHub Desktop.
using Omega
# Beta distributed random variables in [0, 1]
p1 = beta(0.5)
pgood = beta(0.5)
pbad = beta(0.5)
# Function that simulates the car
function simulate_car(ω)
car_is_good = Bernoulli(ω, p1(ω), Bool)
cuts_you_off = ifelse(prob_car_is_good, Bernoulli(ω, pgood(ω), Bool), Bernoulli(ω, pbad, Bool))
drive_sim = some_function(car_is_good, cuts_you_off)
return drive_sim
end
# n data points
N = 10
# Random variable over vector of drive_sim
simulations = rv(ω -> [simulate_car_(ω) for i = 1:n])
# Data
data = ...
# Posterior of pgood, pbad, p1
rand(cond((pgood, pbad, p1), data == simulations))
# Is it better (does variance decrease)
var(cond(pbad, data == simulations)) - var(cond(pbad, (data == simulations) & pgood > pbad))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment