nengolib.stats.SphericalCoords

class nengolib.stats.SphericalCoords(m)[source]

Spherical coordinates for inverse transform method.

This is used to map the hypercube onto the hypersphere and hyperball. [1]

Parameters:
m : integer

Positive index for spherical coordinate.

References

[1]K.-T. Fang and Y. Wang, Number-Theoretic Methods in Statistics. Chapman & Hall, 1994.

Examples

>>> from nengolib.stats import SphericalCoords
>>> coords = SphericalCoords(3)
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(0, 1, 1000)
>>> plt.figure(figsize=(8, 8))
>>> plt.subplot(411)
>>> plt.title(str(coords))
>>> plt.ylabel("Samples")
>>> plt.hist(coords.sample(1000), bins=50, normed=True)
>>> plt.subplot(412)
>>> plt.ylabel("PDF")
>>> plt.plot(x, coords.pdf(x))
>>> plt.subplot(413)
>>> plt.ylabel("CDF")
>>> plt.plot(x, coords.cdf(x))
>>> plt.subplot(414)
>>> plt.ylabel("PPF")
>>> plt.plot(x, coords.ppf(x))
>>> plt.xlabel("x")
>>> plt.show()

(Source code)

_images/nengolib-stats-SphericalCoords-1.png

Methods

cdf(x) Evaluates the CDF along the values x.
pdf(x) Evaluates the PDF along the values x.
ppf(y) Evaluates the inverse CDF along the values x.
sample(n[, d, rng]) Samples n points in d dimensions.