Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 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 = [0, 0, 0, 1, 1, 2]
- var model = function() {
- var b = Dirichlet({alpha: Vector([1, 1, 1])});
- var x = sample(b);
- //var x = dirichlet(Vector([1, 1, 1]))
- //var c = Categorical({ps: x, vs: [0, 1, 2]})
- //var c = Multinomial({ps: x, n: 6})
- //var obsFn = function(x) {observe(c, x)}
- //mapData({data: observations}, obsFn)
- return x;
- }
- // var g = Infer({method: 'forward', samples: 1000},model);
- //var g = Infer({method: 'MCMC', samples: 10000, burn: 2000}, model);
- var g = Infer(model);
- //display(g)
- viz(g);
Add Comment
Please, Sign In to add comment