Skip to main content

Latent component Gaussian process

Project description

Latent component Gaussian process (LCGP)

CI Coverage Status Documentation Status PyPI version

Implementation of latent component Gaussian process (LCGP). LCGP handles the emulation of multivariate stochastic simulation outputs.


List of Contents:

Installation

The implementation of LCGP can be installed through

pip install lcgp

Note on LBFGS optimizer:

It is strongly recommended that PyTorch-LBFGS is installed to fully utilize this implementation. Installation guide on PyTorch-LBFGS can be found on its repository. Note that PyTorch-LBFGS has an additional requirement matplotlib. The source code of a version of PyTorch-LBFGS that does not require matplotlib is included in reference_code.

Basic usage

What most of us need:

import numpy as np
from lcgp import LCGP
from lcgp import evaluation  # optional evaluation module

# Generate fifty 2-dimensional input and 4-dimensional output
x = np.random.randn(50, 2)
y = np.random.randn(4, 50)

# Define LCGP model
model = LCGP(y=y, x=x)

# Estimate error covariance and hyperparameters
model.fit()

# Prediction
p = model.predict(x0=x)  # mean and variance
rmse = evaluation.rmse(y, p[0].numpy())
dss = evaluation.dss(y, p[0].numpy(), p[1].numpy(), use_diag=True)
print('Root mean squared error: {:.3E}'.format(rmse))
print('Dawid-Sebastiani score: {:.3f}'.format(dss))

# Access parameters
print(model)

Specifying number of latent components

There are two ways to specify the number of latent components by passing one of the following arguments in initializing an LCGP instance:

  • q = 5: Five latent components will be used. q must be less than or equal to the output dimension.
  • var_threshold = 0.99: Include $q$ latent components such that 99% of the output variance are explained, using a singular value decomposition.

Note: Only one of the options should be provided at a time.

model_q = LCGP(y=y, x=x, q=5)
model_var = LCGP(y=y, x=x, var_threshold=0.99)

Specifying diagonal error groupings

If errors of multiple output dimensions are expected to be similar, the error variances can be grouped in estimation.

For example, the 6-dimensional output is split into two groups: the first two have low errors and the remaining four have high errors.

import numpy as np

x = np.linspace(0, 1, 100)
y = np.row_stack((
    np.sin(x), np.cos(x), np.tan(x),
    np.sin(x/2), np.cos(x/2), np.tan(x/2)
))

y[:2] += np.random.normal(2, 1e-3, size=(2, 100))
y[2:] += np.random.normal(-2, 1e-1, size=(4, 100))

Then, LCGP can be defined with the argument diag_error_structure as a list of output dimensions to group. The following code groups the first 2 and the remaining 4 output dimensions.

model_diag = LCGP(y=y, x=x, diag_error_structure=[2, 4])

By default, LCGP assigns a separate error variance to each dimension, equivalent to

model_diag = LCGP(y=y, x=x, diag_error_structure=[1]*6)

Define LCGP using different submethod

Three submethods are implemented under LCGP:

  • Full posterior (full)
  • ELBO (elbo)
  • Profile likelihood (proflik)

Under circumstances where the simulation outputs are stochastic, the full posterior approach should perform the best. If the simulation outputs are deterministic, the profile likelihood method should suffice.

LCGP_models = []
submethods = ['full', 'elbo', 'proflik']
for submethod in submethods:
    model = LCGP(y=y, x=x, submethod=submethod)
    LCGP_models.append(model)

Standardization choices

LCGP standardizes the simulation output by each dimension to facilitate hyperparameter training. The two choices are implemented through robust_mean = True or robust_mean = False.

  • robust_mean = False: The empirical mean and standard deviation are used.
  • robust_mean = True: The empirical median and median absolute error are used.
model = LCGP(y=y, x=x, robust_mean=False)

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

lcgp-0.1.2.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

lcgp-0.1.2-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file lcgp-0.1.2.tar.gz.

File metadata

  • Download URL: lcgp-0.1.2.tar.gz
  • Upload date:
  • Size: 44.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for lcgp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 41fe371be40da51d6bd94b57bc3c1df1f031df059d99e3e7cd2d6fc7cb6eca9e
MD5 1988355e68cca50e686964c1af4099a9
BLAKE2b-256 0ba4e2252b46ac9b5ce51926fe1c9ab8434218b7056c96812646c44edd135b89

See more details on using hashes here.

File details

Details for the file lcgp-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lcgp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for lcgp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 277a43ece9de09cc4bbc9ef27ef03f2d2f359d6163e36635b94685474be21bd0
MD5 95e92ad0037238689244134a312e4fef
BLAKE2b-256 db89753be3dd42f697cd398a0d038120a5b02332ee1b373be83769a0c288ad61

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