From 4ad94ba774cd167107cc9c7d21a7f1c0ca5fe87d Mon Sep 17 00:00:00 2001 From: Christopher Fonnesbeck Date: Sun, 6 May 2018 21:56:56 -0500 Subject: [PATCH 1/5] Replaced sigma argument with noise in MarginalSparse.marginal_likelihood --- pymc3/gp/gp.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pymc3/gp/gp.py b/pymc3/gp/gp.py index a692166ecc..edc1c0ee6b 100644 --- a/pymc3/gp/gp.py +++ b/pymc3/gp/gp.py @@ -671,7 +671,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 +689,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 +702,18 @@ 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 + self.sigma = noise + if self.sigma 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) 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: From 27de84c0841cddbfdf2a07e2c3691dba95f702bc Mon Sep 17 00:00:00 2001 From: Christopher Fonnesbeck Date: Sun, 6 May 2018 22:00:24 -0500 Subject: [PATCH 2/5] Changed sigma to noise in test_gp for MarginalSparse.marginal_likelihood --- pymc3/tests/test_gp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/tests/test_gp.py b/pymc3/tests/test_gp.py index 1c9e474597..28a0d6c1ad 100644 --- a/pymc3/tests/test_gp.py +++ b/pymc3/tests/test_gp.py @@ -791,7 +791,7 @@ 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: From a2d8cda85003f37d1f2de5f636f0fec35a4b9a35 Mon Sep 17 00:00:00 2001 From: Christopher Fonnesbeck Date: Sun, 6 May 2018 23:13:39 -0500 Subject: [PATCH 3/5] Refactored handling of noise/sigma to avoidfe getter error --- pymc3/gp/gp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymc3/gp/gp.py b/pymc3/gp/gp.py index edc1c0ee6b..e87aaf49ee 100644 --- a/pymc3/gp/gp.py +++ b/pymc3/gp/gp.py @@ -702,8 +702,7 @@ def marginal_likelihood(self, name, X, Xu, y, noise=None, is_observed=True, **kw self.X = X self.Xu = Xu self.y = y - self.sigma = noise - if self.sigma is None: + if noise is None: sigma = kwargs.get('sigma') if sigma is None: raise ValueError('noise argument must be specified') @@ -712,6 +711,8 @@ def marginal_likelihood(self, name, X, Xu, y, noise=None, is_observed=True, **kw 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=noise) if is_observed: From fb4ed21b4f2db08550f7a739b3eb70edae8c85a9 Mon Sep 17 00:00:00 2001 From: Christopher Fonnesbeck Date: Sun, 6 May 2018 23:18:15 -0500 Subject: [PATCH 4/5] Changed instance of sigma to noise in gp_test; added warnings import --- pymc3/gp/gp.py | 1 + pymc3/tests/test_gp.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pymc3/gp/gp.py b/pymc3/gp/gp.py index e87aaf49ee..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 diff --git a/pymc3/tests/test_gp.py b/pymc3/tests/test_gp.py index 28a0d6c1ad..6f5e8bd66c 100644 --- a/pymc3/tests/test_gp.py +++ b/pymc3/tests/test_gp.py @@ -796,7 +796,7 @@ def testAdditiveMarginalSparse(self, approx): 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) From a370c9998b58b8e80357bc876ab3f7110b731761 Mon Sep 17 00:00:00 2001 From: Christopher Fonnesbeck Date: Thu, 10 May 2018 11:10:45 -0500 Subject: [PATCH 5/5] Added changes to release notes --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) 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)