Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pymc3/gp/gp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import warnings

import numpy as np
import theano.tensor as tt
Expand Down Expand Up @@ -671,7 +672,7 @@ def _build_marginal_likelihood_logp(self, y, X, Xu, sigma):
quadratic = 0.5 * (tt.dot(r, r_l) - tt.dot(c, c))
return -1.0 * (constant + logdet + quadratic + trace)

def marginal_likelihood(self, name, X, Xu, y, sigma, is_observed=True, **kwargs):
def marginal_likelihood(self, name, X, Xu, y, noise=None, is_observed=True, **kwargs):
R"""
Returns the approximate marginal likelihood distribution, given the input
locations `X`, inducing point locations `Xu`, data `y`, and white noise
Expand All @@ -689,7 +690,7 @@ def marginal_likelihood(self, name, X, Xu, y, sigma, is_observed=True, **kwargs)
y : array-like
Data that is the sum of the function with the GP prior and Gaussian
noise. Must have shape `(n, )`.
sigma : scalar, Variable
noise : scalar, Variable
Standard deviation of the Gaussian noise.
is_observed : bool
Whether to set `y` as an `observed` variable in the `model`.
Expand All @@ -702,9 +703,19 @@ def marginal_likelihood(self, name, X, Xu, y, sigma, is_observed=True, **kwargs)
self.X = X
self.Xu = Xu
self.y = y
self.sigma = sigma
if noise is None:
sigma = kwargs.get('sigma')
if sigma is None:
raise ValueError('noise argument must be specified')
else:
self.sigma = sigma
warnings.warn(
"The 'sigma' argument has been deprecated. Use 'noise' instead.",
DeprecationWarning)
else:
self.sigma = noise
logp = functools.partial(self._build_marginal_likelihood_logp,
X=X, Xu=Xu, sigma=sigma)
X=X, Xu=Xu, sigma=noise)
if is_observed:
return pm.DensityDist(name, logp, observed=y, **kwargs)
else:
Expand Down
4 changes: 2 additions & 2 deletions pymc3/tests/test_gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,12 @@ def testAdditiveMarginalSparse(self, approx):
gp3 = pm.gp.MarginalSparse(self.means[2], self.covs[2], approx=approx)

gpsum = gp1 + gp2 + gp3
fsum = gpsum.marginal_likelihood("f", self.X, Xu, self.y, sigma=sigma)
fsum = gpsum.marginal_likelihood("f", self.X, Xu, self.y, noise=sigma)
model1_logp = model1.logp({"fsum": self.y})

with pm.Model() as model2:
gptot = pm.gp.MarginalSparse(reduce(add, self.means), reduce(add, self.covs), approx=approx)
fsum = gptot.marginal_likelihood("f", self.X, Xu, self.y, sigma=sigma)
fsum = gptot.marginal_likelihood("f", self.X, Xu, self.y, noise=sigma)
model2_logp = model2.logp({"fsum": self.y})
npt.assert_allclose(model1_logp, model2_logp, atol=0, rtol=1e-2)

Expand Down