Open marcoct opened 3 years ago
@femtomc I wonder if it might be worth making a generalized truncated
operation, similar to: https://juliastats.org/Distributions.jl/stable/truncate/
We could do a fallback implementation like:
function _logpdf(d::Truncated, x::T) where {T<:Real}
if d.lower <= x <= d.upper
logpdf(d.untruncated, x) - d.logtp
else
TF = float(T)
-TF(Inf)
end
end
and specialized implementations for common truncated distributions like the truncated normal.
I was discussing this a bit with Alex -- will comment in a bit.
I agree with your comment. Basically, start with truncated normal. As we build more, you can specialize and have a function truncate
which mimics the Distributions.jl
method truncated
.
I was actually thinking the other way round! But I realized on further thought that a fallback implementation won't be as easy, just because we don't equip Gen distributions with CDFs like Distributions.jl does, and that means we can't calculate d.logtp
for every distribution easily.
I'll take a swing at this today. Looks cool.