MCPcopy Index your code
hub / github.com/python/cpython / vonmisesvariate

Method vonmisesvariate

Lib/random.py:625–665  ·  view source on GitHub ↗

Circular data distribution. mu is the mean angle, expressed in radians between 0 and 2*pi, and kappa is the concentration parameter, which must be greater than or equal to zero. If kappa is equal to zero, this distribution reduces to a uniform random angle over the

(self, mu, kappa)

Source from the content-addressed store, hash-verified

623 return -_log(1.0 - self.random()) / lambd
624
625 def vonmisesvariate(self, mu, kappa):
626 """Circular data distribution.
627
628 mu is the mean angle, expressed in radians between 0 and 2*pi, and
629 kappa is the concentration parameter, which must be greater than or
630 equal to zero. If kappa is equal to zero, this distribution reduces
631 to a uniform random angle over the range 0 to 2*pi.
632
633 """
634 # Based upon an algorithm published in: Fisher, N.I.,
635 # "Statistical Analysis of Circular Data", Cambridge
636 # University Press, 1993.
637
638 # Thanks to Magnus Kessler for a correction to the
639 # implementation of step 4.
640
641 random = self.random
642 if kappa <= 1e-6:
643 return TWOPI * random()
644
645 s = 0.5 / kappa
646 r = s + _sqrt(1.0 + s * s)
647
648 while True:
649 u1 = random()
650 z = _cos(_pi * u1)
651
652 d = z / (r + z)
653 u2 = random()
654 if u2 < 1.0 - d * d or u2 <= (1.0 - d) * _exp(d):
655 break
656
657 q = 1.0 / r
658 f = (q + z) / (1.0 + q * z)
659 u3 = random()
660 if u3 > 0.5:
661 theta = (mu + _acos(f)) % TWOPI
662 else:
663 theta = (mu - _acos(f)) % TWOPI
664
665 return theta
666
667 def gammavariate(self, alpha, beta):
668 """Gamma distribution. Not the gamma function!

Callers 3

test_zeroinputsMethod · 0.95
test_von_mises_rangeMethod · 0.95

Calls

no outgoing calls

Tested by 3

test_zeroinputsMethod · 0.76
test_von_mises_rangeMethod · 0.76