Skip to main content

Learn-as-you-go emulator with error estimation

Project description

Python implementation of the Learn As You Go algorithm described in arxiv:1506:01079 and arxiv:2004.11929.

https://badge.fury.io/py/layg.svg https://zenodo.org/badge/240627897.svg Documentation Status https://github.com/auckland-cosmo/LearnAsYouGoEmulator/workflows/pytest/badge.svg https://github.com/auckland-cosmo/LearnAsYouGoEmulator/workflows/doc/badge.svg https://github.com/auckland-cosmo/LearnAsYouGoEmulator/workflows/lints/badge.svg

The package defines a decorator that can be applied to functions to convert them to functions which learn outputs as they go and emulate the true function when expected errors are low. Two emulators are included: the k-nearest neighbors Monte Carlo accelerator described there, and a simple neural network.

The basic usage of the emulator code is something like this:

@emulate(CholeskyNnEmulator)
def loglike(x):
    """
    Your complex and expensive function here
    """
    return -np.dot(x,x)

This decorates the function loglike so that it is an instance of the Learner class. It can be used in the same way as the original function: just call it as loglike(x).

The __call__(x) method now hides some extra complexity: it uses the Learn As You Go emulation scheme. It learns both the output of loglike(x) and the difference between the emulated and the true values of loglike(x) so that it can make a prediction of future the error residuals. We then put a cutoff on the amount of error that one will allow for any local evaluation of the target function. Any call to the emulator that has a too-large error will be discarded and the actual function loglike(x) defined above will be evaluated instead.

The logic for generating training sets and returning a value from either the true function or the emulated function are contained in the Learner class. The Learner class relies on an emulator class to do the actual emulation.

You can define you own emulator. Define a class that inherits from BaseEmulator and define two methods on it: set_emul_func(self, x_train: np.ndarray, y_train: np.ndarray) and set_emul_error_func(self, x_train: np.ndarray, y_train: np.ndarray) that set functions for, respectively, self.emul_func and self.emul_error_func. An example of this definition is provided in examples/example_custom_emulator.py.

See readthedocs.org for more documentation.

Installation

pip

The package is available on pypi.org. Install it with

pip install layg

anaconda

If you use anaconda you can create an appropriate environment and install to your python path by running

conda env create --file environment.yml
conda activate layg
pip install -e .

from this directory.

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

layg-0.0.2.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

layg-0.0.2-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file layg-0.0.2.tar.gz.

File metadata

  • Download URL: layg-0.0.2.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.8

File hashes

Hashes for layg-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0f88131050045c709d5f7fc85d7663ec8243d241fe42cfeac0a8b88d59b67b29
MD5 5ba6ad6c2a4e0150c9308008635e1cb6
BLAKE2b-256 a2becd1483f1ce330cef0c8019fe355bcea0b5d325661c36003f8cdee5ca1db0

See more details on using hashes here.

File details

Details for the file layg-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: layg-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.8

File hashes

Hashes for layg-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3af59d27133bc37623a3cea4e05370fdc9377b087c128a54fc6c988dca26e43f
MD5 46159a233062138b986bc019c90cadbd
BLAKE2b-256 15c96789e1e210451b35a2feb0dde99af2c34a2e2dd808fa61be719f039059c2

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