|
| 1 | +_LATENT_DOCSTRING = """ |
| 2 | +Some Probabilistic Programming Languages (PPLs) like Tilde.jl make a distinction |
| 3 | +between a _latent space_, often a namespace represented as a named tuple, and |
| 4 | +the space containing the return value, which we refer to as the _maifest space_. |
| 5 | +The distinction is that computations are done in terms of the latent space, |
| 6 | +while the resulting value is in the manifest space. |
| 7 | +
|
| 8 | +To simplify many manipulations involving these concepts, we introduce the |
| 9 | +concept of a _joint space_. For example, suppose `m()` is a measure with latent |
| 10 | +space `NamedTuple{(:a, :b)}` that returns `a - b`, so the latent value `(a = 3, |
| 11 | +b = 4)` is mapped to the manifest value `0.75`. Then the corresponding value in |
| 12 | +the joint space is the pair `(a = 3, b = 4) => 0.75`. |
| 13 | +
|
| 14 | +One of the many goals of probabilistic programming is to blur the line between |
| 15 | +"built in" measures like `Normal()` and those defined in terms of a model from a |
| 16 | +PPL. To accommodate this, we extend these concepts to general measures. |
| 17 | +
|
| 18 | +For many measures, it's convenient to work directly in the manifest space, and |
| 19 | +there's no need for such separation. However, it's important to be able to |
| 20 | +manipulate measures programmatically, with minimal special cases. Because of |
| 21 | +this, we introduce fall-back methods |
| 22 | +
|
| 23 | + latentof(m) = m |
| 24 | + manifestof(m) = m |
| 25 | +
|
| 26 | +The default implementation of `jointof` is then a push-forward through the |
| 27 | +function `x -> (x => x)`. For example, |
| 28 | +
|
| 29 | + julia> rand(MeasureBase.jointof(StdUniform())) |
| 30 | + 0.346439=>0.346439 |
| 31 | +""" |
| 32 | + |
| 33 | +""" |
| 34 | + latentof(m) |
| 35 | +
|
| 36 | +$_LATENT_DOCSTRING |
| 37 | +""" |
| 38 | +latentof(m) = m |
| 39 | + |
| 40 | +""" |
| 41 | + manifestof(m) |
| 42 | +
|
| 43 | +$_LATENT_DOCSTRING |
| 44 | +""" |
| 45 | +manifestof(m) = m |
| 46 | + |
| 47 | +""" |
| 48 | + jointof(m) |
| 49 | +
|
| 50 | +$_LATENT_DOCSTRING |
| 51 | +""" |
| 52 | +function jointof(m) |
| 53 | + fwd(x) = x => x |
| 54 | + |
| 55 | + function back(p::Pair) |
| 56 | + x,y = p |
| 57 | + @assert x === y |
| 58 | + return x |
| 59 | + end |
| 60 | + |
| 61 | + PushforwardMeasure(fwd, back, m, NoVolCorr()) |
| 62 | +end |
0 commit comments