pymc.gp.MarginalKron#
- class pymc.gp.MarginalKron(*, mean_func=<pymc.gp.mean.Zero object>, cov_funcs=<pymc.gp.cov.Constant object>)[source]#
Marginal Gaussian process whose covariance is a tensor product kernel.
The gp.MarginalKron class is an implementation of the sum of a Kronecker GP prior and additive white noise. It has marginal_likelihood, conditional and predict methods. This GP implementation can be used to efficiently implement regression on data that are normally distributed with a tensor product kernel and are measured on a full grid of inputs: cartesian(*Xs). MarginalKron is based on the KroneckerNormal distribution, see its docstring for more information. For more information on the marginal_likelihood, conditional and predict methods, see their docstrings.
- Parameters:
- mean_func
Mean
, defaultZero
The mean function.
- cov_funcs
list
ofCovariance
, default [Constant
] The covariance functions that compose the tensor (Kronecker) product.
- mean_func
Examples
# One dimensional column vectors of inputs X1 = np.linspace(0, 1, 10)[:, None] X2 = np.linspace(0, 2, 5)[:, None] Xs = [X1, X2] y = np.random.randn(len(X1)*len(X2)) # toy data with pm.Model() as model: # Specify the covariance functions for each Xi cov_func1 = pm.gp.cov.ExpQuad(1, ls=0.1) # Must accept X1 without error cov_func2 = pm.gp.cov.ExpQuad(1, ls=0.3) # Must accept X2 without error # Specify the GP. The default mean function is `Zero`. gp = pm.gp.MarginalKron(cov_funcs=[cov_func1, cov_func2]) # Place a GP prior over the function f. sigma = pm.HalfCauchy("sigma", beta=3) y_ = gp.marginal_likelihood("y", Xs=Xs, y=y, sigma=sigma) # ... # After fitting or sampling, specify the distribution # at new points with .conditional # Xnew need not be on a full grid Xnew1 = np.linspace(-1, 2, 10)[:, None] Xnew2 = np.linspace(0, 3, 10)[:, None] Xnew = np.concatenate((Xnew1, Xnew2), axis=1) # Not full grid, works Xnew = pm.math.cartesian(Xnew1, Xnew2) # Full grid, also works with model: fcond = gp.conditional("fcond", Xnew=Xnew)
Methods
MarginalKron.__init__
(*[, mean_func, cov_funcs])MarginalKron.conditional
(name, Xnew[, ...])Returns the conditional distribution evaluated over new input locations Xnew, just as in Marginal.
MarginalKron.marginal_likelihood
(name, Xs, ...)Returns the marginal likelihood distribution, given the input locations cartesian(*Xs) and the data y.
MarginalKron.predict
(Xnew[, point, diag, ...])Return the mean vector and covariance matrix of the conditional distribution as numpy arrays, given a point, such as the MAP estimate or a sample from a trace.
MarginalKron.prior
(name, X, *args, **kwargs)Attributes
Xs
sigma
y