Guest User

Untitled

a guest
Nov 20th, 2018
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. //
  2. // Zoo: Infer prevalence of 3 animals after a zoo visit
  3. //
  4. // Observed: 3 lions, 2 tigers and 1 bear
  5. //
  6. // Questions:
  7. // - Prevalence of each species
  8. // - Probability of seeing a bear next time
  9. //
  10.  
  11. var animals = ['lion', 'tiger', 'bear']
  12. var observations = [0, 0, 0, 1, 1, 2]
  13.  
  14. var model = function() {
  15. var b = Dirichlet({alpha: Vector([1, 1, 1])});
  16. var x = sample(b);
  17. //var x = dirichlet(Vector([1, 1, 1]))
  18.  
  19. //var c = Categorical({ps: x, vs: [0, 1, 2]})
  20. //var c = Multinomial({ps: x, n: 6})
  21.  
  22. //var obsFn = function(x) {observe(c, x)}
  23. //mapData({data: observations}, obsFn)
  24.  
  25. return x;
  26. }
  27.  
  28.  
  29. // var g = Infer({method: 'forward', samples: 1000},model);
  30. //var g = Infer({method: 'MCMC', samples: 10000, burn: 2000}, model);
  31. var g = Infer(model);
  32.  
  33. //display(g)
  34.  
  35. viz(g);
Add Comment
Please, Sign In to add comment