Skip to content

Commit 635d730

Browse files
authored
latent etc (#72)
* latent etc * include latent-joint * update jointof * docstring * bump version
1 parent 1d04e2f commit 635d730

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MeasureBase"
22
uuid = "fa1605e6-acd5-459c-a1e6-7e635759db14"
33
authors = ["Chad Scherrer <[email protected]> and contributors"]
4-
version = "0.12.1"
4+
version = "0.12.2"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/MeasureBase.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ include("standard/stdmeasure.jl")
127127
include("standard/stduniform.jl")
128128
include("standard/stdexponential.jl")
129129
include("standard/stdlogistic.jl")
130+
include("latent-joint.jl")
130131

131132
include("rand.jl")
132133

src/latent-joint.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)