Skip to content

Commit b059ee2

Browse files
committed
rand for Affine measures
1 parent 68b8552 commit b059ee2

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/combinators/affine.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct Affine{N,M,T} <: AbstractMeasure
2222
parent::M
2323
end
2424

25+
parent(d::Affine) = getfield(d, :parent)
26+
2527
Affine(nt::NamedTuple, μ::AbstractMeasure) = Affine(AffineTransform(nt), μ)
2628

2729
Affine(nt::NamedTuple) = μ -> Affine(nt, μ)
@@ -36,6 +38,8 @@ Base.propertynames(d::Affine{N}) where {N} = N ∪ (:parent,)
3638
end
3739
end
3840

41+
42+
3943
# Note: We could also write
4044
# logdensity(d::Affine, x) = logdensity(inv(getfield(d, :f)), x)
4145

@@ -57,3 +61,9 @@ logjac(::AffineTransform{(:μ,:ω)}) = log(d.ω)
5761
logjac(::AffineTransform{(:σ,)}) = -log(d.σ)
5862
logjac(::AffineTransform{(:ω,)}) = log(d.ω)
5963
logjac(::AffineTransform{(:μ,)}) = 0.0
64+
65+
function Base.rand(rng::Random.AbstractRNG. ::Type{T}, d::Affine) where {T}
66+
z = rand(rng, T, parent(d))
67+
f = getfield(d, :f)
68+
return f(z)
69+
end

0 commit comments

Comments
 (0)