10
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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]] $\endgroup$ – Bob Hanlon Aug 6 '15 at 6:33
  • 2
    $\begingroup$ 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$. $\endgroup$ – J. M. will be back soon Aug 6 '15 at 13:35
  • 2
    $\begingroup$ This is indeed a bug. We're looking into it. $\endgroup$ – Stefan R Aug 6 '15 at 19:42
7
$\begingroup$

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

Statistics`NormalDistributionsDump`compiledvonmisesrandom[0, 0, 1]
$\endgroup$
  • $\begingroup$ As noted in WRI comment, it is indeed a bug. $\endgroup$ – ciao Aug 6 '15 at 20:16
  • $\begingroup$ Oops - forgot to upvote you, +1 $\endgroup$ – ciao Aug 6 '15 at 20:41
4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ If I got it correct RandomVariate@VonMisesDistribution[0, 0] will call Statistics`NormalDistributionsDump`compiledvonmisesrandom[0, 0, 1] and if you have a look into that, you'll find things like (2*kappa)^(-1). $\endgroup$ – Karsten 7. Aug 6 '15 at 21:45
  • $\begingroup$ @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. $\endgroup$ – ciao Aug 6 '15 at 22:08
  • $\begingroup$ @Karsten, then yes, they are indeed using Best-Fisher. As noted, it can't handle $\kappa=0$. $\endgroup$ – J. M. will be back soon Aug 7 '15 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.