flopscope.

flopscope.numpy.random.vonmises

fnp.random.vonmises(mu, kappa, size=None)[flopscope source]

Draw samples from a von Mises distribution.

Adapted from NumPy docs np.random.vonmises

Arearandom
Typecustom
Cost
16×per-operation
Flopscope Context

Sampling; cost = numel(output).

Samples are drawn from a von Mises distribution with specified mode (mu) and concentration (kappa), on the interval [-pi, pi].

The von Mises distribution (also known as the circular normal distribution) is a continuous probability distribution on the unit circle. It may be thought of as the circular analogue of the normal distribution.

Note.

New code should use the vonmises method of a Generator instance instead; please see the random-quick-start.

Parameters

mu:float or array_like of floats

Mode ("center") of the distribution.

kappa:float or array_like of floats

Concentration of the distribution, has to be >=0.

size:int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if mu and kappa are both scalars. Otherwise, flops.broadcast(mu, kappa).size samples are drawn.

Returns

out:ndarray or scalar

Drawn samples from the parameterized von Mises distribution.

See also

Notes

The probability density for the von Mises distribution is

p(x)=eκcos(xμ)2πI0(κ),p(x) = \frac{e^{\kappa cos(x-\mu)}}{2\pi I_0(\kappa)},

where μ\mu is the mode and κ\kappa the concentration, and I0(κ)I_0(\kappa) is the modified Bessel function of order 0.

The von Mises is named for Richard Edler von Mises, who was born in Austria-Hungary, in what is now the Ukraine. He fled to the United States in 1939 and became a professor at Harvard. He worked in probability theory, aerodynamics, fluid mechanics, and philosophy of science.

References

footnote
1

Abramowitz, M. and Stegun, I. A. (Eds.). "Handbook of
Mathematical Functions with Formulas, Graphs, and Mathematical
Tables, 9th printing," New York: Dover, 1972.
footnote
2

von Mises, R., "Mathematical Theory of Probability
and Statistics", New York: Academic Press, 1964.

Examples

Draw samples from the distribution:

>>> mu, kappa = 0.0, 4.0 # mean and concentration
>>> s = flops.random.vonmises(mu, kappa, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> from scipy.special import i0  # doctest: +SKIP
>>> plt.hist(s, 50, density=True)
>>> x = flops.linspace(-flops.pi, flops.pi, num=51)
>>> y = flops.exp(kappa*flops.cos(x-mu))/(2*flops.pi*i0(kappa))  # doctest: +SKIP
>>> plt.plot(x, y, linewidth=2, color='r')  # doctest: +SKIP
>>> plt.show()