{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#import necessary modules, set up the plotting\n", "import numpy as np\n", "%matplotlib inline\n", "%config InlineBackend.figure_format = 'svg'\n", "import matplotlib;matplotlib.rcParams['figure.figsize'] = (8,6)\n", "from matplotlib import pyplot as plt\n", "import GPy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Interacting with models\n", "\n", "### November 2014, by Max Zwiessele\n", "#### with edits by James Hensman\n", "\n", "The GPy model class has a set of features which are designed to make it simple to explore the parameter space of the model. By default, the scipy optimisers are used to fit GPy models (via model.optimize()), for which we provide mechanisms for ‘free’ optimisation: GPy can ensure that naturally positive parameters (such as variances) remain positive. But these mechanisms are much more powerful than simple reparameterisation, as we shall see.\n", "\n", "Along this tutorial we’ll use a sparse GP regression model as example. This example can be in GPy.examples.regression. All of the examples included in GPy return an instance of a model class, and therefore they can be called in the following way:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "m = GPy.examples.regression.sparse_GP_regression_1D(plot=False, optimize=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Examining the model using print\n", "\n", "To see the current state of the model parameters, and the model’s (marginal) likelihood just print the model\n", "\n", " print m\n", "\n", "The first thing displayed on the screen is the log-likelihood value of the model with its current parameters. Below the log-likelihood, a table with all the model’s parameters is shown. For each parameter, the table contains the name of the parameter, the current value, and in case there are defined: constraints, ties and prior distrbutions associated." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "

\n", "Model: sparse gp
\n", "Objective: 422.820894957
\n", "Number of Parameters: 8
\n", "Number of Optimization Parameters: 8
\n", "Updates: True
\n", "

\n", "\n", "\n", "\n", "\n", "\n", "\n", "
sparse_gp. valueconstraintspriors
inducing inputs (5, 1)
rbf.variance 1.0 +ve
rbf.lengthscale 1.0 +ve
Gaussian_noise.variance 1.0 +ve
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this case the kernel parameters (`bf.variance`, `bf.lengthscale`) as well as the likelihood noise parameter (`Gaussian_noise.variance`), are constrained to be positive, while the inducing inputs have no constraints associated. Also there are no ties or prior defined.\n", "\n", "You can also print all subparts of the model, by printing the subcomponents individually; this will print the details of this particular parameter handle:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
rbf. valueconstraintspriors
variance 1.0 +ve
lengthscale 1.0 +ve
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m.rbf" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When you want to get a closer look into multivalue parameters, print them directly:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "\u001b[1msparse_gp.inducing_inputs\u001b[0;0m:\n", "Param([[ 0.1745099 ],\n", " [ 2.19478599],\n", " [ 1.0945254 ],\n", " [-0.42446266],\n", " [ 0.45784368]])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m.inducing_inputs" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "m.inducing_inputs[0] = 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interacting with Parameters:\n", "\n", "The preferred way of interacting with parameters is to act on the parameter handle itself. Interacting with parameter handles is simple. The names, printed by print m are accessible interactively and programatically. For example try to set the kernel's `lengthscale` to 0.2 and print the result:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Name : sparse gp\n", "Objective : 590.608017128\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 8\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | | \n", " \u001b[1mrbf.variance \u001b[0;0m | 1.0 | +ve | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 0.2 | +ve | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 1.0 | +ve | \n" ] } ], "source": [ "m.rbf.lengthscale = 0.2\n", "print m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This will already have updated the model’s inner state: note how the log-likelihood has changed. YOu can immediately plot the model or see the changes in the posterior (`m.posterior`) of the model." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Regular expressions\n", "\n", "The model’s parameters can also be accessed through regular expressions, by ‘indexing’ the model with a regular expression, matching the parameter name. Through indexing by regular expression, you can only retrieve leafs of the hierarchy, and you can retrieve the values matched by calling `values()` on the returned object" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \u001b[1mindex\u001b[0;0m | sparse_gp.rbf.variance | constraints | priors\n", " \u001b[1m[0] \u001b[0;0m | 1.00000000 | +ve | \n", " \u001b[1m-----\u001b[0;0m | sparse_gp.Gaussian_noise.variance | ----------- | ------\n", " \u001b[1m[0] \u001b[0;0m | 1.00000000 | +ve | \n" ] } ], "source": [ "print m['.*var']\n", "#print \"variances as a np.array:\", m['.*var'].values()\n", "#print \"np.array of rbf matches: \", m['.*rbf'].values()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is access to setting parameters by regular expression, as well. Here are a few examples of how to set parameters by regular expression. Note that each time the values are set, computations are done internally to compute the log likeliood of the model." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Name : sparse gp\n", "Objective : 694.201181379\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 8\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | | \n", " \u001b[1mrbf.variance \u001b[0;0m | 2.0 | +ve | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 0.2 | +ve | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 2.0 | +ve | \n", "\n", "Name : sparse gp\n", "Objective : 714.484895561\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 8\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | | \n", " \u001b[1mrbf.variance \u001b[0;0m | 2.0 | +ve | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 0.2 | +ve | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 3.0 | +ve | \n" ] } ], "source": [ "m['.*var'] = 2.\n", "print m\n", "m['.*var'] = [2., 3.]\n", "print m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A handy trick for seeing all of the parameters of the model at once is to regular-expression match every variable:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \u001b[1mindex\u001b[0;0m | sparse_gp.inducing_inputs | constraints | priors\n", " \u001b[1m[0 0]\u001b[0;0m | 1.00000000 | | \n", " \u001b[1m[1 0]\u001b[0;0m | 2.19478599 | | \n", " \u001b[1m[2 0]\u001b[0;0m | 1.09452540 | | \n", " \u001b[1m[3 0]\u001b[0;0m | -0.42446266 | | \n", " \u001b[1m[4 0]\u001b[0;0m | 0.45784368 | | \n", " \u001b[1m-----\u001b[0;0m | sparse_gp.rbf.variance | ----------- | ------\n", " \u001b[1m[0] \u001b[0;0m | 2.00000000 | +ve | \n", " \u001b[1m-----\u001b[0;0m | sparse_gp.rbf.lengthscale | ----------- | ------\n", " \u001b[1m[0] \u001b[0;0m | 0.20000000 | +ve | \n", " \u001b[1m-----\u001b[0;0m | sparse_gp.Gaussian_noise.variance | ----------- | ------\n", " \u001b[1m[0] \u001b[0;0m | 3.00000000 | +ve | \n" ] } ], "source": [ "print m['']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting and fetching parameters parameter_array\n", "\n", "Another way to interact with the model’s parameters is through the parameter_array. The Parameter array holds all the parameters of the model in one place and is editable. It can be accessed through indexing the model for example you can set all the parameters through this mechanism:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[-4. -2. 0. 2. 4. 0.1 2. 0.7]\n", "\n", "Name : sparse gp\n", "Objective : 322.317452127\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 8\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | | \n", " \u001b[1mrbf.variance \u001b[0;0m | 0.1 | +ve | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 2.0 | +ve | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 0.7 | +ve | \n" ] } ], "source": [ "new_params = np.r_[[-4,-2,0,2,4], [.1,2], [.7]]\n", "print new_params\n", "\n", "m[:] = new_params\n", "print m " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Parameters themselves (leafs of the hierarchy) can be indexed and used the same way as numpy arrays. First let us set a slice of the inducing_inputs:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \u001b[1mindex\u001b[0;0m | sparse_gp.inducing_inputs | constraints | priors\n", " \u001b[1m[0 0]\u001b[0;0m | -4.00000000 | | \n", " \u001b[1m[1 0]\u001b[0;0m | -2.00000000 | | \n", " \u001b[1m[2 0]\u001b[0;0m | 1.00000000 | | \n", " \u001b[1m[3 0]\u001b[0;0m | 3.00000000 | | \n", " \u001b[1m[4 0]\u001b[0;0m | 5.00000000 | | \n" ] } ], "source": [ "m.inducing_inputs[2:, 0] = [1,3,5]\n", "print m.inducing_inputs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or you use the parameters as normal numpy arrays for calculations:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ 1.42857143]\n" ] } ], "source": [ "precision = 1./m.Gaussian_noise.variance\n", "print precision" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting the model parameter’s gradients\n", "\n", "The gradients of a model can shed light on understanding the (possibly hard) optimization process. The gradients of each parameter handle can be accessed through their gradient field.:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "all gradients of the model:\n", "[ 2.01697286 3.69837406 1.1975515 -0.38669436 -0.31342694\n", " 99.38364871 -12.37834911 -268.18547317]\n", "\n", " gradients of the rbf kernel:\n", "[ 99.38364871 -12.37834911]\n" ] } ], "source": [ "print \"all gradients of the model:\\n\", m.gradient\n", "print \"\\n gradients of the rbf kernel:\\n\", m.rbf.gradient" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we optimize the model, the gradients (should be close to) zero" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ -9.07579744e-04 1.55292147e-03 2.70479755e-04 8.65120340e-04\n", " 9.78466589e-04 4.66719022e-04 2.65199506e-04 -3.76904571e-01]\n" ] } ], "source": [ "m.optimize()\n", "print m.gradient" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Adjusting the model’s constraints\n", "\n", "When we initially call the example, it was optimized and hence the log-likelihood gradients were close to zero. However, since we have been changing the parameters, the gradients are far from zero now. Next we are going to show how to optimize the model setting different restrictions on the parameters.\n", "\n", "Once a constraint has been set on a parameter, it is possible to remove it with the command unconstrain(), which can be called on any parameter handle of the model. The methods constrain() and unconstrain() return the indices which were actually unconstrained, relative to the parameter handle the method was called on. This is particularly handy for reporting which parameters where reconstrained, when reconstraining a parameter, which was already constrained:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Name : sparse gp\n", "Objective : -590.884678521\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 8\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | | \n", " \u001b[1mrbf.variance \u001b[0;0m | 1.37750834107 | | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 2.47448694644 | +ve | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 0.00267772602954 | +ve | \n" ] } ], "source": [ "m.rbf.variance.unconstrain()\n", "print m" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Name : sparse gp\n", "Objective : -590.884678521\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 8\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | | \n", " \u001b[1mrbf.variance \u001b[0;0m | 1.37750834107 | | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 2.47448694644 | | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 0.00267772602954 | | \n" ] } ], "source": [ "m.unconstrain()\n", "print m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to unconstrain only a specific constraint, you can call the respective method, such as `unconstrain_fixed()` (or `unfix()`) to only unfix fixed parameters:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Name : sparse gp\n", "Objective : -590.884678521\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 7\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | {fixed} | \n", " \u001b[1mrbf.variance \u001b[0;0m | 1.37750834107 | +ve | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 2.47448694644 | +ve | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 0.00267772602954 | | \n", "\n", "Name : sparse gp\n", "Objective : -590.884678521\n", "Number of Parameters : 8\n", "Number of Optimization Parameters : 8\n", "Updates : True\n", "Parameters:\n", " \u001b[1msparse_gp. \u001b[0;0m | value | constraints | priors\n", " \u001b[1minducing inputs \u001b[0;0m | (5, 1) | | \n", " \u001b[1mrbf.variance \u001b[0;0m | 1.37750834107 | +ve | \n", " \u001b[1mrbf.lengthscale \u001b[0;0m | 2.47448694644 | +ve | \n", " \u001b[1mGaussian_noise.variance\u001b[0;0m | 0.00267772602954 | | \n" ] } ], "source": [ "m.inducing_inputs[0].fix()\n", "m.rbf.constrain_positive()\n", "print m\n", "m.unfix()\n", "print m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tying Parameters\n", "\n", "Not yet implemented for GPy version 0.8.0\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Optimizing the model\n", "\n", "Once we have finished defining the constraints, we can now optimize the model with the function optimize.:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARNING: reconstraining parameters sparse_gp.rbf\n" ] } ], "source": [ "m.Gaussian_noise.constrain_positive()\n", "m.rbf.constrain_positive()\n", "m.optimize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By deafult, GPy uses the lbfgsb optimizer.\n", "\n", "Some optional parameters may be discussed here.\n", "\n", " * `optimizer`: which optimizer to use, currently there are lbfgsb, fmin_tnc, scg, simplex or any unique identifier uniquely identifying an optimizer.\n", "Thus, you can say m.optimize('bfgs') for using the `lbfgsb` optimizer\n", " * `messages`: if the optimizer is verbose. Each optimizer has its own way of printing, so do not be confused by differing messages of different optimizers\n", " * `max_iters`: Maximum number of iterations to take. Some optimizers see iterations as function calls, others as iterations of the algorithm. Please be advised to look into scipy.optimize for more instructions, if the number of iterations matter, so you can give the right parameters to optimize()\n", " * `gtol`: only for some optimizers. Will determine the convergence criterion, as the tolerance of gradient to finish the optimization.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting\n", "Many of GPys models have built-in plot functionality. we distringuish between plotting the posterior of the function (`m.plot_f`) and plotting the posterior over predicted data values (`m.plot`). This becomes especially important for non-Gaussian likleihoods. Here we'll plot the sparse GP model we've been working with. for more information of the meaning of the plot, please refer to the accompanying `basic_gp_regression` and `sparse_gp` noteooks." ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = m.plot()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "We can even change the backend for plotting and plot the model using a different backend." ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "This is the format of your plot grid:\n", "[ (1,1) x1,y1 ]\n", "\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "GPy.plotting.change_plotting_library('plotly')\n", "fig = m.plot(plot_density=True)\n", "GPy.plotting.show(fig, filename='gpy_sparse_gp_example')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }
indexsparse_gp.inducing_inputsconstraintspriors
[0 0] 0.17450990
[1 0] 2.19478599
[2 0] 1.09452540
[3 0] -0.42446266
[4 0] 0.45784368