{ "metadata": { "name": "", "signature": "sha256:f855cd50a7036d5f21fea00acdafbd29d680a9474bb8afb20fa38eb212be0bdc" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Non Gaussian Likelihoods\n", "\n", "## Gaussian Winter School, Genova, Italy\n", "### 22nd January 2015\n", "### Ricardo Andrade Pacheco, Max Zwiessele, James Hensman and Neil Lawrence\n", "\n", "In this lab we are going to consider approaches to dealing with non-Gaussian likelihoods." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import GPy\n", "import pods\n", "from IPython.display import display" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 44 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "from matplotlib.patches import Polygon\n", "from matplotlib.collections import PatchCollection\n", "import cPickle as pickle\n", "import urllib\n", "\n", "urllib.urlretrieve('http://staffwww.dcs.sheffield.ac.uk/people/M.Zwiessele/gpss/lab2/EastTimor.pickle', 'EastTimor2.pickle')\n", "\n", "#Load the data\n", "with open(\"./EastTimor2.pickle\",\"rb\") as f:\n", " X,y,polygons = pickle.load(f)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 45 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we will create a map of East Timor and, using GPy, plot the data on top of it. \n", "A classification model can be defined in a similar way to the regression model, but now using `GPy.models.GPClassification`. However, once we've define the model, we also need to update the approximation to the likelihood. This runs the Expectation propagation updates." ] }, { "cell_type": "code", "collapsed": false, "input": [ "print y.shape\n", "print X.shape" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "(67, 1)\n", "(67, 2)\n" ] } ], "prompt_number": 46 }, { "cell_type": "code", "collapsed": false, "input": [ "#Visualize a map of East-Timor\n", "fig = plt.figure()\n", "ax = fig.add_subplot(111)\n", "for p in polygons:\n", " ax.add_collection(PatchCollection([Polygon(p)],facecolor=\"#F4A460\"))\n", "ax.set_xlim(124.,127.5)\n", "ax.set_ylim(-9.6,-8.1)\n", "ax.set_xlabel(\"longitude\")\n", "ax.set_ylabel(\"latitude\")\n", "\n", "#Define the model\n", "kern = GPy.kern.RBF(2)\n", "model = GPy.models.GPClassification(X,y, kernel=kern)\n", "display(model)\n", "model.plot(ax=ax)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", "\n", "
\n",
"Model: gp_classification
\n",
"Log-likelihood: -115.594679675
\n",
"Number of Parameters: 2
\n",
"
gp_classification. | \n", "Value | \n", "Constraint | \n", "Prior | \n", "Tied to | \n", "
---|---|---|---|---|
rbf.variance | 1.0 | +ve | ||
rbf.lengthscale | 1.0 | +ve |
\n",
"Model: gp_classification
\n",
"Log-likelihood: -107.199692241
\n",
"Number of Parameters: 2
\n",
"
gp_classification. | \n", "Value | \n", "Constraint | \n", "Prior | \n", "Tied to | \n", "
---|---|---|---|---|
rbf.variance | 1.66833160644 | +ve | ||
rbf.lengthscale | 0.316603830844 | +ve |
\n",
"Model: gp
\n",
"Log-likelihood: 0.229198900966
\n",
"Number of Parameters: 5
\n",
"
gp. | \n", "Value | \n", "Constraint | \n", "Prior | \n", "Tied to | \n", "
---|---|---|---|---|
add.rbf.variance | 0.369163294699 | +ve | ||
add.rbf.lengthscale | 24.7889955937 | +ve | ||
add.bias.variance | 8.71519672427 | +ve | ||
Student_T.t_scale2 | 0.00853947044833 | +ve | ||
Student_T.deg_free | 5.0 | +ve |