Hi All,
I have been going through the GPs examples in Heteroscedastic Gaussian Processess
I would like very much to get the Sparse GP working in PyMC5.
In the section “Sparse Heteroskedastic GP” a class SparseLatent
, using a method
def prior(self, name, X, Xu):
Kuu = self.cov(Xu)
self.L = pm.gp.util.cholesky(pm.gp.util.stabilize(Kuu))
Trying the code I get the error
Indeed, if I check the source code in gp.util source code there is no cholesky
method anymore.
Is there a Sparse GP implementation example elsewhere?
I could not find much other than this example, using PyMC3.
I made some PyMC5 related changes, but I get the error
AttributeError: 'TensorVariable' object has no attribute 'endswith'
The code I am using is, as close as possible to the original PyMC3 link
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
# set the seed
np.random.seed(1)
n = 2000 # The number of data points
X = 10 * np.sort(np.random.rand(n))[:, None]
# Define the true covariance function and its parameters
ℓ_true = 1.0
η_true = 3.0
cov_func = η_true**2 * pm.gp.cov.Matern52(1, ℓ_true)
# A mean function that is zero everywhere
mean_func = pm.gp.mean.Zero()
# The latent function values are one sample from a multivariate normal
# Note that we have to call `eval()` because PyMC3 built on top of Theano
f_true = np.random.multivariate_normal(
mean_func(X).eval(), cov_func(X).eval() + 1e-8 * np.eye(n), 1
).flatten()
# The observed data is the latent function plus a small amount of IID Gaussian noise
# The standard deviation of the noise is `sigma`
σ_true = 2.0
y = f_true + σ_true * np.random.randn(n)
with pm.Model() as model:
ℓ = pm.Gamma("ℓ", alpha=2, beta=1)
η = pm.HalfCauchy("η", beta=5)
cov = η**2 * pm.gp.cov.Matern52(1, ℓ)
gp = pm.gp.MarginalSparse(cov_func=cov, approx="FITC")
# initialize 20 inducing points with K-means
# gp.util
Xu = pm.gp.util.kmeans_inducing_points(20, X)
σ = pm.HalfCauchy("σ", beta=5)
y_ = gp.marginal_likelihood("y", X=X, Xu=Xu, y=y, noise=σ)
trace = pm.sample(1000, chains = 1)
X_new = np.linspace(-1, 11, 200)[:, None]
# add the GP conditional to the model, given the new X values
with model:
f_pred = gp.conditional("f_pred", X_new)
# To use the MAP values, you can just replace the trace with a length-1 list with `mp`
with model:
pred_samples = pm.sample_posterior_predictive(trace, var_names=[f_pred])
and the last line triggers the error
Thank you