Skip to main content

Compute the smallest bounding ball of a point cloud. Cython binding of the popular miniball utility. Fast!

Project description

cyminiball

image License Build Status Coverage Status CodeFactor DeepSource

A Python package to compute the smallest bounding ball of a point cloud in arbitrary dimensions. A Python/Cython binding of the popular miniball utility by Bernd Gärtner.

To my knowledge, this is currently the fastest implementation available in Python. For other implementations see:

Installation:

The package is available via pip.

python -m pip install cyminiball

Usage:

import cyminiball as miniball
import numpy as np

d = 2               # Number of dimensions
n = 10000           # Number of points
dt = np.float64     # Data type

points = np.random.randn(n, d)
points = points.astype(dt)
C, r2 = miniball.compute(points)
print("Center:", C)
print("Radius:", np.sqrt(r2))

Additional output can be generated using the details flag and compute_max_chord().

C, r2, info = miniball.compute(points, details=True)
# Returns an info dict with the following keys:
#       center:         center
#       radius:         radius
#       support:        indices of the support points
#       relative_error: error measure realtive to r2
#       is_valid:       numerical validity
#       elapsed:        time required
#
# The maximal chord is the longest line connecting any
# two of the support points. The following extends the
# info dict by the following keys:
#       pts_max:        point coordinates of the two points
#       ids_max:        ids of the two extreme points
#       d_max:          length of the maximal chord
(p1, p2), d_max = miniball.compute_max_chord(points, info=info)

See examples/examples.py for further usage examples

Build package

Building the package requires

  • Python 3.x
  • Cython
  • numpy

First, download the project and set up the environment.

git clone "https://github.com/hirsch-lab/cyminiball.git"
cd cyminiball
python -m pip install -r "requirements.txt"

Then build and install the package. Run the tests/examples to verify the package.

./build_install.sh
python "tests/test_all.py"
python "examples/examples.py"

Performance

For a comparison with miniballcpp, run the below command. In my experiments, the Cython-optimized code ran 10-50 times faster, depending on the number of points and point dimensions.

python "examples/comparison.py"

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

cyminiball-2.1.1.tar.gz (183.8 kB view details)

Uploaded Source

Built Distribution

cyminiball-2.1.1-cp310-cp310-macosx_12_0_arm64.whl (125.4 kB view details)

Uploaded CPython 3.10 macOS 12.0+ ARM64

File details

Details for the file cyminiball-2.1.1.tar.gz.

File metadata

  • Download URL: cyminiball-2.1.1.tar.gz
  • Upload date:
  • Size: 183.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for cyminiball-2.1.1.tar.gz
Algorithm Hash digest
SHA256 c815add326836b3ce3fbeee4f22bb3fae17e169c82dbef6f75eaef150386a3cd
MD5 4f732b676ed13c4d3d87239cb45b1b23
BLAKE2b-256 57c53dfae2118c0f2ea8893fa32c3b1a85897d58c72d4322279844114592b80b

See more details on using hashes here.

File details

Details for the file cyminiball-2.1.1-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for cyminiball-2.1.1-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 f08829815c87b84eff34bc828db96659c8b0d0f23ec92eb5f3157bfbcced53ce
MD5 c419b29ea2e09835f63c3fa6c1331275
BLAKE2b-256 b6f064cbe79f490563df11805441c8feecef4e2d111915ef4bdcf7cc5d9479dc

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