Open
Description
I noticed that Truncated distributions generally don't support mean, var, etc. But they could easily be calculated using numerical methods. In fact, I wrote my own custom module for them:
function numeric_mean( Dist::ContinuousUnivariateDistribution )
(LB, UB) = extrema(Dist)
F(x) = x*pdf(Dist,x)
return quadgk(F, LB, UB)[1]
end
function numeric_mean( Dist::DiscreteUnivariateDistribution )
(LB, UB) = extrema(Dist)
F(x) = x*pdf(Dist,x)
ϵ = 1E-9
#Ensure loop is finite
if !isfinite(LB)
LB = quantile(Dist, ϵ)
end
if !isfinite(UB)
UB = quantile(Dist, 1-ϵ)
end
#Loop through and numerically calculate the mean
y = 0.0
for x in LB:UB
y += F(x)
end
return y
end
I'm wondering why this sort of method (numeric_mean) isn't used as a fallback for the mean truncated distributions? I tried to extend "mean" myself, but it doesn't seem to work smoothly; I get errors and there's possible issues around type piracy. If performance is an issue, would it not be enough to give a warning that a numerical method is being used as an approximation?
Metadata
Metadata
Assignees
Labels
No labels