Last active
December 17, 2017 17:39
-
-
Save chagag/ab6f488b7b2f6b90cebaf5a280227020 to your computer and use it in GitHub Desktop.
Bayesian model of categorization
This file contains hidden or 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
var data = {self: 1, group : [5,5,6,7,8,9]} | |
var model = function(){ | |
// uninformative prior over group beliefs | |
var groupMean = uniform(0,10) //prior | |
var groupSd = uniform(0,10) //prior | |
var belong = flip() //prior | |
// estimate groupmean and sd considering the group | |
mapData({data: data.group}, function(datum){ | |
observe(Gaussian({mu: groupMean, sigma: groupSd}), datum) | |
}) | |
// use group dist as true emotion prior if you belong; otherwise uninformative | |
var groupDist = (belong ? | |
Gaussian({mu: groupMean, sigma: groupSd}) : | |
Uniform({a: 0, b: 10})) | |
// data about self is noisy observation from group distribution | |
observe(Gaussian({mu:sample(groupDist), sigma: groupSd}), data.self) | |
// return beliefs about both the group and the self, so we can compare | |
return (belong) | |
} | |
var posterior = Infer({method:'MCMC', samples: 1000, lag: 100, burn: 5},model) | |
print('probability of belong: ' + expectation(posterior)) | |
viz(posterior) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment