Distributions.jl extension

Hi,

I’m trying to code an extension of the Distributions.jl to add my own distribution, a convolution of N gammas, for which there exists an efficient algorithm for exact pdf / cdf computations.

I wrote a bunch of code, and i’m now trying to test it. For the moment it complaints about

MethodError: no method matching rand(::Random._GLOBAL_RNG, ::Exponential{Float64})

Edit :

I get why, i was making a mistake in the way i implemented the RNG. The documentaiton is quite outdated, this Implementing a custom Sampler in Distributions.jl - #2 by contradict solved it.

Just change rand into
Base.rand(rng::Distributions.AbstractRNG, s::UnivariateGammaConvolutionSampler) = sum(rand.(rng,s.samplers))

julia> dist = UnivariateGammaConvolution([1,2],[1,2])
UnivariateGammaConvolution{Float64}(
α: [1.0, 2.0]
θ: [1.0, 2.0]
P: MoschopoulosParameters{Float64}(1.0, 4.0, [0.0, 0.5], [1.0], 3.0, [1.0])
)

julia> rand(dist)
4.209602393629504

Yeah that works too ! We should update the documentation.

1 Like