miniball
A Python module to efficiently compute the smallest bounding ball of a point set, in arbitrary number of dimensions.
The algorithm runs in approximatively linear time in respects to the number of input points. This is NOT a derivative nor a port of Bernd Gaertner’s C++ library.
This project is licensed under the MIT License
Requirements
miniball 1.2 requires
Python >= 3.5
Numpy >= 1.17
Installation
$ pip install miniball
Usage
Here is how you can get the smallest bounding ball of a set of points S
>>> import numpy
>>> import miniball
>>> S = numpy.random.randn(100, 2)
>>> C, r2 = miniball.get_bounding_ball(S)
The center of the bounding ball is C, its radius is the square root of r2. The input coordinates S can be integer, they will automatically cast to floating point internally.
And that’s it ! miniball does only one thing with one function.
Result accuracy
Although the algorithm returns exact results in theory, in practice it returns result only exact up to a given precision. The epsilon keyword argument allows to control that precision, it is set to 1e-7 by default.
>>> import numpy
>>> import miniball
>>> S = numpy.random.randn(100, 2)
>>> C, r2 = miniball.get_bounding_ball(S, epsilon=1e-7)
Repeatability
The algorithm to compute bounding balls relies on a pseudo-random number generator. Although the algorithms return an exact solution, it is only exact up to the epsilon parameter. As a consequence, running the get_bounding_ball function twice on the same input might not return exactly the same output.
By default, each call to get_bounding_ball pull out a new, freshly seeded pseudo-random number generator. Therefore, if you wish to get repeatable results from get_bounding_ball, you have to (and only have to) pass the same pseudo-random number generator, using with the rng keyword argument
>>> import numpy
>>> import miniball
>>> S = numpy.random.randn(100, 2)
>>> rng = numpy.random.RandomState(42)
>>> C, r2 = miniball.get_bounding_ball(S, rng = rng)
Duplicated input points
Duplicated input points might trigger failures. This implementation do not check for duplicated input points, the guaranty of non-duplication is defered to you, the programmer. This is by design, to avoid to pay the cost of de-duplication when we are sure that the input has no duplicates.
Implementation notes
The algorithm implemented is Welzl’s algorithm. It is a pure Python implementation, it is not a binding of the popular C++ package Bernd Gaertner’s miniball.
The algorithm, although often presented in its recursive form, is here implemented in an iterative fashion. Python have an hard-coded recursion limit, therefore a recursive implementation of Welzl’s algorithm would have an artificially limited number of point it could process.
License
This project is licensed under the MIT License - see the LICENSE file for details
Metadata
Release files for miniball 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| miniball-1.2.0.tar.gz | 6.1 kB | Without provenance | Details for miniball-1.2.0.tar.gz |
Release files / miniball-1.2.0.tar.gz
| Download URL | miniball-1.2.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e46a12a158a6d5428f9095195afe28682aa5a419ec4fccf4db165f3e25919ce5
|
|
BLAKE2b-256 checksum How to use checksums |
4644779ef60d32098c73ac73b4881a54ce244141ca38d485f422d7f7efb476c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for miniball 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.