Skip to main content

Sample balls, spheres, spherical caps

Project description

sambal

sambal provides functions to

  • uniformly sample a sphere
  • uniformly sample a spherical cap of a sphere

Usage

Random vector on sphere

Generate a random vector on a 100-dimensional unit sphere.

import numpy as np
from sambal import random_on_sphere

dim = 100
print(random_on_sphere(dim))

The same as above, but with a random number generator seeded to 0.

import numpy as np
from sambal import random_on_sphere

dim = 100
rng = np.random.default_rng(0)
print(random_on_sphere(dim, rng))

Random vector on spherical cap

Generate a 100-dimensional random vector on a spherical cap whose central axis is [1, 1, 1, ..., 1] / sqrt(100) and whose maximum planar angle is pi/3.

import numpy as np
from sambal import random_on_cap

dim = 100
axis = np.ones(dim)
axis = axis / np.linalg.norm(axis)
max_planar_angle = np.pi/3
print(random_on_cap(axis, max_planar_angle))

The same as above, but with a random number generator seeded to 0.

import numpy as np
from sambal import random_on_cap

rng = np.random.default_rng(0)
dim = 100
axis = np.ones(dim)
axis = axis / np.linalg.norm(axis)
max_planar_angle = np.pi/3
print(random_on_cap(axis, max_planar_angle, rng))

Citing

If you use this code for your research, please cite the paper An O(n) algorithm for generating uniform random vectors in n-dimensional cones.

License

sambal is free software released under the terms of the GNU General Public License, either version 3 of the License, or (at your option) any later version.

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

sambal-0.1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

sambal-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file sambal-0.1.0.tar.gz.

File metadata

  • Download URL: sambal-0.1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for sambal-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3fd79cbcf64998e2c2dd22ccd0e34c8487f2114af121c248b98d896952515647
MD5 7365f8f475206e1ede3e96a911b25223
BLAKE2b-256 2823dcbdf844227a71da03bb75888e699ac0f74bda9097bd670ad446f2ad0da7

See more details on using hashes here.

File details

Details for the file sambal-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sambal-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for sambal-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1672b81c898d629cf4944c8b8ad38a72ec672889dc86317d31c5d6661736a1ad
MD5 4f63950765e859f2751c0e08c32512bc
BLAKE2b-256 de3550598fad1f0a0c72c1b748e9932c3f2c889a8c92cf2ae52e606047e2cb0e

See more details on using hashes here.

Supported by

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