virocon._nsphere module

Sample almost equally distributed points from an n-dimensional hypersphere.

class virocon._nsphere.NSphere(dim, n_samples)[source]

Bases: object

This class calculates almost equally spaced points on a n-sphere.

It considers the Thomson problem 1 to distribute the points on the sphere.

References

1

https://en.wikipedia.org/wiki/Thomson_problem

Examples

>>> sphere = NSphere(3, 1000)
>>> samples = sphere.unit_sphere_points
>>> #%% plot sphere
>>> from mpl_toolkits.mplot3d import Axes3D
>>> import matplotlib.pyplot as plt
>>> plt.close('all')
>>> #fig = plt.figure(figsize=plt.figaspect(1))
>>> #ax = fig.add_subplot(111, projection='3d')
>>> u = np.linspace(0, 2 * np.pi, 50)
>>> v = np.linspace(0, np.pi, 30)
>>> x = np.outer(np.cos(u), np.sin(v))
>>> y = np.outer(np.sin(u), np.sin(v))
>>> z = np.outer(np.ones(np.size(u)), np.cos(v))
>>> #wireframe_plot = ax.plot_wireframe(x, y, z, rcount=10, ccount=10,)
>>> #sphere_plot = ax.scatter(samples[:, 0], samples[:, 1], samples[:, 2],                                 c='green', depthshade=False, label="verteilt")
>>> #plot_legend = ax.legend()
__init__(dim, n_samples)[source]
Parameters
  • dim (int) – The number of dimensions. (i.e. the n in n-sphere plus 1)

  • n_samples (int) – The number of points to distribute on the n-sphere.