Last active
November 23, 2016 20:59
-
-
Save chagag/2b165ab59f9336afc0d0b3f9f06b6f84 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
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 | |
// observe | |
// estimate groupmean and sd considering the group | |
mapData({data: data.group}, function(datum) | |
{observe(Gaussian({mu: groupMean, sigma: groupSd}), datum)}) | |
// true emotion is generated from the group dist | |
var trueEmotion = Gaussian({mu: groupMean, sigma: groupSd}) | |
observe (trueEmotion, data.self) | |
// return beliefs about both the group and the self, so we can compare | |
var response = sample(trueEmotion) | |
condition(response < 10 && response > 0) | |
return {group: groupMean, response: response} | |
} | |
var posterior = Infer({method:'MCMC', samples: 500, lag: 50, burn: 5},model) | |
viz(posterior) | |
viz.marginals(posterior) |
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
//Estimating group mean based on a sample | |
//the prior is a uniform distribution participants assume that the mean and standard deviation were taken from a gaussian dist. | |
//They estimate the mean of that distribution. | |
var groupEmotions = [5,3,5,6,7] | |
var model = function(){ | |
var gaussianMean = uniform(0,10) //prior | |
var guassianSd = uniform(0, 10) //prior | |
var obsFn = function(datum){ observe(Gaussian({mu: gaussianMean, | |
sigma: guassianSd}), datum) } | |
mapData({data: groupEmotions}, obsFn) | |
return gaussianMean | |
} | |
// an alternative option var obsFn = function(datum){ condition( sample(gaussian(..,..) == datum ) } | |
var estimateColEmotion = Infer({method:'MCMC', samples: 100, lag: 100, burn: 5},model) | |
print('Expected average is: ' + expectation(estimateColEmotion)) | |
expectation(estimateColEmotion) | |
viz(estimateColEmotion) | |
// estimating the group emotion from the individual emotion | |
//By merely assuming a uniform distribution on the prior the system tends to assume that an extreme participant is biased. | |
var indivEmotion = [8] | |
var model = function(){ | |
var gaussianMean = uniform(0,10) //prior | |
var gaussianSd = uniform(0, 10) //prior | |
var obsFn = function(datum){ observe(Gaussian({mu: gaussianMean, | |
sigma: gaussianSd}), datum) } | |
mapData({data: indivEmotion}, obsFn) | |
return gaussianMean | |
} | |
var estimateColEmotion = Infer({method:'MCMC', samples: 100, lag: 100, burn: 5},model) | |
print('Expected average is: ' + expectation(estimateColEmotion)) | |
expectation(estimateColEmotion) | |
viz(estimateColEmotion) |
This is really close to what we talked about!
The main difference is that rather than just using the (inferred) group distribution as a prior for your own observation, you assume your data is a noisy observation of the true emotion. See below for the slightly refactored version of this model. I also added in uncertainty over whether you belong to the group or not, which I think might be needed to get that phenomenon of drift toward/away from the group.
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
// 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 belong = flip()
var trueEmotionPrior = (belong ?
Gaussian({mu: groupMean, sigma: groupSd}) :
Uniform({a: 0, b: 10}))
// data about self is noisy observation from true emotion prior
var trueEmotion = sample(trueEmotionPrior);
condition(trueEmotion < 10 && trueEmotion > 0)
observe(Gaussian({mu: trueEmotion, sigma: 1}), data.self)
// return beliefs about both the group and the self, so we can compare
return {groupMean, trueEmotion, belong}
}
var posterior = Infer({method:'MCMC', samples: 1000, lag: 100, burn: 5},model)
viz.marginals(posterior)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome! I think the trick to get an individual emotion from the group is to build it all into a single model. Basically, instead of just returning beliefs about the group mean, you want to also return the individual's belief about themselves. This is where your theory about a person's bias goes (I called it "decisionRule" in the code below, and instantiate a naive function where you're one standard deviation toward the extreme from the inferred group mean)