using Gadfly, Stochy
@pp function literallistener(utterance)
enum() do
local world = worldprior(),
m = meaning(utterance, world)
factor(m ? 0 : -Inf)
world
end
end
literallistener (generic function with 1 method)
@pp function worldprior()
randominteger(4) - 1
end
worldprior (generic function with 1 method)
@pp function utteranceprior()
local utterances = [
"some of the people are nice",
"all of the people are nice",
"none of the people are nice"]
utterances[randominteger(3)]
end
utteranceprior (generic function with 1 method)
@pp function meaning(utterance, world)
utterance == "some of the people are nice" ? world > 0 :
utterance == "all of the people are nice" ? world == 3 :
utterance == "none of the people are nice" ? world == 0 :
true
end
meaning (generic function with 1 method)
dist = @pp literallistener("some of the people are nice");
plot(dist)
@pp function speaker(world)
enum() do
local utterance = utteranceprior()
#factor(world == sample(literallistener(utterance)) ? 0 : -Inf)
local l = literallistener(utterance)
factor(score(l, world))
utterance
end
end
speaker (generic function with 1 method)
@pp function listener(utterance)
enum() do
local world = worldprior()
#factor(utterance == sample(speaker(world)) ? 0 : -Inf)
local s = speaker(world)
factor(score(s, utterance))
world
end
end
listener (generic function with 1 method)
dist = @pp listener("some of the people are nice");
plot(dist)