Skip to content

Instantly share code, notes, and snippets.

@jhaberstro
jhaberstro / unfair-casino-hmm.js
Created January 25, 2019 07:33
WebPPL Hidden Markov Model Inference
/*
Dealer repeatedly flips a coin. Sometimes the coin is fair, with P(heads) = 0.5,
sometimes it’s loaded, with P(heads) = 0.8. Dealer occasionally switches coins,
invisibly to you. Given an list of observed coin flips, infer if the coin was
fair for each individual flip.
*/
var hmm = function(n, initial, transitionf, observef) {
var impl = function(N) {
if (N > 1) {