Skip to content

Commit 0960323

Browse files
authored
Remove deprecated noise parameter for GPs (#7886)
1 parent 127ac30 commit 0960323

File tree

2 files changed

+3
-113
lines changed

2 files changed

+3
-113
lines changed

pymc/gp/gp.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,6 @@
3939
__all__ = ["TP", "Latent", "LatentKron", "Marginal", "MarginalApprox", "MarginalKron"]
4040

4141

42-
_noise_deprecation_warning = (
43-
"The 'noise' parameter has been been changed to 'sigma' "
44-
"in order to standardize the GP API and will be "
45-
"deprecated in future releases."
46-
)
47-
48-
49-
def _handle_sigma_noise_parameters(sigma, noise):
50-
"""Help transition of 'noise' parameter to be named 'sigma'."""
51-
if (sigma is None and noise is None) or (sigma is not None and noise is not None):
52-
raise ValueError("'sigma' argument must be specified.")
53-
54-
if sigma is None:
55-
warnings.warn(_noise_deprecation_warning, FutureWarning)
56-
return noise
57-
58-
return sigma
59-
60-
6142
class Base:
6243
"""Base class."""
6344

@@ -477,8 +458,7 @@ def marginal_likelihood(
477458
name,
478459
X,
479460
y,
480-
sigma=None,
481-
noise=None,
461+
sigma,
482462
jitter=JITTER_DEFAULT,
483463
is_observed=True,
484464
**kwargs,
@@ -505,8 +485,6 @@ def marginal_likelihood(
505485
sigma : float, Variable, or Covariance, default ~pymc.gp.cov.WhiteNoise
506486
Standard deviation of the Gaussian noise. Can also be a Covariance for
507487
non-white noise.
508-
noise : float, Variable, or Covariance, optional
509-
Deprecated. Previous parameterization of `sigma`.
510488
jitter : float, default 1e-6
511489
A small correction added to the diagonal of positive semi-definite
512490
covariance matrices to ensure numerical stability.
@@ -516,8 +494,6 @@ def marginal_likelihood(
516494
Extra keyword arguments that are passed to :class:`~pymc.MvNormal` distribution
517495
constructor.
518496
"""
519-
sigma = _handle_sigma_noise_parameters(sigma=sigma, noise=noise)
520-
521497
noise_func = sigma if isinstance(sigma, BaseCovariance) else pm.gp.cov.WhiteNoise(sigma)
522498
mu, cov = self._build_marginal_likelihood(X=X, noise_func=noise_func, jitter=jitter)
523499
self.X = X
@@ -544,10 +520,6 @@ def _get_given_vals(self, given):
544520
cov_total = self.cov_func
545521
mean_total = self.mean_func
546522

547-
if "noise" in given:
548-
warnings.warn(_noise_deprecation_warning, FutureWarning)
549-
given["sigma"] = given["noise"]
550-
551523
if all(val in given for val in ["X", "y", "sigma"]):
552524
X, y, sigma = given["X"], given["y"], given["sigma"]
553525
noise_func = sigma if isinstance(sigma, BaseCovariance) else pm.gp.cov.WhiteNoise(sigma)
@@ -804,9 +776,7 @@ def _build_marginal_likelihood_loglik(self, y, X, Xu, sigma, jitter):
804776
quadratic = 0.5 * (pt.dot(r, r_l) - pt.dot(c, c))
805777
return -1.0 * (constant + logdet + quadratic + trace)
806778

807-
def marginal_likelihood(
808-
self, name, X, Xu, y, sigma=None, noise=None, jitter=JITTER_DEFAULT, **kwargs
809-
):
779+
def marginal_likelihood(self, name, X, Xu, y, sigma, jitter=JITTER_DEFAULT, **kwargs):
810780
R"""
811781
Return the approximate marginal likelihood distribution.
812782
@@ -827,8 +797,6 @@ def marginal_likelihood(
827797
noise. Must have shape `(n, )`.
828798
sigma : float, Variable
829799
Standard deviation of the Gaussian noise.
830-
noise : float, Variable, optional
831-
Previous parameterization of `sigma`.
832800
jitter : float, default 1e-6
833801
A small correction added to the diagonal of positive semi-definite
834802
covariance matrices to ensure numerical stability.
@@ -840,7 +808,7 @@ def marginal_likelihood(
840808
self.Xu = Xu
841809
self.y = y
842810

843-
self.sigma = _handle_sigma_noise_parameters(sigma=sigma, noise=noise)
811+
self.sigma = sigma
844812

845813
approx_loglik = self._build_marginal_likelihood_loglik(
846814
y=self.y, X=self.X, Xu=self.Xu, sigma=self.sigma, jitter=jitter

tests/gp/test_gp.py

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -25,84 +25,6 @@
2525
from pymc.math import cartesian
2626

2727

28-
class TestSigmaParams:
29-
def setup_method(self):
30-
"""Common setup."""
31-
self.x = np.linspace(-5, 5, 30)[:, None]
32-
self.xu = np.linspace(-5, 5, 10)[:, None]
33-
self.y = np.random.normal(0.25 * self.x, 0.1)
34-
35-
with pm.Model() as self.model:
36-
cov_func = pm.gp.cov.Linear(1, c=0.0)
37-
c = pm.Normal("c", mu=20.0, sigma=100.0)
38-
mean_func = pm.gp.mean.Constant(c)
39-
self.gp = self.gp_implementation(mean_func=mean_func, cov_func=cov_func)
40-
self.sigma = pm.HalfNormal("sigma", sigma=100)
41-
42-
43-
class TestMarginalSigmaParams(TestSigmaParams):
44-
R"""Tests for the deprecation warnings and raising ValueError."""
45-
46-
gp_implementation = pm.gp.Marginal
47-
48-
def test_catch_warnings(self):
49-
"""Warning from using the old noise parameter."""
50-
with self.model:
51-
with pytest.warns(FutureWarning):
52-
self.gp.marginal_likelihood("lik_noise", X=self.x, y=self.y, noise=self.sigma)
53-
54-
with pytest.warns(FutureWarning):
55-
self.gp.conditional(
56-
"cond_noise",
57-
Xnew=self.x,
58-
given={
59-
"noise": self.sigma,
60-
},
61-
)
62-
63-
def test_raise_value_error(self):
64-
"""Either both or neither parameter is specified."""
65-
with self.model:
66-
with pytest.raises(ValueError):
67-
self.gp.marginal_likelihood(
68-
"like_both", X=self.x, y=self.y, noise=self.sigma, sigma=self.sigma
69-
)
70-
71-
with pytest.raises(ValueError):
72-
self.gp.marginal_likelihood("like_neither", X=self.x, y=self.y)
73-
74-
75-
class TestMarginalApproxSigmaParams(TestSigmaParams):
76-
R"""Tests for the deprecation warnings and raising ValueError"""
77-
78-
gp_implementation = pm.gp.MarginalApprox
79-
80-
@pytest.mark.xfail(reason="Possible shape problem, see #6366")
81-
def test_catch_warnings(self):
82-
"""Warning from using the old noise parameter."""
83-
with self.model:
84-
with pytest.warns(FutureWarning):
85-
self.gp.marginal_likelihood(
86-
"lik_noise", X=self.x, Xu=self.xu, y=self.y, noise=self.sigma
87-
)
88-
89-
def test_raise_value_error(self):
90-
"""Either both or neither parameter is specified."""
91-
with self.model:
92-
with pytest.raises(ValueError):
93-
self.gp.marginal_likelihood(
94-
"like_both",
95-
X=self.x,
96-
Xu=self.xu,
97-
y=self.y,
98-
noise=self.sigma,
99-
sigma=self.sigma,
100-
)
101-
102-
with pytest.raises(ValueError):
103-
self.gp.marginal_likelihood("like_neither", X=self.x, Xu=self.xu, y=self.y)
104-
105-
10628
class TestMarginalVsMarginalApprox:
10729
R"""
10830
Compare test fits of models Marginal and MarginalApprox.

0 commit comments

Comments
 (0)