Skip to content

Commit 5ed1046

Browse files
committed
working on docs
1 parent f71a428 commit 5ed1046

File tree

3 files changed

+130
-23
lines changed

3 files changed

+130
-23
lines changed

docs/source/notebooks/GP-Latent.ipynb

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"If `gp` is part of a sum of GP objects, it can be conditioned on different components of that sum using the optional keyword argument `given`,\n",
8686
"\n",
8787
"```python\n",
88-
" f_star_diff = gp.conditional(\"f_star_diff\", n_points=100, X_star, given=a_different_gp)\n",
88+
" f_star_diff = gp.conditional(\"f_star_diff\", n_points=100, X_star, \n",
89+
" gp=a_different_gp)\n",
8990
"```"
9091
]
9192
},
@@ -125,7 +126,8 @@
125126
"ExecuteTime": {
126127
"end_time": "2017-08-14T20:08:36.301608Z",
127128
"start_time": "2017-08-14T20:08:33.664334Z"
128-
}
129+
},
130+
"collapsed": false
129131
},
130132
"outputs": [
131133
{
@@ -190,7 +192,8 @@
190192
"ExecuteTime": {
191193
"end_time": "2017-08-14T20:13:07.436337Z",
192194
"start_time": "2017-08-14T20:08:36.443723Z"
193-
}
195+
},
196+
"collapsed": false
194197
},
195198
"outputs": [
196199
{
@@ -239,7 +242,8 @@
239242
"ExecuteTime": {
240243
"end_time": "2017-08-14T20:13:08.808843Z",
241244
"start_time": "2017-08-14T20:13:07.453184Z"
242-
}
245+
},
246+
"collapsed": false
243247
},
244248
"outputs": [
245249
{
@@ -264,7 +268,8 @@
264268
"ExecuteTime": {
265269
"end_time": "2017-08-14T20:13:09.647392Z",
266270
"start_time": "2017-08-14T20:13:08.810335Z"
267-
}
271+
},
272+
"collapsed": false
268273
},
269274
"outputs": [
270275
{
@@ -313,7 +318,8 @@
313318
"ExecuteTime": {
314319
"end_time": "2017-08-14T20:13:25.150070Z",
315320
"start_time": "2017-08-14T20:13:09.648849Z"
316-
}
321+
},
322+
"collapsed": false
317323
},
318324
"outputs": [
319325
{
@@ -345,7 +351,8 @@
345351
"ExecuteTime": {
346352
"end_time": "2017-08-14T20:13:26.148611Z",
347353
"start_time": "2017-08-14T20:13:25.177747Z"
348-
}
354+
},
355+
"collapsed": false
349356
},
350357
"outputs": [
351358
{
@@ -425,7 +432,8 @@
425432
"ExecuteTime": {
426433
"end_time": "2017-08-14T20:15:45.834572Z",
427434
"start_time": "2017-08-14T20:15:45.499711Z"
428-
}
435+
},
436+
"collapsed": false
429437
},
430438
"outputs": [
431439
{
@@ -453,7 +461,8 @@
453461
"ExecuteTime": {
454462
"end_time": "2017-08-14T20:24:59.612463Z",
455463
"start_time": "2017-08-14T20:15:45.841669Z"
456-
}
464+
},
465+
"collapsed": false
457466
},
458467
"outputs": [
459468
{
@@ -496,7 +505,8 @@
496505
"ExecuteTime": {
497506
"end_time": "2017-08-14T20:25:07.307076Z",
498507
"start_time": "2017-08-14T20:24:59.619823Z"
499-
}
508+
},
509+
"collapsed": false
500510
},
501511
"outputs": [
502512
{
@@ -521,7 +531,8 @@
521531
"ExecuteTime": {
522532
"end_time": "2017-08-14T20:25:29.473243Z",
523533
"start_time": "2017-08-14T20:25:07.308607Z"
524-
}
534+
},
535+
"collapsed": false
525536
},
526537
"outputs": [
527538
{
@@ -550,7 +561,8 @@
550561
"ExecuteTime": {
551562
"end_time": "2017-08-14T20:25:30.710482Z",
552563
"start_time": "2017-08-14T20:25:29.478224Z"
553-
}
564+
},
565+
"collapsed": false
554566
},
555567
"outputs": [
556568
{
@@ -592,7 +604,7 @@
592604
"name": "python",
593605
"nbconvert_exporter": "python",
594606
"pygments_lexer": "ipython3",
595-
"version": "3.5.3"
607+
"version": "3.5.2"
596608
}
597609
},
598610
"nbformat": 4,

