-
-
Save usptact/263f63f0af1bc41fb7d7ddc7e5e6123c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Zoo: Infer prevalence of 3 animals after a zoo visit | |
// | |
// Observed: 3 lions, 2 tigers and 1 bear | |
// | |
// Questions: | |
// - Prevalence of each species | |
// - Probability of seeing a bear next time | |
// | |
var animals = ['lion', 'tiger', 'bear'] | |
var observations = ['lion', 'lion', 'lion', 'tiger', 'tiger', 'bear'] | |
var model = function() { | |
// set Dirichlet prior | |
var a = [uniform(0,5), uniform(0,5), uniform(0,5)] | |
var p = dirichlet(Vector(a)) | |
// set Categorical distribution | |
var cdist = Categorical({ps: p, vs: animals}) | |
// observe every data point | |
var obsFn = function(x) {observe(cdist, x)} | |
mapData({data: observations}, obsFn) | |
// get animal prevalencies | |
return {p_lion: p.data[0], p_tiger:p.data[1], p_bear:p.data[2]}; | |
} | |
var g = Infer({method: 'MCMC', samples: 1000000, burn: 5000}, model); | |
viz.marginals(g); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment