Uncertainty, structured prediction, and causal learning · Uncertainty, structured prediction, and causal learning · UNC007 · Model
Gaussian process latent variable model (GPLVM)
Explain a high-dimensional observation matrix through low-dimensional latent inputs to Gaussian-process mappings.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.
- GP latent variable map Experimental
Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.
- Availability
- Runs in CodeSplash (Experimental)
- Code example
- Complete calculation
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through discover.gplvm. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Explain a high-dimensional observation matrix through low-dimensional latent inputs to Gaussian-process mappings. Unlike kernel PCA, the model is generative from latent coordinates to observations and can quantify conditional predictive uncertainty. Bayesian/variational GPLVM inference is included here as a substantial inference option, not counted as an extra near-duplicate entry.
Question / hypotheses
Which low-dimensional latent configuration and nonlinear mappings account for the observed variables? The learned embedding is an explanatory representation, not a uniquely identified set of causal factors or a hypothesis test for the number of latent dimensions.
Architecture / computational structure
Each observed feature is a GP output indexed by a shared latent coordinate matrix Z. Integrate the mapping functions analytically under Gaussian noise and optimize Z in a point-estimate GPLVM. Bayesian variants place a prior on Z and use inducing-variable variational inference to integrate latent uncertainty approximately.
Assumptions
Gaussian observation noise and conditional independence of output features given the shared kernel are the basic convention here. Alternative likelihoods require different inference. Latent rotations, reflections and other transformations may be unidentifiable; missing observations need a correctly masked likelihood.
Formula / computational definition
For centered and latent , and . A Bayesian version maximizes an ELBO containing and GP/inducing-variable terms.
Parameters and notation
Learned: latent coordinates or their variational distribution, kernel parameters, observation noise, and optional inducing parameters. Hyperparameters: latent dimension q, kernel family, priors, inducing budget, initialization and optimization tolerance. ARD lengthscales can indicate weak dimensions under a specific prior/inference model; they do not certify an absolute true dimension.
Fitting, fine-tuning, and adaptation
Neural fine-tuning is not intrinsic. Warm-start latent and kernel parameters for refitting, or infer new-object latent posteriors while fixing global parameters. Joint refitting can move old coordinates, so align embeddings before comparing them. Bayesian updating must avoid counting old observations twice.
How to use and calibrate
Initialize from PCA and multiple alternative embeddings. Evaluate held-out observed-entry reconstruction likelihood, predictive uncertainty and sensitivity to q, scaling and restart. For a genuinely new object, infer its latent coordinates from available observed features using the fitted mapping; this is not generally a single fixed linear projection.
Example application
Embed multichannel sensor profiles on a smooth latent manifold and impute missing channels. Visualize posterior uncertainty and local reconstructions, not just an appealing scatterplot.
Interpretation / pitfalls
Watch out
High likelihood can reward distorted latent geometry. Plug-in latent coordinates understate their uncertainty; Bayesian variational inference adds approximation error rather than eliminating it. Exact dense inference scales cubically in n, so sparse methods change the computational and inferential approximation.
Python and R code examples
Scope: Complete Gaussian GPLVM marginal-likelihood evaluation for fixed latent coordinates. It evaluates the fitting objective but does not optimize coordinates or perform variational inference.
Dependencies / validation: use the shared NumPy/SciPy or base-R setup above. Python executed successfully with assertions; R reviewed but not executed.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Complete calculation — Complete Gaussian GPLVM marginal-likelihood evaluation for fixed latent coordinates. It evaluates the fitting objective but does not optimize coordinates or perform variational inference.
Shared setup for this chapter
import numpy as np
from scipy.special import logsumexp, gammaln
from scipy.linalg import expm
from itertools import product
def rbf(a, b, ell=1.0):
a, b = np.atleast_2d(a), np.atleast_2d(b)
return np.exp(-np.sum((a[:, None, :] - b[None, :, :])**2, axis=2)/(2*ell**2))
Z = np.linspace(-1,1,5)[:,None]
Y = np.column_stack([np.sin(2*Z[:,0]),Z[:,0]**2,Z[:,0]])
Y -= Y.mean(axis=0); n,D = Y.shape
C = rbf(Z,Z,.6)+.08*np.eye(n)
L = np.linalg.cholesky(C)
nll = D*np.log(np.diag(L)).sum()+.5*np.sum(Y*np.linalg.solve(C,Y))+n*D/2*np.log(2*np.pi)
assert np.isfinite(nll) and np.allclose(C,C.T)
print({'negative_log_marginal_likelihood':float(nll),'latent_dimension':Z.shape[1]})
Complete calculation — Complete Gaussian GPLVM marginal-likelihood evaluation for fixed latent coordinates. It evaluates the fitting objective but does not optimize coordinates or perform variational inference.
Shared setup for this chapter
lse <- function(z) { m <- max(z); m + log(sum(exp(z-m))) }
rbf <- function(a,b,ell=1) {
a <- as.matrix(a); b <- as.matrix(b)
D <- outer(rowSums(a*a),rowSums(b*b),"+")-2*a%*%t(b)
exp(-pmax(D,0)/(2*ell^2))
}
Z <- matrix(seq(-1,1,length.out=5),ncol=1)
Y <- cbind(sin(2*Z[,1]),Z[,1]^2,Z[,1]); Y <- scale(Y,center=TRUE,scale=FALSE)
n <- nrow(Y); D <- ncol(Y); C <- rbf(Z,Z,.6)+.08*diag(n)
U <- chol(C)
nll <- D*sum(log(diag(U)))+.5*sum(Y*solve(C,Y))+n*D/2*log(2*pi)
stopifnot(is.finite(nll),max(abs(C-t(C)))<1e-12)
print(c(negative_log_marginal_likelihood=nll,latent_dimension=ncol(Z)))
Sources
- Lawrence GPLVM paperjmlr.org
- Titsias–Lawrence Bayesian GPLVMproceedings.mlr.press
- Source 3docs.gpytorch.ai
From the CodeSplash reference, entry UNC007.