shift_walkers#
- crispy.scms.shift_walkers(G, X, h, d, c, mask)[source]#
Shift walkers towards density ridges using the Subspace Constrained Mean Shift (SCMS) algorithm.
This function updates the positions of walkers (G) based on local density estimates from data points (X) and a Gaussian kernel with bandwidth h. The shift is constrained to the subspace defined by the eigenvectors of the Hessian matrix with the largest eigenvalues.
- Parameters:
G (ndarray) – Coordinates of the walkers, shape (m, D, 1), where m is the number of walkers and D is the dimensionality.
X (ndarray) – Coordinates of the data points, shape (n, D, 1), where n is the number of points.
h (float) – Smoothing bandwidth for the Gaussian kernel.
d (int) – Target dimensionality of the ridge subspace.
c (ndarray) – Weighted Gaussian values computed for the data points and walkers, shape (m, n).
mask (ndarray of bool) – Boolean mask indicating valid (True) data points for each walker. Shape is (m, n).
- Returns:
G_updated (ndarray) – Updated coordinates of the walkers after the SCMS shift, shape (m, D, 1).
error (ndarray) – Convergence error for each walker, shape (m,). The error represents the displacement of each walker and is used to determine convergence.
Notes
The SCMS algorithm shifts walkers towards regions of high density and projects their movement onto the subspace spanned by the eigenvectors of the Hessian matrix with the largest eigenvalues.
The convergence error is calculated as the magnitude of the shift relative to the density gradient.
Examples
Perform a single SCMS shift for walkers:
>>> import numpy as np >>> from crispy import scms >>> data = np.random.random((100, 3, 1)) # 3D data points >>> walkers = np.random.random((10, 3, 1)) # Walker positions >>> c = np.random.random((10, 100)) # Weighted Gaussian values >>> mask = np.random.choice([True, False], size=(10, 100)) # Boolean mask >>> h = 1.0 >>> d = 1 >>> G_updated, error = scms.shift_walkers(walkers, data, h, d, c, mask)