Skip to content

Commit ebf3323

Browse files
author
arzwa
committed
Added ConstantDistribution struct
1 parent 77ecf8f commit ebf3323

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/mcmc.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ Base.getindex(x::State, s::Symbol, i::Int64) = x[s][i]
1515
# HACK: for constant parameters
1616
Distributions.logpdf(d::Float64, x::Float64) = 0.
1717

18+
"""
19+
ConstantDistribution(x)
20+
21+
A 'constant' distribution (Dirac mass), sometimes useful.
22+
"""
23+
struct ConstantDistribution{T}
24+
x::T
25+
end
26+
27+
Base.rand(x::ConstantDistribution) = x.x
28+
pdf(x::ConstantDistribution, y) = y x.x ? 1. : 0.
29+
logpdf(x::ConstantDistribution, y) = log(pdf(x, y))
30+
31+
1832
# GBM model
1933
"""
2034
GBMModel(st::SlicedTree, ν::T, η::T, λ::T, μ::T, q::T) where

0 commit comments

Comments
 (0)