forked from probmods/webppl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scalarImplicature.wppl
48 lines (42 loc) · 1.21 KB
/
scalarImplicature.wppl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var worldPrior = function() {
var num_nice_people = randomInteger(4) //3 people.. 0-3 can be nice.
return num_nice_people
}
var utterancePrior = function() {
var utterances = ['some of the people are nice',
'all of the people are nice',
'none of the people are nice']
var i = randomInteger(utterances.length)
return utterances[i]
}
var meaning = function(utt, world) {
return utt == 'some of the people are nice' ? world > 0 :
utt == 'all of the people are nice' ? world == 3 :
utt == 'none of the people are nice' ? world == 0 :
true
}
var literalListener = cache(function(utterance) {
Enumerate(function() {
var world = worldPrior()
var m = meaning(utterance, world)
factor(m ? 0 : -Infinity)
return world
})
})
var speaker = cache(function(world) {
Enumerate(function() {
var utterance = utterancePrior()
var L = literalListener(utterance)
factor(L.score([], world))
return utterance
})
})
var listener = function(utterance) {
Enumerate(function() {
var world = worldPrior()
var S = speaker(world)
factor(S.score([], utterance))
return world
})
}
listener('some of the people are nice')