Skip to main content

Epistemic Nearest Neighbors

Project description

Epistemic Nearest Neighbors

A fast, alternative surrogate for Bayesian optimization

ENN estimates a function's value and associated epistemic uncertainty using a K-Nearest Neighbors model. Queries take $O(N lnK)$ time, where $N$ is the number of observations available for KNN lookups. Compare to an exact GP, which takes $O(N^2)$ time. Additionally, measured running times are very small compared to GPs and other alternative surrogates. [1]

Contents

  • ENN surrogate, EpistemicNearestNeighbors [1]

  • TuRBO-ENN optimizer via create_optimizer with config factories

    • turbo_one_config() - TuRBO [2], matching the reference implementation.
    • turbo_enn_config() - Uses ENN instead of GP.
    • turbo_zero_config() - No surrogate
    • lhd_only_config() - LHD design on every ask(). Good for a baseline and for testing. The optimizer has an ask()/tell() interface. All turbo_*() methods follow TuRBO:
    • Generate candidates with RAASP [3] sampling.
    • Select a candidate with Thompson sampling (TuRBO-one), UCB (TuRBO-ENN), or randomly (TURBO-zero).
  • Overview of algorithms: algos.pdf

[1] M. Bafna, Jadhav, S. a., & Sweet, D., (2025). Taking the GP Out of the Loop. arXiv preprint arXiv:2506.12818. https://arxiv.org/abs/2506.12818 [2] Eriksson, D., Pearce, M., Gardner, J. R., Turner, R., & Poloczek, M. (2020). Scalable Global Optimization via Local Bayesian Optimization. Advances in Neural Information Processing Systems, 32. https://arxiv.org/abs/1910.01739 [3] Rashidi, B., Johnstonbaugh, K., & Gao, C. (2024). Cylindrical Thompson Sampling for High-Dimensional Bayesian Optimization. Proceedings of The 27th International Conference on Artificial Intelligence and Statistics (pp. 3502–3510). PMLR. https://proceedings.mlr.press/v238/rashidi24a.html

Installation

pip install ennbo[with-deps] or cargo add ennbo

PyPI wheels are platform-specific (they include the enn.enn_rust native extension). If pip install ennbo gives an import error about enn.enn_rust, install a matching wheel (same OS/arch/Python) or build from source (Rust + linkable Faiss C API; see below).

Demonstration

demo_enn.ipynb - Shows how to use EpistemicNearestNeighbors to build and query an ENN model. demo_turbo_enn.ipynb - Shows how to use TurboOptimizer to optimize the Ackley function.

Installation, MacOS

On my MacBook I can run into problems with dependencies and compatibilities.

On MacOS try:

micromamba env create -n ennbo -f admin/conda-macos.yml
micromamba activate ennbo
pip install --no-deps ennbo
pytest -sv tests

You may replace micromamba with conda and this will probably still work.

The commands above make sure

  • You use the MacOS-specific PyTorch (with mps).
  • You avoid having multiple, competing OpenMPs installed PyTorch issue faiss issue.
  • You use old enough versions of NumPy and PyTorch to be compatible with faiss faiss issue.
  • Prevent matplotlib's installation from upgrading your NumPy to an incompatible version.
  • ennbo's listed dependencies do not undo any of the above (which is fine b/c the above commands set the up correctly).

Run tests with

pytest -x -sv tests

and they should all pass fairly quickly (~10s-30s).

If your code still crashes or hangs, try this hack:

export KMP_DUPLICATE_LIB_OK=TRUE
export OMP_NUM_THREADS=1

I don't recommend this, however, as it will slow things down.

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

ennbo-0.3.3.tar.gz (103.5 kB view details)

Uploaded Source

Built Distributions

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

ennbo-0.3.3-cp312-cp312-manylinux_2_31_x86_64.whl (9.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

ennbo-0.3.3-cp311-cp311-manylinux_2_31_x86_64.whl (20.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

ennbo-0.3.3-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file ennbo-0.3.3.tar.gz.

File metadata

  • Download URL: ennbo-0.3.3.tar.gz
  • Upload date:
  • Size: 103.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.5

File hashes

Hashes for ennbo-0.3.3.tar.gz
Algorithm Hash digest
SHA256 b3bf0711cef6c988c4963ad299ca91793b36b6dc9502b9a448740b443bef4f4a
MD5 f5d3504bc392372b0f117186be6874d4
BLAKE2b-256 efa9dde74cb9f5b5eb83e5607e205bfa67361ec1a616bab42fd2454eaca26d28

See more details on using hashes here.

File details

Details for the file ennbo-0.3.3-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for ennbo-0.3.3-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 3d34bd6b4f031040f0fb5c7f6b1b952acc1fd5a1a18bfb2673c383aca9b633ae
MD5 54fca84356223bf4f1cbf0fc7a3e75a9
BLAKE2b-256 3618fc7e40ea0744ebda9ea301691cd0e9ab47791d3a02a53c584c1767bc7add

See more details on using hashes here.

File details

Details for the file ennbo-0.3.3-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for ennbo-0.3.3-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 81179733199c50a1492643961a19ced4ce5ddebe22cc637fc3508b0e060f85fe
MD5 97c75560d933f0bbdb5eaf287d2087f2
BLAKE2b-256 fb0712778cf98123176a9f0761249d4f53adb8f964d9d263172b3b5116419eaf

See more details on using hashes here.

File details

Details for the file ennbo-0.3.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ennbo-0.3.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a3e630188f6218bca9b2a67e55dce72d0d66d7e21f1edf4524d9a49958bbf57b
MD5 8a7ec8891d5f25e561636a3b91db0dbc
BLAKE2b-256 1446ce79f18b217f2f30a13405254eee23999425d31b0ae560cee587607f400c

See more details on using hashes here.

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