Machine Learning

Mean Shift Mode Seeking

Follow Gaussian-weighted updates toward stationary points of a density estimate.

By Riano · Published · Updated · Report a correction

Mean Shift Mode Seeking

Mean shift is an iterative procedure for locating the maxima of a density function given discrete data sampled from that function. It operates by assigning a window around each data point and repeatedly moving the window to the mean of the data points within it, weighted by a kernel function (often a Gaussian). This effectively traces paths toward local regions of highest density (modes).

Worked Example

Consider fixed data points at [-2, -1, 1, 2]. We start searching from y = 2 with a Gaussian kernel of bandwidth h = 1.

  1. We evaluate the weight wi = exp(-(y - xi)2 / (2h2)) for each data point relative to y = 2.
  2. For x = -2, w = exp(-(16) / 2) = exp(-8) ≈ 0.000335
  3. For x = -1, w = exp(-(9) / 2) = exp(-4.5) ≈ 0.011109
  4. For x = 1, w = exp(-(1) / 2) = exp(-0.5) ≈ 0.606531
  5. For x = 2, w = exp(0) = 1.0
  6. The new position is a weighted average: ynew = ( -2 * 0.000335 + -1 * 0.011109 + 1 * 0.606531 + 2 * 1.0 ) / ( 0.000335 + 0.011109 + 0.606531 + 1.0 )
  7. This gives ynew ≈ 2.5947 / 1.61797 ≈ 1.603702

After one iteration, the displacement is 1.603702 - 2.0 = -0.396298.

Experiment

You can verify the calculations by using the interactive module:Mean Shift Mode Seeking

  1. Set Start to 2.
  2. Set Bandwidth to 1.
  3. Set Iterations to 1.
  4. Observe that the Current location updates to approximately 1.6037, with a Displacement of -0.3963.
  5. Increase the iterations to trace the full path toward the density peak near 1.5.

Limitations

The choice of bandwidth h heavily influences the result. A very large bandwidth over-smooths the density, potentially merging multiple distinct modes into one. Conversely, a very small bandwidth creates artificial local maxima at each individual data point. The symmetric starting position 0 remains stationary because the forces from points at [-2, -1] and [1, 2] perfectly balance, creating a critical point (a saddle or minimum) rather than a true density maximum for small h.

References

This fundamental paper formalizes mean shift for clustering, mode seeking, and image segmentation using a density gradient ascent interpretation with kernel methods.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Mean Shift Mode Seeking module.

Try Mean Shift Mode Seeking on Riano →

More in Machine Learning