Skip to main content

Implementation of Python package for Fitting and Inference of Linearly Constrained Gaussian Processes

Project description

Constrained_GaussianProcess

Constrained_GaussianProcess is able to deal with linear inequality constraints in Gaussian Process frameworks. Check out the paper Finite-Dimensional Gaussian Approximation with Linear Inequality Constraints for a detail explanation.

A toy example

There are also Hamiltonian Monte Carlo method and Gibbs sampling method to sample from truncated multivariate Gaussian.

Requirement

The code requires Python 3.7 , as well as the following python libraries:

  • cvxpy==1.0.25
  • numpy==1.17.3
  • scipy==1.2.1

Those modules can be installed using: pip install numpy scipy cvxpy or pip install -r requirements.txt.

Installation

Use the package manager pip to install Constrained_GaussianProcess.

pip install Constrained-GaussianProcess

Usage

from Constrained_GaussianProcess import ConstrainedGP
m=30
# specify the constraints
constraints={'increasing': True, 'bounded': [0,1], 'convex': False}  
interval=[0,1]
Gp = ConstrainedGP(m, constraints=constraints, interval=interval)

# Training data
x_train = np.array([0.25, 0.5, 0.75])
y_train = norm().cdf((x-0.5)/0.2)

# the MCMC methods are used to approximate the posterior distribution, 
# so apart from training data, 'method' ('HMC' or 'Gibbs'), required number of samples 
# 'n' and the burn in numbers 'burn_in' should be specified when fitting the data.
Gp.fit_gp(x_train, y_train, n=100, burn_in=100, method='HMC')

x_test = np.arange(0, 1 + 0.01, 0.5)
y_pred = Gp.mean(x_test)  # get the conditional mean

Sampling from with constraints f\cdot X+g\ge 0

from Constrained_GaussianProcess import tmg

# set the number of samples and number in burn in phase
n = 150  
burn_in = 30

#Define the covariance matrix and mean vector
M = np.array([[0.5, -0.4], [-0.4, 0.5]])  
mu = np.array([0,0])

# Set initial point for the Markov chain
initial = np.array([4,1])

# Define two linear constraints
f = np.array([[1,1],[1,0]])
g = np.array([0,0])

# Sample 
samples = tmg(n, mu, M, initial, f, g, burn_in=burn_in)

Acknowledment

The HMC method for MCMC is based on the R package tmg.

License

MIT

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

Constrained_GaussianProcess-0.1.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

Constrained_GaussianProcess-0.1.1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Constrained_GaussianProcess-0.1.1.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for Constrained_GaussianProcess-0.1.1.tar.gz
Algorithm Hash digest
SHA256 799673b2d3ee8641385a0aa54ca446a5eb95b34b1b27f5d8994eaef4236d0699
MD5 b121093b39c32971130147f8b54b7984
BLAKE2b-256 152f0ec2f0aa5eeb68b4560e32a7e97038d22189bb466271d54709972e250bb2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Constrained_GaussianProcess-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for Constrained_GaussianProcess-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92f2b8dbcd359cbb0ce780cfbe8329b57cc9bc967e1d4cf3aed8d2662b42f9b9
MD5 6dae3a5a2be3eca9f5850cbe6ae00ef6
BLAKE2b-256 53ce112b909196cdb260675b005922db88f4ada04e49ff6943bb35c0caba7c33

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