{ "info": { "author": "Wessel Bruinsma", "author_email": "wessel.p.bruinsma@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# [GPAR](http://github.com/wesselb/gpar)\n\n[![Build](https://travis-ci.org/wesselb/gpar.svg?branch=master)](https://travis-ci.org/wesselb/gpar)\n[![Coverage Status](https://coveralls.io/repos/github/wesselb/gpar/badge.svg?branch=master&service=github)](https://coveralls.io/github/wesselb/gpar?branch=master)\n[![Latest Docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://wesselb.github.io/gpar)\n\nImplementation of the Gaussian Process Autoregressive Regression Model\n\nSee the [paper](https://arxiv.org/abs/1802.07182), and see the [docs](https://wesselb.github.io/gpar).\n\n* [Installation](#installation)\n* [Basic Usage](#basic-usage)\n* [Features](#features)\n - [Input and Output Dependencies](#input-and-output-dependencies)\n - [Output Transformation](#output-transformation)\n - [Sampling](#sampling)\n - [Logpdf Computation](#logpdf-computation)\n - [Inducing Points](#inducing-points)\n * [Example (examples/paper/synthetic.py)](#example-examples-paper-synthetic-py)\n\n## Installation\nBefore installing the package, please ensure that `gcc` and `gfortran` are \navailable.\nOn OS X, these are both installed with `brew install gcc`;\nusers of Anaconda may want to instead consider `conda install gcc`.\nThen simply\n\n```\npip install gpar\n```\n\n## Basic Usage\nA simple instance of GPAR can be created as follows:\n\n```python\nfrom gpar import GPARRegressor\n\ngpar = GPARRegressor(replace=True, impute=True,\n scale=1.0,\n linear=True, linear_scale=100.0,\n nonlinear=True, nonlinear_scale=1.0,\n noise=0.1,\n normalise_y=True)\n```\n\nHere the keyword arguments have the following meaning:\n\n* `replace=True`: Replace data points with the posterior mean of the previous\n layer before feeding them into the next layer. This helps the model deal \n with noisy data, but may discard important structure in the data if the \n fit is bad.\n \n* `impute=True`: GPAR requires that data is _closed downwards_. If this is \n not the case, the model will be unable to use part of the data. Setting \n `impute` to `True` lets GPAR impute data points to ensure that the data is\n closed downwards.\n \n* `scale=1.0`: Initialisation of the length scale with respect to the inputs.\n\n* `linear=True`: Use linear dependencies between outputs.\n\n* `linear_scale=True`: Initialisation of the length scale of the linear \n dependencies between outputs.\n \n* `nonlinear=True`: Also use nonlinear dependencies between outputs.\n\n* `nonlinear_scale=1.0`: Initialisation of the length scale of the nonlinear \n dependencies between outputs. _Important:_ this length scale applies \n _after_ possible normalisation of the outputs (see below), in which case \n `nonlinear_scale=1.0` corresponds to a simple, but nonlinear relationship.\n \n* `noise=0.1`: Initialisation of the variance of the observation noise.\n\n* `normalise_y=True`: Internally, work with a normalised version of the \n outputs by subtracting the mean and dividing by the standard deviation.\n Predictions will be transformed back appropriately.\n\nIn the above, any scalar hyperparameter may be replaced by a list of values \nto initialise each layer separately, e.g. `scale=[1.0, 2.0]`. See the \ndocumentation for a full overview of the keywords that may be passed to \n`GPARRegressor`.\n\nTo fit GPAR, call `gpar.fit(x_train, y_train)` where `x_train` are the training \ninputs and `y_train` the training outputs. The inputs `x_train` must have shape \n$n$ or $n \\times m$, where $n$ is the number of data points and $m$ the \nnumber of input features, and the outputs `y_train` must have shape $n$ or $n \n\\times p$, where $p$ is the number of outputs.\n\nFinally, to make predictions, call\n\n```python\nmeans = gpar.predict(x_test, num_samples=100)\n```\n\nto get the predictive means, or \n\n```python\nmeans, lowers, uppers = gpar.predict(x_test,\n num_samples=100, \n credible_bounds=True)\n```\n\nto also get lower and upper 95% central marginal credible bounds. If you wish\n to predict the underlying latent function instead of the observed values, set\n`latent=True` in the call to `GPARRegressor.predict`.\n\n## Features\n\n### Input and Output Dependencies\nUsing keywords arguments, `GPARRegressor` can be configured to specify the \ndependencies with respect to the inputs and between the outputs. The following\ndependencies can be specified:\n\n* **Linear input dependencies:** Set `linear_input=True` and specify the \n length scale with `linear_input_scale`.\n \n* **Nonlinear input dependencies:** This is enabled by default. The length \n scale can be specified using `scale`. To tie these length scales across all\n layers, set `scale_tie=True`.\n \n* **Locally periodic input dependencies:** Set `per=True` and specify the period\n with `per_period`, the length scale with `per_scale`, and the length \n scale on which the periodicity changes with `per_decay`.\n \n* **Linear output dependencies:** Set `linear=True` and specify the length \n scale with `linear_scale`.\n \n* **Nonlinear output dependencies:** Set `nonlinear=True` and specify the \n length scale with `nonlinear_scale`.\n \nAll nonlinear kernels are exponentiated quadratic kernels. If you wish to \ninstead use rational quadratic kernels, set `rq=True`.\n\nAll parameters can be set to a list of values to initialise the value for \neach layer separately.\n\nTo let every layer depend only the `k`th previous layers, set `markov=k`.\n\n\n### Output Transformation\n\nOne may want to apply a transformation to the data before fitting the model, \ne.g. $y\\mapsto\\log(y)$ in the case of positive data. Such a transformation can\nbe specified by setting the `transform_y` keyword argument for `GPARRegressor`.\nThe following transformations are available:\n\n* `log_transform`: $y \\mapsto \\log(y)$.\n\n* `squishing_transform`: $y \\mapsto \\operatorname{sign}(y) \\log(1 + |y|)$.\n\n\n### Sampling\n\nSampling from the model can be done with `GPARRegressor.sample`. The keyword \nargument `num_samples` specifies the number of samples, and `latent` \nspecifies whether to sample from the underlying latent function or the \nobserved values. Sampling from the _prior_ and _posterior_ (model must be fit\nfirst) can be done as follows:\n \n```python\nsample = gpar.sample(x, p=2) # Sample two outputs from the prior.\n\nsample = gpar.sample(x, posterior=True) # Sample from the posterior.\n```\n\n### Logpdf Computation\nThe logpdf of data can be computed with `GPARRegressor.logpdf`. To compute the\nlogpdf under the posterior, set `posterior=True`. To sample missing data to \ncompute an unbiased estimate of the *pdf*, *not logpdf*, set \n`sample_missing=True`.\n\n\n### Inducing Points\nInducing points can be used to scale GPAR to large data sets. Simply set `x_ind`\nto the locations of the inducing points in `GPARRegressor`.\n\n\n## Example (`examples/paper/synthetic.py`)\n\n![Prediction](https://raw.githubusercontent.com/wesselb/gpar/master/readme_example_prediction.png)\n\n```python\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom gpar.regression import GPARRegressor\n\n# Create toy data set.\nn = 200\nx = np.linspace(0, 1, n)\nnoise = 0.1\n\n# Draw functions depending on each other in complicated ways.\nf1 = -np.sin(10 * np.pi * (x + 1)) / (2 * x + 1) - x ** 4\nf2 = np.cos(f1) ** 2 + np.sin(3 * x)\nf3 = f2 * f1 ** 2 + 3 * x\nf = np.stack((f1, f2, f3), axis=0).T\n\n# Add noise and subsample.\ny = f + noise * np.random.randn(n, 3)\nx_obs, y_obs = x[::8], y[::8]\n\n# Fit and predict GPAR.\nmodel = GPARRegressor(scale=0.1,\n linear=True, linear_scale=10.,\n nonlinear=True, nonlinear_scale=0.1,\n noise=0.1,\n impute=True, replace=True, normalise_y=False)\nmodel.fit(x_obs, y_obs)\nmeans, lowers, uppers = \\\n model.predict(x, num_samples=200, credible_bounds=True, latent=True)\n\n# Fit and predict independent GPs: set markov=0.\nigp = GPARRegressor(scale=0.1,\n linear=True, linear_scale=10.,\n nonlinear=True, nonlinear_scale=0.1,\n noise=0.1, markov=0, normalise_y=False)\nigp.fit(x_obs, y_obs)\nigp_means, igp_lowers, igp_uppers = \\\n igp.predict(x, num_samples=200, credible_bounds=True, latent=True)\n\n# Plot the result.\nplt.figure(figsize=(12, 2.5))\nplt.rcParams['font.family'] = 'serif'\nplt.rcParams['mathtext.fontset'] = 'dejavuserif'\n\nfor i in range(3):\n ax = plt.subplot(1, 3, i + 1)\n ax.spines['right'].set_visible(False)\n ax.spines['top'].set_visible(False)\n ax.yaxis.set_ticks_position('left')\n ax.xaxis.set_ticks_position('bottom')\n plt.scatter(x_obs, y_obs[:, i], label='Observations', c='black', s=15)\n plt.plot(x, f[:, i], label='Truth', c='tab:orange')\n plt.plot(x, means[:, i], label='GPAR', c='tab:blue')\n plt.fill_between(x, lowers[:, i], uppers[:, i],\n facecolor='tab:blue', alpha=.25)\n plt.plot(x, igp_means[:, i], label='IGP', c='tab:green')\n plt.fill_between(x, igp_lowers[:, i], igp_uppers[:, i],\n facecolor='tab:green', alpha=.25)\n plt.xlabel('$t$')\n plt.ylabel('$y_{}$'.format(i + 1))\n if i == 2:\n leg = plt.legend(facecolor='#eeeeee')\n leg.get_frame().set_linewidth(0)\n\nplt.tight_layout()\nplt.savefig('examples/paper/synthetic_prediction.pdf')\nplt.show()\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/wesselb/gpar", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "gpar", "package_url": "https://pypi.org/project/gpar/", "platform": "", "project_url": "https://pypi.org/project/gpar/", "project_urls": { "Homepage": "https://github.com/wesselb/gpar" }, "release_url": "https://pypi.org/project/gpar/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "Implementation of the Gaussian Process Autoregressive Regression Model", "version": "0.1.2" }, "last_serial": 5509397, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "83dd63517f5506e45928fd57cb113367", "sha256": "47309749ff99ca700158106f7f3715180427bfa3313434a04b03214d1622ae15" }, "downloads": -1, "filename": "gpar-0.1.0.tar.gz", "has_sig": false, "md5_digest": "83dd63517f5506e45928fd57cb113367", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17438, "upload_time": "2019-06-13T17:02:47", "url": "https://files.pythonhosted.org/packages/49/49/ffc058c42b45f53dc0153979f27437b710e2493daa5da8514af798870187/gpar-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "d1b2b608fd2de111d3a314a2b4685dd9", "sha256": "574344d5d1d422a3adcdde63d0619423e9ef30b4172502498088ccc3f61630e4" }, "downloads": -1, "filename": "gpar-0.1.1.tar.gz", "has_sig": false, "md5_digest": "d1b2b608fd2de111d3a314a2b4685dd9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17617, "upload_time": "2019-06-13T18:01:54", "url": "https://files.pythonhosted.org/packages/fd/e5/a7b738d94b62d24ef36647eab6671fee5974bc03ab29147a758148e78b8f/gpar-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c038b7a280e72ae919fb2b334bedc853", "sha256": "efe499c3855e174e7f2ac2d50d31c9db4ce320d840016362ac92ccb14dbc72c7" }, "downloads": -1, "filename": "gpar-0.1.2.tar.gz", "has_sig": false, "md5_digest": "c038b7a280e72ae919fb2b334bedc853", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17631, "upload_time": "2019-07-09T22:40:16", "url": "https://files.pythonhosted.org/packages/51/9a/174767faae814b842d807ce81c37ae2177befa3cfe0ddf03f9f96b91e656/gpar-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c038b7a280e72ae919fb2b334bedc853", "sha256": "efe499c3855e174e7f2ac2d50d31c9db4ce320d840016362ac92ccb14dbc72c7" }, "downloads": -1, "filename": "gpar-0.1.2.tar.gz", "has_sig": false, "md5_digest": "c038b7a280e72ae919fb2b334bedc853", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17631, "upload_time": "2019-07-09T22:40:16", "url": "https://files.pythonhosted.org/packages/51/9a/174767faae814b842d807ce81c37ae2177befa3cfe0ddf03f9f96b91e656/gpar-0.1.2.tar.gz" } ] }