Skip to content

Commit

Permalink
Improve Likelihood ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
oschulz committed Sep 15, 2024
1 parent 1713b77 commit c3fb38f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/combinators/likelihood.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ struct Likelihood{K,X} <: AbstractLikelihood
k::K
x::X

Likelihood(k::K, x::X) where {K,X} = new{K,X}(k, x)
#!!!!!!!!!!! # For type stability if `K isa UnionAll (e.g. a parameterized MeasureType)`
Likelihood(::Type{K}, x::X) where {K<:AbstractMeasure,X} = new{K,X}(K, x)
Likelihood{K,X}(k, x) where {K,X} = new{K,X}(k, x)
end

# For type stability, in case k is a type (resp. a constructor):
Likelihood(k, x::X) where {X} = Likelihood{Core.Typeof(k),X}(k, x)

(lik::AbstractLikelihood)(p) = exp(ULogarithmic, logdensityof(lik.k(p), lik.x))

DensityInterface.DensityKind(::AbstractLikelihood) = IsDensity()
Expand Down

0 comments on commit c3fb38f

Please sign in to comment.