Hi! I want to define a MixtureModel
in which the component distributions might be from different families. While this piece of code works, the code is type unstable:
using Distributions
mixture = MixtureModel([Normal(-2, 1), TDist(2), Normal(2, 1)])
@code_warntype logpdf(mixture, 1.0)
and the output is
MethodInstance for Distributions.logpdf(::MixtureModel{Univariate, Continuous, Distribution{Univariate, Continuous}, Categorical{Float64, Vector{Float64}}}, ::Float64)
from logpdf(d::UnivariateMixture, x::Real) in Distributions at /Users/leevi/.julia/packages/Distributions/O5xl5/src/mixtures/mixturemodel.jl:363
Arguments
#self#::Core.Const(Distributions.logpdf)
d::MixtureModel{Univariate, Continuous, Distribution{Univariate, Continuous}, Categorical{Float64, Vector{Float64}}}
x::Float64
Body::Any
1 ─ %1 = Distributions._mixlogpdf1(d, x)::Any
└── return %1
When the components are from the same family, there is no problem:
mixture = MixtureModel([Normal(-2, 1), Normal(0, 1), Normal(2, 1)])
@code_warntype logpdf(mixture, 1.0)
Are there any workarounds for this?