StackOverflowError when fitting data to a von Mises distribution

Hi everyone.

I’m trying to use Turing.jl to fit data to a von Mises circular distribution, and I am having some “stack overflow” issues during the fitting.

This is my (very simple) code (coin flip adaptation):

using Turing
using Distributions

μ = 0; κ = 517
vm = VonMises(μ, κ)
data = rand(vm, 100)

@model model(x) = begin
    μ ~ Normal(0, 10)
    κ ~ Uniform(450, 550)
    N = length(x)
    for n in 1:N
        x[n] ~ VonMises(μ, κ)
    end
end

ϵ = 0.05
τ = 10
iterations = 1000

chain = sample(model(data), HMC(ϵ, τ), iterations, progress=false)

The error is “StackOverflowError: in besselix at SpecialFunctions/LC8dm/src/bessel.jl:583”

Thank you very much in advance.

This is a known issue https://github.com/TuringLang/DistributionsAD.jl/blob/bc0ab9ae3f8754c2beb1fa5cf4d7265a26e625a1/test/ad/distributions.jl#L220. One fix is to have a pure Julia implementation of the besselix function.

1 Like

If you are up for the task, check this https://github.com/JuliaMath/SpecialFunctions.jl/blob/cf85c05f2c7b77cec2d0ca23209d4c780eaa4c52/docs/src/functions_overview.md#bessel-functions.

1 Like

Hi Mohamed.

Thank you very much for your quick answer. I didn’t know about the issue (absolute beginner in Julia). I shall take a look to the references you sent to me.

Many thanks again.

1 Like

Hi,

I’d also be very interested in getting von Mises distributions distributions working.

When you say a pure Julia function is needed, are there any specific requirements for that? Would a straight conversion of netlib.org/amos/zbesi.f and associated functions be suitable, or does it have to match a technique already used in SpecialFunctions?

Thanks.

1 Like