Skip to content

Commit

Permalink
Fix docs in GP submodule (pymc-devs#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirthasheshpatel authored Jul 25, 2020
1 parent df4a873 commit c75f577
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 2 additions & 6 deletions pymc4/gp/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,6 @@ class Constant(Stationary):
>>> from pymc4.gp.cov import Constant
>>> import numpy as np
>>> k = Constant(coef=5., feature_ndims=1)
>>> k
<pymc4.gp.cov.Constant object at 0x000001C96936DE10>
>>> X1 = np.array([[1.], [2.], [3.]])
>>> X2 = np.array([[4.], [5.], [6.]])
>>> k(X1, X2)
Expand Down Expand Up @@ -564,8 +562,6 @@ class WhiteNoise(Stationary):
>>> from pymc4.gp.cov import WhiteNoise
>>> import numpy as np
>>> k = WhiteNoise(noise=1e-4, feature_ndims=1)
>>> k
<pymc4.gp.cov.WhiteNoise object at 0x00000162FC073390>
>>> X1 = np.array([[1.], [2.]])
>>> X2 = np.array([[3.], [4.]])
>>> k(X1, X2)
Expand Down Expand Up @@ -779,8 +775,8 @@ class Matern32(Stationary):
>>> k = Matern32(1.)
>>> k(x, x)
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1. , 0.0439721],
[0.0439721, 1. ]], dtype=float32)>
array([[1. , 0.0439721],
[0.0439721, 1. ]], dtype=float32)>
Notes
-----
Expand Down
16 changes: 10 additions & 6 deletions pymc4/gp/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ class LatentGP(BaseGP):
and 5 new samples. Notice that unlike PyMC3, ``given`` in ``conditional`` method is
NOT optional.
>>> import numpy as np
>>> import pymc4 as pm
>>> X = np.random.randn(2, 10, 2, 2)
>>> Xnew = np.random.randn(2, 5, 2, 2)
>>> # Let's define out GP model and its parameters
... mean_fn = pm.gp.mean.Zero(feature_ndims=2)
>>> cov_fn = pm.gp.cov.ExpQuad(1., 1., feature_ndims=2)
>>> gp = pm.gp.LatentGP(mean_fn, cov_fn)
>>> @pm.model
>>> def gpmodel():
... def gpmodel():
... f = yield gp.prior('f', X)
... fcond = yield gp.conditional('fcond', Xnew, given={'X': X, 'f': f})
... return fcond
Expand Down Expand Up @@ -171,14 +173,15 @@ def prior(self, name: NameType, X: ArrayLike, **kwargs) -> ContinuousDistributio
--------
>>> import pymc4 as pm
>>> import numpy as np
>>> X = np.linspace(0, 1, 10)
>>> X = np.linspace(0, 1, 10)[..., np.newaxis]
>>> X = X.astype('float32')
>>> cov_fn = pm.gp.cov.ExpQuad(amplitude=1., length_scale=1.)
>>> gp = pm.gp.LatentGP(cov_fn=cov_fn)
>>> @pm.model
... def gp_model():
... f = yield gp.prior('f', X)
>>> model = gp_model()
>>> trace = pm.sample(model, num_samples=100)
>>> trace = pm.sample(model, num_samples=10, burn_in=10)
"""
mu, cov = self._build_prior(name, X, **kwargs)
if self._is_univariate(X):
Expand Down Expand Up @@ -234,16 +237,17 @@ def conditional(
--------
>>> import pymc4 as pm
>>> import numpy as np
>>> X = np.linspace(0, 1, 10)
>>> Xnew = np.linspace(0, 1, 50)
>>> X = np.linspace(0, 1, 10)[..., np.newaxis]
>>> Xnew = np.linspace(0, 1, 50)[..., np.newaxis]
>>> X, Xnew = X.astype('float32'), Xnew.astype('float32')
>>> cov_fn = pm.gp.cov.ExpQuad(amplitude=1., length_scale=1.)
>>> gp = pm.gp.LatentGP(cov_fn=cov_fn)
>>> @pm.model
... def gp_model():
... f = yield gp.prior('f', X)
... fcond = yield gp.conditional('fcond', Xnew, given={'f': f, 'X': X})
>>> model = gp_model()
>>> trace = pm.sample(model, num_samples=100)
>>> trace = pm.sample(model, num_samples=10, burn_in=10)
"""
givens = self._get_given_vals(given)
mu, cov = self._build_conditional(Xnew, *givens)
Expand Down

0 comments on commit c75f577

Please sign in to comment.