Skip to content

Instantly share code, notes, and snippets.

@usptact usptact/second_tallest
Last active Oct 11, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.