docs/source/notebooks/GP-Marginal.ipynb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@
156156
"ExecuteTime": {
157157
"end_time": "2017-08-14T18:32:50.803008Z",
158158
"start_time": "2017-08-14T18:32:48.214450Z"
159-
}
159+
},
160+
"collapsed": false
160161
},
161162
"outputs": [
162163
{
@@ -208,7 +209,8 @@
208209
"ExecuteTime": {
209210
"end_time": "2017-08-14T18:32:55.433300Z",
210211
"start_time": "2017-08-14T18:32:50.805810Z"
211-
}
212+
},
213+
"collapsed": false
212214
},
213215
"outputs": [
214216
{
@@ -240,7 +242,8 @@
240242
"ExecuteTime": {
241243
"end_time": "2017-08-14T18:32:55.447681Z",
242244
"start_time": "2017-08-14T18:32:55.435521Z"
243-
}
245+
},
246+
"collapsed": false
244247
},
245248
"outputs": [
246249
{
@@ -333,7 +336,8 @@
333336
"ExecuteTime": {
334337
"end_time": "2017-08-14T18:34:37.785728Z",
335338
"start_time": "2017-08-14T18:32:55.449138Z"
336-
}
339+
},
340+
"collapsed": false
337341
},
338342
"outputs": [
339343
{
@@ -365,7 +369,8 @@
365369
"ExecuteTime": {
366370
"end_time": "2017-08-14T18:34:40.688955Z",
367371
"start_time": "2017-08-14T18:34:37.793988Z"
368-
}
372+
},
373+
"collapsed": false
369374
},
370375
"outputs": [
371376
{
@@ -412,7 +417,8 @@
412417
"ExecuteTime": {
413418
"end_time": "2017-08-14T18:36:16.040227Z",
414419
"start_time": "2017-08-14T18:34:40.690375Z"
415-
}
420+
},
421+
"collapsed": false
416422
},
417423
"outputs": [
418424
{
@@ -436,7 +442,8 @@
436442
"ExecuteTime": {
437443
"end_time": "2017-08-14T18:36:19.189319Z",
438444
"start_time": "2017-08-14T18:36:16.042082Z"
439-
}
445+
},
446+
"collapsed": false
440447
},
441448
"outputs": [
442449
{
@@ -496,7 +503,8 @@
496503
"ExecuteTime": {
497504
"end_time": "2017-08-14T18:36:20.178631Z",
498505
"start_time": "2017-08-14T18:36:19.190828Z"
499-
}
506+
},
507+
"collapsed": false
500508
},
501509
"outputs": [
502510
{
@@ -549,7 +557,7 @@
549557
"name": "python",
550558
"nbconvert_exporter": "python",
551559
"pygments_lexer": "ipython3",
552-
"version": "3.5.3"
560+
"version": "3.5.2"
553561
}
554562
},
555563
"nbformat": 4,

pymc3/gp/gp.py

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,47 @@ def predict(self, Xnew, point=None, given=None, diag=False):
5353

