shift_particles#
- crispy.scms.shift_particles(G, X, D, h, d, c, n, H, Hinv)[source]#
Shift walkers toward density ridges using the Subspace Constrained Mean Shift (SCMS) algorithm.
This function updates the positions of walkers (G) based on local density estimates computed from data points (X) and projects their movement onto the subspace of interest, defined by eigenvectors of the Hessian matrix.
- Parameters:
G (ndarray) – Initial 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.
D (int) – Dimensionality of the data points.
h (float) – Smoothing bandwidth of 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).
n (int) – Number of data points (n = X.shape[0]).
H (ndarray) – Covariance matrix for the Gaussian kernel, shape (D, D).
Hinv (ndarray) – Inverse of the covariance matrix, shape (D, D).
- Returns:
G_updated (ndarray) – Updated coordinates of the walkers, 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 toward regions of high density by iteratively estimating gradients and projecting movements onto the ridge subspace.
The eigen decomposition of the Hessian matrix is used to constrain movement to the subspace defined by the largest eigenvalues.
The convergence error is computed as the displacement magnitude of each walker 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 >>> h = 1.0 >>> d = 1 >>> c = np.random.random((10, 100)) # Weighted Gaussian values >>> n = data.shape[0] >>> H = np.eye(3) * h**2 # Covariance matrix >>> Hinv = np.linalg.inv(H) # Inverse covariance matrix >>> G_updated, error = scms.shift_particles(walkers, data, D=3, h=h, d=d, c=c, n=n, H=H, Hinv=Hinv)