Skip to main content

Nearest Neighbors Gaussian Process Regressor

Project description

Nngpr: Nearest Neighbors Gaussian Process Regressor

This project implements the Nearest Neighbor Gaussian Process Regressor (Nngpr) according to Datta 2016. This model works by building a local Gaussian Process around the kernel-space nearest neighbors of a given point. Since the local Gaussian Process depends only a small number of nearest neighbors, this model overcomes the quadratic complexity of the standard Gaussian Processes regressor. The complexity of Nngpr with n points and m nearest neighbors is n*m^2 for the Gaussian Process kernel and matrix operations, and n^2 for the nearest neighbors search. For large datasets the nearest neighbors search becomes the main bottleneck, however it can be accelerated by GPUs. Nngpr does not have a quadratic memory footprint since it never stores the full kernel or covariance matrices, thus can be used on datasets much larger than what typically possible with traditional Gaussian Processes.

Some very basic benchmarks are provided in the notebook benchmark.ipynb.

Installation

Nngpr can be installed from pip with:

pip install nngpr

By default, this command does not install gpu-accellerated Nngpr. To install the cupy or torch accellerated Nngpr (see Usage section below), simply do:

pip install nngpr[torch]

or, if you don't want to install torch, you can rely on cupy:

pip install nngpr[cupy]

Usage

Nearest Neighbor Gaussian Process Regressor is implementend in a scikit-learn-like interface. Nngpr must be used with kernels that inherits from nngpr.batched_kernels.BatchedKernel. The package nngpr.batched_kernels already provides a sckit-learn-like implementation of the most common kernels.

There are three different implementations of Nngpr:

  • Numpy-based (NumpyNngpr): this is the simplest implementation and requires only scikit-learn as dependency. It runs on CPU and is not practically usable for large datasets as it would turn out to be rather slow (see benchmark.ipynb for some rough numbers). This is always available within the nngpr package.
  • Torch-based (TorchNngpr): this implementation uses torch and can potentially run on any torch device. On Cuda devices, kernels of the type WhiteKernel + ConstantKernel * RBF gets accellerated by custom Cuda kernels (here kernels refers to Cuda software) through cupy. This implementation is available when installing nngpr[torch].
  • Cupy-based (CupyNngpr): this implementation uses cupy to run on Nvidia GPUs. It does not require torch, however it currently supports only kernels of the type WhiteKernel + ConstantKernel * RBF. This implementation is available when installing nngpr[cupy] or nngpr[torch].

CupyNngpr and TorchNngpr have practically the same performance on Nvidia GPUs, with the latter supporting a broader family of kernels. NumpyNngpr performs better than cpu-based TorchNngpr. For specific examples on using Nngpr please see the examples folder.

Run unittests

Some unittest are included in the nngpr to check that everything works correctly. You can run them with:

  • python -m nngpr.run_tests

Python requirements

Requirements are automatically installed by pip. If you want to run the benchmark notebook, install these additional packages:

  • matplotlib
  • ucimlrepo
  • gpytorch (if you want to run GPyTorch models, tested on gpytorch v1.14)

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

nngpr-0.1.1.tar.gz (89.4 kB view details)

Uploaded Source

Built Distribution

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

nngpr-0.1.1-py3-none-any.whl (81.9 kB view details)

Uploaded Python 3

File details

Details for the file nngpr-0.1.1.tar.gz.

File metadata

  • Download URL: nngpr-0.1.1.tar.gz
  • Upload date:
  • Size: 89.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for nngpr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5a19d1105eb166f9817cca05c40f9a2132cd232325db2fd987dff1ba5b2f9789
MD5 1cf52e351d474f2fba5eeeb1ef4cadcd
BLAKE2b-256 ce76854644fce4cb0dab38a9a1fcfaa73ea656839adebec6a86b03cae6ebdae1

See more details on using hashes here.

File details

Details for the file nngpr-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nngpr-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 81.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for nngpr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81e7f437458825b487d4f29bf835b0daa7acc0c92ec046aecb995caf54538b45
MD5 05dd8c617f83df96abc77ad1e74893d8
BLAKE2b-256 043d45cd133e642ebdceca02ebb3e5c03440a343364409bdc9fb670c04e18b48

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