5454
@conditioned_vars(["X", "f"])
5555
class Latent(Base):
56-
""" Where the GP f isnt integrated out, and is sampled explicitly
56+
R"""
57+
The `gp.Latent` class is a direct implementation of a GP. No addiive
58+
noise is assumed. It is called "Latent" because the underlying function
59+
values are treated as latent variables. It has a `prior` method, and a
60+
`conditional` method. Given a mean and covariance function, the
61+
function $f(x)$ is modeled as,
62+
63+
.. math::
64+
65+
f(x) \sim \mathcal{GP}\left(\mu(x), k(x, x')\right)
66+
67+
Use the `prior` and `conditional` methods to construct random
68+
variables representing the unknown, or latent, function whose
69+
distribution is the GP prior or GP conditional. This GP implementation
70+
can be used to implement regression with non-normal likelihoods or
71+
classification.
72+
73+
Parameters
74+
----------
75+
cov_func : None, 2D array, or instance of Covariance
76+
The covariance function. Defaults to matrix of zeros.
77+
mean_func : None, instance of Mean
78+
The mean function. Defaults to a vector of ones.
79+
80+
Notes
81+
-----
82+
- After initializing the GP object with a mean and covariance
83+
function, it can be added to other `Latent` GP objects.
84+
85+
- For more information on the `prior` and `conditional` methods,
86+
see their docstrings.
87+
88+
Examples
89+
--------
90+
.. code:: python
91+
92+
with pm.Model() as model:
93+
94+
5795
"""
96+
5897
def __init__(self, mean_func=None, cov_func=None):
5998
super(Latent, self).__init__(mean_func, cov_func)
6099

@@ -69,6 +108,29 @@ def _build_prior(self, name, X, n_points, reparameterize=True):
69108
return f
70109

71110
def prior(self, name, X, n_points=None, reparameterize=True):
111+
R"""
112+
Returns the GP prior distribution evaluated over the input
113+
locations `X`. This is the prior probability over the space
114+
of functions described by its mean and covariance function.
115+
116+
.. math::
117+
118+
f \mid X \sim \text{MvNormal}\left(\boldsymbol\mu, \mathbf{K}\right)
119+
120+
Parameters
121+
----------
122+
name : string
123+
Name of the random variable
124+
X : array-like
125+
Function input values.
126+
n_points : int, optional
127+
Required if `X` is a random variable or a Theano object.
128+
This is the number of points the GP is evaluated over, the
129+
number of rows in `X`.
130+
reparameterize : bool
131+
Reparameterize the distribution by rotating the random
132+
variable by the Cholesky factor of the covariance matrix.
133+
"""
72134
n_points = infer_shape(X, n_points)
73135
f = self._build_prior(name, X, n_points, reparameterize)
74136
self.X = X
@@ -100,6 +162,31 @@ def _build_conditional(self, Xnew, X, f, cov_total, mean_total):
100162
return mu, cov
101163

102164
def conditional(self, name, Xnew, n_points=None, given=None):
165+
R"""
166+
Returns the conditional distribution evaluated over new input
167+
locations `Xnew`. Given a set of function values `f` that
168+
the GP prior was over, the conditional distribution over a
169+
set of new points, `f_*` is
170+
171+
.. math::
172+
173+
f^* \mid f, X, X_{\text{new}} \sim \mathcal{GP}\left(\mu(x), k(x, x')\right)
174+
175+
Parameters
176+
----------
177+
name : string
178+
Name of the random variable
179+
Xnew : array-like
180+
Function input values.
181+
n_points : int, optional
182+
Required if `Xnew` is a random variable or a Theano object.
183+
This is the number of points the GP is evaluated over, the
184+
number of rows in `Xnew`.
185+
given : keyword arguments
186+
The `gp.Latent` argument can optionally take as keyword args,
187+
`X`, `f`, and `gp`. See the tutorial on additive GP models in
188+
PyMC3 for more information.
189+
"""
103190
givens = self._get_given_vals(**given)
104191
mu, cov = self._build_conditional(Xnew, *givens)
105192
chol = cholesky(stabilize(cov))

0 commit comments

Comments
 (0)