diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 4e86c6c619..7ac3cec3af 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -13,6 +13,7 @@ - Fixed `KeyError` raised when only subset of variables are specified to be recorded in the trace. - Removed unused `repeat=None` arguments from all `random()` methods in distributions. +- Deprecated the `sigma` argument in `MarginalSparse.marginal_likelihood` in favor of `noise` ## PyMC 3.4.1 (April 18 2018) diff --git a/pymc3/gp/gp.py b/pymc3/gp/gp.py index a692166ecc..db6a2f4c42 100644 --- a/pymc3/gp/gp.py +++ b/pymc3/gp/gp.py @@ -1,4 +1,5 @@ import functools +import warnings import numpy as np import theano.tensor as tt @@ -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 @@ -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`. @@ -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: diff --git a/pymc3/tests/test_gp.py b/pymc3/tests/test_gp.py index 1c9e474597..6f5e8bd66c 100644 --- a/pymc3/tests/test_gp.py +++ b/pymc3/tests/test_gp.py @@ -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)