Skip to content

Commit 16fceea

Browse files
committed
Add distribution wrappers from Turing
1 parent 4d80d02 commit 16fceea

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/DynamicPPL.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ include("selector.jl")
9090
include("model.jl")
9191
include("sampler.jl")
9292
include("varname.jl")
93+
include("distribution_wrappers.jl")
9394
include("contexts.jl")
9495
include("varinfo.jl")
9596
include("compiler.jl")

src/distribution_wrappers.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Distributions:
2+
3+
"""
4+
A named distribution that carries the name of the random variable with it.
5+
"""
6+
struct NamedDist{
7+
variate,
8+
support,
9+
Td <: Distribution{variate, support},
10+
Tn
11+
} <: Distribution{variate, support}
12+
dist::Td
13+
name::Tn
14+
end
15+
16+
17+
struct NoDist{
18+
variate,
19+
support,
20+
Td <: Distribution{variate, support}
21+
} <: Distribution{variate, support}
22+
dist::Td
23+
end
24+
NoDist(dist::NamedDist) = NamedDist(NoDist(dist.dist), dist.name)
25+
26+
Distributions.rand(d::NoDist) = rand(d.dist)
27+
Distributions.logpdf(d::NoDist{<:Univariate}, ::Real) = 0
28+
Distributions.logpdf(d::NoDist{<:Multivariate}, ::AbstractVector{<:Real}) = 0
29+
function Distributions.logpdf(d::NoDist{<:Multivariate}, x::AbstractMatrix{<:Real})
30+
return zeros(Int, size(x, 2))
31+
end
32+
Distributions.logpdf(d::NoDist{<:Matrixvariate}, ::AbstractMatrix{<:Real}) = 0
33+
Bijectors.logpdf_with_trans(d::NoDist{<:Univariate}, ::Real) = 0
34+
Bijectors.logpdf_with_trans(d::NoDist{<:Multivariate}, ::AbstractVector{<:Real}) = 0
35+
function Bijectors.logpdf_with_trans(d::NoDist{<:Multivariate}, x::AbstractMatrix{<:Real})
36+
return zeros(Int, size(x, 2))
37+
end
38+
Bijectors.logpdf_with_trans(d::NoDist{<:Matrixvariate}, ::AbstractMatrix{<:Real}) = 0

0 commit comments

Comments
 (0)