Skip to main content

Python library for Gaussian Process Regression.

Project description

Build Status Documentation Status

GPlib

A python library for Gaussian Process Regression.

Setup GPlib

  • The following packages must be installed before installing GPlib

# for ptyhon3
apt-get install python3-tk
# or for python2
apt-get install python-tk
  • Create and activate virtualenv (for python2) or venv (for ptyhon3)

# for ptyhon3
python3 -m venv --system-site-packages .env
# or for python2
virtualenv --system-site-packages .env

source .env/bin/activate
  • Upgrade pip

# for ptyhon3
python3 -m pip install --upgrade pip
# or for python2
python -m pip install --upgrade pip
  • Install GPlib package

python -m pip install gplib

Use GPlib

  • Import GPlib to use it in your python script.

import gplib
  • Generate some data and test points.

import numpy as np
data = {
  'X': np.arange(3, 8, 1)[:, None],
  'Y': np.random.uniform(0, 2, 5)[:, None]
}
plot_points = np.arange(0, 10, 0.01)[:, None]
  • Initialize the GP module with the desired modules.

gp = gplib.GP(
  mean_function=gplib.mea.Constant(data),
  covariance_function=gplib.cov.SquaredExponential(data, is_ard=False),
  likelihood_function=gplib.lik.Gaussian(is_noisy=True),
  inference_method=gplib.inf.ExactGaussian()
)
  • Sample the prior and the posterior GPs.

prior_samples = gp.sample(plot_points, n_samples=10)
posterior_gp = gp.get_posterior(data)
posterior_samples = posterior_gp.sample(plot_points, n_samples=10)
  • Finally plot the samples.

import matplotlib.pyplot as plt

plt.style.use('ggplot')

plt.clf()
plt.plot(
  (plot_points).flatten().tolist(),
  prior_samples, color='#43dce5'
)
plt.plot(
  (plot_points).flatten().tolist(),
  posterior_samples, color='#b19df0'
)
plt.plot(
  (data['X']).flatten().tolist(),
  (data['Y']).flatten().tolist(), color='#714ce5',
  linestyle='None', marker='o'
)
plt.show()
  • There are more examples in examples/ directory. Check them out!

Develop GPlib

  • Download the repository using git

git clone https://github.com/ibaidev/gplib.git
cd gplib
git config user.email 'MAIL'
git config user.name 'NAME'
git config credential.helper 'cache --timeout=300'
git config push.default simple
  • Update API documentation

source ./.env/bin/activate
pip install Sphinx
cd docs/
sphinx-apidoc -f -o ./ ../gplib

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gplib-0.5.2.tar.gz (29.5 kB view hashes)

Uploaded Source

Built Distribution

gplib-0.5.2-py2.py3-none-any.whl (45.1 kB view hashes)

Uploaded Python 2 Python 3

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