pymc.gp.HSGPPeriodic#
- class pymc.gp.HSGPPeriodic(m, scale=1.0, *, mean_func=<pymc.gp.mean.Zero object>, cov_func)[source]#
Hilbert Space Gaussian process approximation for the Periodic covariance function.
Note, this is not actually a Hilbert space approximation, but it comes from the same paper (Riutort-Mayol et al., 2022. See Appendix B) and follows the same spirit: using a basis approximation to a Gaussian process. In this case, the approximation is based on a series of stochastic resonators.
For these reasons, we have followed the same API as gp.HSGP, and can be used as a drop-in replacement for gp.Latent. Like gp.Latent, it has prior and conditional methods.
Smaller lengthscales need larger m. A good minimum is
m = ceil(1.86 / ls) + 1, where ls is the smallest lengthscale of the Periodic kernel you expect. approx_hsgp_periodic_m computes this. See Riutort-Mayol et al., Appendix B. Note, this approximation is only implemented for the 1-D case.To work with the approximation in its “linearized” form, as a matrix of basis vectors and a vector of coefficients, see the method prior_linearized.
Changed in version 6.5.0: The approximation now matches the Periodic kernel. Earlier versions used the coefficient variances as standard deviations, and the lengthscale convention of Riutort-Mayol et al., which is half of the one Periodic uses. Priors and posteriors of existing models will differ, so check their lengthscale and scale priors.
- Parameters:
- m: int
The number of basis vectors to use. Must be a positive integer.
- scale: TensorLike
The standard deviation (square root of the variance) of the GP effect. Defaults to 1.0.
- cov_func: Must be an instance of instance of `Periodic` covariance
- mean_func: None, instance of Mean
The mean function. Defaults to zero.
References
Riutort-Mayol, G., and Anderson, M., and Solin, A., and Vehtari, A. (2022). Practical Hilbert Space Approximate Bayesian Gaussian Processes for Probabilistic Programming
Examples
# A three dimensional column vector of inputs. X = np.random.rand(100, 3) with pm.Model() as model: # Specify the covariance function, only for the 1-D case scale = pm.HalfNormal("scale", 10) cov_func = pm.gp.cov.Periodic(1, period=1, ls=0.1) # Specify the approximation with 25 basis vectors gp = pm.gp.HSGPPeriodic(m=25, scale=scale, cov_func=cov_func) # Place a GP prior over the function f. f = gp.prior("f", X=X) ... # After fitting or sampling, specify the distribution # at new points with .conditional Xnew = np.linspace(-1, 2, 50)[:, None] with model: fcond = gp.conditional("fcond", Xnew=Xnew)
Methods
HSGPPeriodic.__init__(m[, scale, mean_func])HSGPPeriodic.conditional(name, Xnew[, dims])Return the (approximate) conditional distribution evaluated over new input locations Xnew.
HSGPPeriodic.marginal_likelihood(name, X, ...)HSGPPeriodic.predict(Xnew[, point, given, ...])HSGPPeriodic.prior(name, X[, dims, ...])Return the (approximate) GP prior distribution evaluated over the input locations X.
Linearized version of the approximation.