Skip to content

Commit 424c52c

Browse files
committed
more docstrings
1 parent 6fe8a53 commit 424c52c

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed

docs/source/notebooks/GP-Latent.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"\\end{aligned}\n",
5656
"$$\n",
5757
"\n",
58-
"For more information about this reparameterization, see the secion on [drawing values from a multivariate distribution](https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Drawing_values_from_the_distribution). This reparameterization can be disabled by setting the optional flag in the `prior` method, `reparameterize = False`. The default is `True`."
58+
"For more information about this reparameterization, see the section on [drawing values from a multivariate distribution](https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Drawing_values_from_the_distribution). This reparameterization can be disabled by setting the optional flag in the `prior` method, `reparameterize = False`. The default is `True`."
5959
]
6060
},
6161
{
@@ -64,15 +64,15 @@
6464
"source": [
6565
"## `.conditional`\n",
6666
"\n",
67-
"The conditional method implements the \"predictive\" distribution for function values that were not necessarily part of the data set. This distribution is,\n",
67+
"The conditional method implements the \"predictive\" distribution for function values that were not part of the original data set. This distribution is,\n",
6868
"\n",
6969
"$$\n",
7070
"\\mathbf{f}_* \\mid \\mathbf{f} \\sim \\text{MvNormal} \\left(\n",
7171
" \\mathbf{m}_* + \\mathbf{K}_{*x}\\mathbf{K}_{xx}^{-1} \\mathbf{f} ,\\,\n",
7272
" \\mathbf{K}_{**} - \\mathbf{K}_{*x}\\mathbf{K}_{xx}^{-1}\\mathbf{K}_{x*} \\right)\n",
7373
"$$\n",
7474
"\n",
75-
"In PyMC3, using the same `gp` that we defined above, this is specified as,\n",
75+
"Using the same `gp` object we defined above, this is specified as,\n",
7676
"\n",
7777
"```python\n",
7878
"# vector of new X points we want to predict the function at\n",

pymc3/gp/gp.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ def _build_prior(self, name, n_points, X, reparameterize=True):
239239
return f
240240

241241
def prior(self, name, n_points, X, reparameterize=True):
242+
R"""
243+
Returns the TP prior distribution evaluated over the input
244+
locations `X`. This is the prior probability over the space
245+
of functions described by its mean and covariance function.
246+
247+
.. math::
248+
249+
f \mid X \sim \text{MvStudentT}\left(\boldsymbol\mu, \mathbf{K}, \nu \right)
250+
251+
Parameters
252+
----------
253+
name : string
254+
Name of the random variable
255+
X : array-like
256+
Function input values.
257+
n_points : int, optional
258+
Required if `X` is a random variable or a Theano object.
259+
This is the number of points the GP is evaluated over, the
260+
number of rows in `X`.
261+
reparameterize : bool
262+
Reparameterize the distribution by rotating the random
263+
variable by the Cholesky factor of the covariance matrix.
264+
"""
242265
f = self._build_prior(name, n_points, X, reparameterize)
243266
self.X = X
244267
self.f = f
@@ -290,6 +313,54 @@ def conditional(self, name, Xnew, n_points=None):
290313

291314
@conditioned_vars(["X", "y", "noise"])
292315
class Marginal(Base):
316+
R"""
317+
The `gp.Marginal` class is an implementation of the sum of a GP
318+
prior and additive noise. It has `marginal_likelihood`, `conditional`
319+
and `predict` methods. This GP implementation can be used to
320+
implement regression on data that is normally distributed.
321+
322+
Parameters
323+
----------
324+
cov_func : None, 2D array, or instance of Covariance
325+
The covariance function. Defaults to zero.
326+
mean_func : None, instance of Mean
327+
The mean function. Defaults to zero.
328+
329+
Examples
330+
--------
331+
.. code:: python
332+
333+
# A one dimensional column vector of inputs.
334+
X = np.linspace(0, 1, 10)[:, None]
335+
336+
with pm.Model() as model:
337+
# Specify the covariance function.
338+
cov_func = pm.gp.cov.ExpQuad(1, lengthscales=0.1)
339+
340+
# Specify the GP. The default mean function is `Zero`.
341+
gp = pm.gp.Latent(cov_func=cov_func)
342+
343+
# Place a GP prior over the function f.
344+
sigma = pm.HalfCauchy("sigma", beta=3)
345+
y_ = gp.marginal_likelihood("y", X=X, y=y, noise=sigma)
346+
347+
...
348+
349+
# After fitting or sampling, specify the distribution
350+
# at new points with .conditional
351+
Xnew = np.linspace(-1, 2, 50)[:, None]
352+
353+
with model:
354+
fcond = gp.conditional("fcond", Xnew=Xnew)
355+
356+
Notes
357+
-----
358+
- After initializing the GP object with a mean and covariance
359+
function, it can be added to other `Latent` GP objects.
360+
361+
- For more information on the `prior` and `conditional` methods,
362+
see their docstrings.
363+
"""
293364

294365
def __init__(self, mean_func=None, cov_func=None):
295366
super(Marginal, self).__init__(mean_func, cov_func)

0 commit comments

Comments
 (0)