# Possible bug in VonMisesDistribution?

Bug introduced in 10.2 or earlier and fixed in 10.3

Observe:

FullSimplify[PDF[VonMisesDistribution[μ, 0], x], -π + μ <= x <= π + μ] ==
FullSimplify[PDF[UniformDistribution[{μ - π, μ + π}], x], -π + μ <= x <= π + μ]

(* True *)

SeedRandom[1]
RandomVariate@UniformDistribution[{0 - π, 0 + π}]
RandomVariate@VonMisesDistribution[0, 0]


1.99422

CompiledFunction::cfn: Numerical error encountered at instruction 19; proceeding with uncompiled evaluation. >>

Power::infy: Infinite expression 1/0 encountered. >>

Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>

at which point it just hangs, never completing.

This appears to be for any mean with concentration 0.

• Your first line can be written more simply as Simplify[PDF[VonMisesDistribution[\[Mu], 0], x] == PDF[UniformDistribution[{\[Mu] - \[Pi], \[Mu] + \[Pi]}], x], -\[Pi] + \[Mu] <= x <= \[Pi] + \[Mu]] – Bob Hanlon Aug 6 '15 at 6:33
• If memory serves, the method used internally is the rejection method of Best and Fisher; if you'll look through their algorithm, they implicitly make the assumption that $\kappa$ is positive. So, their algorithm will not work in your case, and there should have been a separate internal handler for $\kappa=0$. – J. M. will be back soon Aug 6 '15 at 13:35
• This is indeed a bug. We're looking into it. – Stefan R Aug 6 '15 at 19:42

To me this looks like a bug. A possible workaround is to use ProbabilityDistribution together with the PDF of the VonMisesDistribution:

SeedRandom[1]
RandomVariate@ProbabilityDistribution[PDF[VonMisesDistribution[0, 0], x], {x, -∞, ∞}]


$\$ 1.99422

This bug is caused by the evaluation of

StatisticsNormalDistributionsDumpcompiledvonmisesrandom[0, 0, 1]

• As noted in WRI comment, it is indeed a bug. – ciao Aug 6 '15 at 20:16
• Oops - forgot to upvote you, +1 – ciao Aug 6 '15 at 20:41

As noted in the comment by WRI staff, this is indeed a bug in the interplay between RandomVariate and the distribution at hand.

The obvious workaround for now is to use

UniformDistribution[{μ - Pi, μ + Pi}]


for zero-concentration cases.

• If I got it correct RandomVariate@VonMisesDistribution[0, 0] will call StatisticsNormalDistributionsDumpcompiledvonmisesrandom[0, 0, 1] and if you have a look into that, you'll find things like (2*kappa)^(-1). – Karsten 7. Aug 6 '15 at 21:45
• @Karsten7.: yep - I titled it with the dist and not RandomVariate since it seems to me it's the specific "hooks" for the dist that have boo-boos... I just used Block in the piece of code affected for me and gave a downvalue for VMD with zero concentration that evaluates to the uniform. – ciao Aug 6 '15 at 22:08
• @Karsten, then yes, they are indeed using Best-Fisher. As noted, it can't handle $\kappa=0$. – J. M. will be back soon Aug 7 '15 at 0:42