Prediction

After running inference, use predict_GP to compute the posterior predictive distribution at new test inputs.

Predictive distribution

RxGP.predict_GPFunction
predict_GP(; m_in, q_v, q_θ, meta) → (means, covs)

Posterior predictive distribution at test inputs, per Eq. (30) of the dID-VSGP paper:

μ_{f̃*} = L̃m(x*) + K̃_xu(x*)(μ_v - K_uu⁻¹ mᵤ)
Σ_{f̃*} = K̃_xx(x*) + K̃_xu(x*)(Σ_v - K_uu⁻¹)K̃_xu(x*)ᵀ

The operator encoded in meta (:fn, :grad, :joint_fn_grad, or custom) determines the output dimension P at each test point:

  • :fn P=1 → means::Vector{Float64}, covs::Vector{Matrix{Float64}}
  • :grad P=D → same shapes, P-dim entries
  • :joint_fn_grad P=1+D → same shapes, P-dim entries

Arguments min: vector of D-dimensional inputs, e.g. [[1.0, 2.0], [3.0, 4.0], ...] qv::MultivariateNormalDistributionsFamily: variational posterior over inducing variables. qθ::Any: kernel hyperparameters (PointMass or plain vector). meta::UniSGPMeta: meta object built by getUniSGPMeta.

Returns (means, covs) means::Vector{<:AbstractVector}: P-dim predictive mean vector per test input. covs::Vector{<:AbstractMatrix}: P×P predictive covariance matrix per test input.

source

The posterior predictive at a test point $x_*$ is:

\[\mu_{f_*} = \tilde{L}\,m(x_*) + \tilde{K}_{x_*u}\bigl(\mu_v - K_{uu}^{-1}\mathbf{m}_u\bigr)\]

\[\Sigma_{f_*} = \tilde{K}_{x_*x_*} + \tilde{K}_{x_*u}\bigl(\Sigma_v - K_{uu}^{-1}\bigr)\tilde{K}_{x_*u}^\top\]

where:

  • $\tilde{L}$ is the linear operator encoded in the meta (identity, gradient, or joint)
  • $\mu_v, \Sigma_v$ are the posterior mean and covariance of the inducing variable $\mathbf{v}$
  • $\mathbf{m}_u$ collects the prior mean at the inducing locations

The output dimensionality $P$ at each test point depends on the operator:

Operator$P$means[i]covs[i]
:fn11-vector1×1 matrix
:grad$D$$D$-vector$D \times D$ matrix
:joint_fn_grad$1+D$$(1+D)$-vector$(1+D) \times (1+D)$ matrix

Example

x_test = [[xi] for xi in range(0, 10, length=100)]
q_v = result.posteriors[:v][end]

means, covs = predict_GP(
    m_in = x_test,
    q_v  = q_v,
    q_θ  = PointMass(θ_fixed),
    meta = meta,
)

# Plot mean ± 2σ
μ = [m[1] for m in means]
σ = [sqrt(C[1,1]) for C in covs]
plot(getindex.(x_test, 1), μ, ribbon=2σ, label="Predictive")