In [1]:
using Stochy, Gadfly, Stochy.GadflySupport
In [2]:
@pp function literallistener(utterance)
    enum() do
        local world = worldprior(),
              m = meaning(utterance, world)
        factor(m ? 0 : -Inf)
        world
    end
end
Out[2]:
literallistener (generic function with 1 method)
In [3]:
@pp function worldprior()
    randominteger(4) - 1
end
Out[3]:
worldprior (generic function with 1 method)
In [4]:
@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
Out[4]:
utteranceprior (generic function with 1 method)
In [5]:
@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
Out[5]:
meaning (generic function with 1 method)
In [6]:
dist = @pp literallistener("some of the people are nice");
In [7]:
bar(dist)
Out[7]:
x 0 1 2 3 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 -1 0 1 2 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 p(x)
In [8]:
@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
Out[8]:
speaker (generic function with 1 method)
In [9]:
@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
Out[9]:
listener (generic function with 1 method)
In [10]:
dist = @pp listener("some of the people are nice");
In [11]:
bar(dist)
Out[11]:
x 0 1 2 3 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5 -1.00 -0.95 -0.90 -0.85 -0.80 -0.75 -0.70 -0.65 -0.60 -0.55 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 1.05 1.10 1.15 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.80 1.85 1.90 1.95 2.00 -1 0 1 2 -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 p(x)
In [11]: