Skip to content

Instantly share code, notes, and snippets.

@usptact
Last active October 11, 2018 04:55
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 usptact/5cb049452a0acc8d8c6801ce53c30e2d to your computer and use it in GitHub Desktop.
Save usptact/5cb049452a0acc8d8c6801ce53c30e2d to your computer and use it in GitHub Desktop.
var person = function() {
var is_female = sample(Bernoulli({p: 0.51}))
if (is_female == false) {
return {hgt: sample(Gaussian({mu: 178.0, sigma: 7.7})), is_female: is_female}
} else {
return {hgt: sample(Gaussian({mu: 163.0, sigma: 7.3})), is_female: is_female}
}
}
var is_taller = function(h1, h2) {
return h1 > h2 ? true : false
}
var model = function() {
var p1 = person()
var p2 = person()
var p3 = person()
var p4 = person()
var p5 = person()
var p6 = person()
var p7 = person()
var p8 = person()
var p9 = person()
var p10 = person()
condition(is_taller(p1.hgt, p2.hgt) == true)
condition(is_taller(p2.hgt, p3.hgt) == true)
condition(is_taller(p3.hgt, p4.hgt) == true)
condition(is_taller(p4.hgt, p5.hgt) == true)
condition(is_taller(p5.hgt, p6.hgt) == true)
condition(is_taller(p6.hgt, p7.hgt) == true)
condition(is_taller(p7.hgt, p8.hgt) == true)
condition(is_taller(p8.hgt, p9.hgt) == true)
condition(is_taller(p9.hgt, p10.hgt) == true)
return p2
}
var dist = Infer({method: 'MCMC', kernel: 'MH', samples: 100000}, model)
//display(expectation(dist.h))
//display(dist.f)
viz.marginals(dist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment