class*, mean_func=< object>, cov_funcs=< 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 prior and conditional methods, see their docstrings.

cov_funcs: list of Covariance objects

The covariance functions that compose the tensor (Kronecker) product. Defaults to [zero].

mean_func: None, instance of Mean

The mean function. Defaults to zero.


# 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 =, ls=0.1)  # Must accept X1 without error
    cov_func2 =, ls=0.3)  # Must accept X2 without error

    # Specify the GP.  The default mean function is `Zero`.
    gp =[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)


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)