Skip to main content

A library for low-discrepancy sequences

Project description

Python Version PyPI License codecov Documentation Status Tests

⚽ sphere-n

Generator of Low discrepancy Sequence on S_n

Generate uniformly distributed points on n-dimensional spheres using low-discrepancy sequences. Perfect for Monte Carlo simulations, numerical integration, and computational geometry.

Quick Start

Installation

pip install sphere-n

Basic Usage

from sphere_n import Sphere3, SphereN, CylindN

# Generate points on 3-sphere
sgen = Sphere3([2, 3, 5])
sgen.reseed(42)
point = sgen.pop()
print(point)  # [0.291, 0.897, -0.333, 6.12e-17]

# Generate points on n-sphere (4D)
nsgen = SphereN([2, 3, 5, 7])
nsgen.reseed(42)
point = nsgen.pop()
print(point)  # 5-dimensional vector

# Batch generation (more efficient)
points = sgen.pop_batch(100)  # Generate 100 points at once

Use Cases

# Monte Carlo integration
import numpy as np
from sphere_n import SphereN

sgen = SphereN([2, 3, 5, 7])
points = np.array(sgen.pop_batch(10000))
values = [f(p) for p in points]
integral = np.mean(values)

# Compare with random sampling
random_points = np.random.randn(10000, 5)
random_points /= np.linalg.norm(random_points, axis=1)[:, None]
random_integral = np.mean([f(p) for p in random_points])

# LDS typically converges 2-3x faster

This library implements a generator for the generation of low-discrepancy sequences on n-dimensional spheres. Low-discrepancy sequences are utilized for the generation of points that are distributed uniformly across a given space. This technique is of significant value in a number of fields, including computer graphics, numerical integration, and Monte Carlo simulations.

The principal objective of this library is to facilitate the generation of points on the surface of spheres of varying dimensions, including three-dimensional and higher-dimensional spheres. The input required is the dimension of the sphere (n) and a set of base numbers to be used for the underlying sequence generation. The output is a series of vectors, with each vector representing a point on the surface of the n-dimensional sphere.

The library achieves this through a combination of mathematical calculations and recursive structures. The library utilizes a number of fundamental components, including:

  1. The VdCorput sequence generator produces a sequence of numbers that are evenly distributed between 0 and 1.
  2. Subsequently, the aforementioned numerical data is mapped onto the surface of a sphere through the use of interpolation functions.
  3. The SphereGen module represents an abstract base class that defines the common interface for all sphere generators.
  4. The recursive structures, namely Sphere3 and NSphere, facilitate the construction of higher-dimensional spheres from their lower-dimensional counterparts.

The primary logic flow begins with the construction of a SphereN object, which utilizes either a Sphere3 (for 3D) or a recursive process to generate lower-dimensional spheres for higher dimensions. In the generation of points, the VdCorput sequence is employed to obtain a base number, which is then subjected to a series of transformations involving sine, cosine, and interpolation in order to map it onto the surface of the sphere.

A noteworthy aspect of the library is its incorporation of caching (through the @cache decorator) to optimize performance by storing and reusing calculated values. Moreover, the library provides traits and structures that facilitate the adaptable deployment of the sphere generators. The SphereGen abstract base class serves to define a common interface for a variety of sphere generators, whereas the NSphere and SphereN structures are responsible for implementing the actual generation logic.

In conclusion, this library provides a sophisticated yet flexible method for generating evenly distributed points on high-dimensional spheres, which can be advantageous in numerous scientific and computational applications.

Dependencies

👀 See also

👉 Note

This project has been set up using PyScaffold 3.2.1. For details and usage information on PyScaffold see https://pyscaffold.org/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphere_n-0.5.tar.gz (38.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphere_n-0.5-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file sphere_n-0.5.tar.gz.

File metadata

  • Download URL: sphere_n-0.5.tar.gz
  • Upload date:
  • Size: 38.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sphere_n-0.5.tar.gz
Algorithm Hash digest
SHA256 fc6964f221211866225d9c3035169158381cfc298c5d256bfcf1cd0de23c2dd9
MD5 9f79012bbf0ea724c38957763e650f20
BLAKE2b-256 e111512dbfa2e60ed29b78fa79d72d226ce840c175220d98f76cfb8b2422b196

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphere_n-0.5.tar.gz:

Publisher: python-publish.yml on luk036/sphere-n

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphere_n-0.5-py3-none-any.whl.

File metadata

  • Download URL: sphere_n-0.5-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sphere_n-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2e42bdc5525b65296036074c5fe91355189522857ccc6141de80ac51d3c13e6d
MD5 af45f7394476e5638567c485e67d7b77
BLAKE2b-256 9d7dd4e23fb7990e100efcf3c117d4d714817ae2bcff202fa42f4d9ca76c5907

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphere_n-0.5-py3-none-any.whl:

Publisher: python-publish.yml on luk036/sphere-n

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page