scviva.tools.vision.apply_rbfpca#

scviva.tools.vision.apply_rbfpca(X, n_components=2, sigma=0.33)[source]#

RBF-kernel PCA 2D projection.

Mirrors R VISION’s applyRBFPCA. Builds a log-distance Gaussian kernel matrix K from pairwise Euclidean distances, row-normalises and z-scores each row, then returns the projection onto the top n_components eigenvectors of K @ K.T.

Parameters:
X ndarray

Input coordinates (latent space).

n_components int

Number of components to retain, by default 2.

sigma float

RBF bandwidth (applied to log-distances), by default 0.33 (matches R).

Return type:

ndarray

Returns:

ndarray of shape (n_cells, n_components)

Notes

The row z-scoring step is a deliberate deviation from what R VISION actually executes, not from what it appears to intend. R’s line reads kMat <- as.matrix(kMat, 1, function(x) (x - mean(x)) / sd(x)), which looks like an apply()-style per-row z-score – but kMat is already a matrix, so as.matrix.default() returns it unchanged and silently discards the extra arguments. R’s RBFPCA therefore never actually z-scores its kernel matrix. This implementation performs the z-score for real, matching the evident intent of that R line rather than R’s actual (apparently unintentional) runtime behavior; the two projections are not numerically equivalent as a result.