|
120 | 120 | "\n",
|
121 | 121 | "Here the `lengthscales` parameter is two dimensional, each dimension can have different lengthscales. The reason we have to specify `input_dim`, the total number of columns of `X`, and `active_dims`, which of those columns or dimensions the covariance function will act on, is because `cov_func` hasn't actually seen the input data yet. The `active_dims` argument is optional, and defaults to all columns of the matrix of inputs. \n",
|
122 | 122 | "\n",
|
123 |
| - "Covariance functions in PyMC3 closely follow the algebraic rules for kernels:\n", |
| 123 | + "Covariance functions in PyMC3 closely follow the algebraic rules for kernels, which allows users to combine covariance functions into new ones, for example:\n", |
124 | 124 | "\n",
|
125 | 125 | "- The sum two covariance functions is also a covariance function.\n",
|
126 | 126 | "\n",
|
|
137 | 137 | " \n",
|
138 | 138 | " cov_func = eta**2 * pm.gp.cov.Matern32(...)\n",
|
139 | 139 | " \n",
|
140 |
| - "- ...\n", |
141 |
| - "\n", |
142 |
| - "Like the `gp.*` objects, until the covariance functions are actually *evaluated* over a set of inputs, they are still a Python objects that aren't part of the model. To evaluate a covariance function and create an actual covariance matrix, call `cov_func(x, x)`, or `cov_func(x, x_new)`. " |
| 140 | + "For more information on combining covariance functions in PyMC3, check out the tutorial on covariance functions. Like the `gp.*` objects, until the covariance functions are actually *evaluated* over a set of inputs, they are still a Python objects that aren't part of the model. To evaluate a covariance function and create an actual covariance matrix, call `cov_func(x, x)`, or `cov_func(x, x_new)`. " |
143 | 141 | ]
|
144 | 142 | },
|
145 | 143 | {
|
|
148 | 146 | "source": [
|
149 | 147 | "# Example: `gp.Latent`\n",
|
150 | 148 | "\n",
|
151 |
| - "The following is an example showing how to specify a simple model with a GP prior, and then sample from the posterior using NUTS. We build an example data set to use using a multivariate normal and known covariance function to generate the data so we can verify that the inference we perform is correct." |
| 149 | + "The following is an example showing how to specify a simple model with a GP prior, then sample from the posterior using NUTS. We build an example data with a draw from a GP, so we can verify that the inference we perform is correct." |
152 | 150 | ]
|
153 | 151 | },
|
154 | 152 | {
|
155 | 153 | "cell_type": "code",
|
156 |
| - "execution_count": 1, |
| 154 | + "execution_count": 14, |
157 | 155 | "metadata": {
|
158 | 156 | "ExecuteTime": {
|
159 |
| - "end_time": "2017-08-04T21:00:54.024910Z", |
160 |
| - "start_time": "2017-08-04T21:00:53.091113Z" |
| 157 | + "end_time": "2017-08-05T00:30:53.357774Z", |
| 158 | + "start_time": "2017-08-05T00:30:53.348602Z" |
161 | 159 | },
|
162 | 160 | "collapsed": true
|
163 | 161 | },
|
|
437 | 435 | "source": [
|
438 | 436 | "# Example: `gp.Marginal`\n",
|
439 | 437 | "\n",
|
440 |
| - "There is a more efficient way to model the last example. Most GP introductions or tutorials describe the scenario we just covered -- regression with IID Gaussian noise. This is a special case, but is the most common GP model that people use. Here there is no need to explicitly include the unknown function values as latent variables because $\\mathbf{f}_x$ can be integrated out analytically. The product of the GP prior probability distribution with a normal likelihood is also normal, and is called the *marginal likelihood*. Including the prior on the hyperparameters of the covariance function, we can write the *marginal posterior* as\n", |
| 438 | + "There is a more efficient way to model the last example. Most GP introductions or tutorials describe the scenario we just covered -- regression with IID Gaussian noise. This is the most common GP model that people use, but it's really a special case. When the noise is Gaussian there is no need to explicitly include $\\mathbf{f}_x$ as latent variables because it can be integrated out analytically. \n", |
| 439 | + "\n", |
| 440 | + "As mentioned before, the product of the GP prior probability distribution with a normal likelihood is also normal. It's called the *marginal likelihood*. If we including the prior on the hyperparameters of the covariance function, we can write the *marginal posterior* as\n", |
441 | 441 | "\n",
|
442 | 442 | "$$\n",
|
443 | 443 | "p(y \\mid x, \\theta)p(\\theta) = \\int p(y \\mid f, x, \\theta) \\, p(f \\mid x, \\theta) \\,\n",
|
|
453 | 453 | " - \\frac{n}{2}\\log (2 \\pi) + \\log p(\\theta)\n",
|
454 | 454 | "$$\n",
|
455 | 455 | "\n",
|
456 |
| - "The first term penalizes lack of fit, the second term penalizes model complexity via the determinant of $K_{xx}$. The third term is just a constant. The final term is the log-prior of the covariance function hyperparameters. \n", |
| 456 | + "The first term penalizes lack of fit, the second term penalizes model complexity via the determinant of $K_{xx}$. The third term is just a constant. The final term on the right is the log-prior of the covariance function hyperparameters. \n", |
457 | 457 | "\n",
|
458 |
| - "We repeat the previous example using `gp.Marginal` instead. The code to specify this equivalent model is a little bit different that before. Notice that `gp.marginal_likelihood` subsumes both the GP prior and the Normal likelihood of the observed data, `y`. Also, since we are using the marginal likelihood, it is possible to use `find_MAP` to quickly get the value at the mode of the covariance function hyperparameters. " |
| 458 | + "The code to specify this equivalent model using `gp.Marginal` is a little bit different that before. The `gp.marginal_likelihood` subsumes both the GP prior and the Normal likelihood of the observed data, `y`. Also, since we are using the marginal likelihood, it is possible to use `find_MAP` to quickly get the value at the mode of the covariance function hyperparameters. " |
459 | 459 | ]
|
460 | 460 | },
|
461 | 461 | {
|
|
0 commit comments