Expectations.jl
Expectations.jl copied to clipboard
[feature request] Generic fallback for non-supported distributions ?
It would be neat if there was a generic fallback for non-supported distributions. I can come up with a simple solution for continuous distributions:
# fallback for UnivariateContinuousDistribution
import Cubature
pcubature(x * Distributions.pdf(X,x), minimum(X), maximum(X))
but i need to think a bit more for discrete infinite supports.
Edit: There is ageneric fallback in Distributions.jl
implemented there: https://github.com/JuliaStats/Distributions.jl/blob/master/src/functionals.jl
So maybe this is just an interface issue, Expectations.jl
should not throw when it does not know the distribution but simply use the Distributions.jl one. Thanks @devmotion for the link.
Currently we have https://github.com/QuantEcon/Expectations.jl/blob/9b99daf98db7b2ec37a8df74a567237bd15325a6/src/iterable.jl#L81, which falls back to Gauss-Legendre for continuous distributions that lack a specified method.
If we're throwing an error instead of using it, that's definitely a mistake. (Though IMO there should be a warning.) I'll look into it.
(There is also https://github.com/QuantEcon/Expectations.jl/blob/9b99daf98db7b2ec37a8df74a567237bd15325a6/src/iterable.jl#L116, which integrates over a uniform quantile grid.)
I think this is the method I hitted : https://github.com/QuantEcon/Expectations.jl/blob/c36874e6578b814b66aee0c17fb4ce0a7c514805/src/iterable.jl#L96-L108
In particular with the Pareto case. While Distributions.jl
's expectation method handles these cases (infinite support) without any issue.