[Numpy-discussion] von mises distribution in numpy.random biased

Travis E. Oliphant oliphant@enthought....
Sat Sep 8 23:44:36 CDT 2007

killian koepsell wrote:
> hi,
> the von mises distribution in numpy.random seems to be biased towards
> a higher concentration (kappa). given a concentration of 2, it
> produces data that has a concentration of 2.36. i compared the
> distribution to the one produced by the CircStats[1] package of R[2]
> using RPy [3] and created a figure here:
>   http://redwood.berkeley.edu/kilian/vonmises.png
> the script i used is attached to this email. i don't know what
> algorithm NumPy uses, so i can't tell if it is a real bug or some sort
> of rounding error. the CircStats package uses the algorithm by Best
> and Fisher [4].


The algorithm in NumPy is basically the same algorithm.  However, two 
things are different about it and the one used in R (and in Python 
itself by the way).

1) The two random variates used in the rejection algorithm are drawn 
from a uniform on [-1,1]
2) The testing for the sign is done with the same random variable 
instead of a new one.

I've updated the source to change both of these behaviors.  I suspect 
the bias is coming from 1)

Perhaps you could re-run your tests.


More information about the Numpy-discussion mailing list