Mean-Shift Algorithm and Its Application

Issues for density estimation
  • how to represent density
  • how to extract the important information
    • local maxima, minima
    • gradient
    • mode

Multivariant kernel density estimation


Kernels

  • Gaussian

  • Epanechnikov


  • Uniform

Basic idea
  • based on kernel density estimation
  • finding local optimum (mode)
  • density gradient estimation
  • iterative hill climbing algorithm
Benefit over the direct computation
  • computational complexity
    • less density function evaluation
    • only local computation
Gradient computation
Always converges to the local maximum

Variable Bandwidth Mean-Shift
  • Abramson's rule

    • : fixed bandwidth for initial estimation
    • : geometric mean
Mean-shift vector

Mean Shift Mode Detection
  • what happens if we reach a saddle point?
  • perturb the mode position and check if we return back
Original mean shift
  • find mode of

  • using

Extended mean shift
  • find mode of

  • using

Mean Shift Properties
  • automatic convergence speed - the mean shift vecotr size depends on the gradient itself
  • near maxima, the steps are small and refined
  • convergence is guaranteed
  • for Uniform Kernel, convergence is achieved in a finite number of steps
  • Norm Kernel exhibits a smooth trajectory, but is slower than Uniform Kernel
Mean Shift strengths
  • application independent tool
  • suitable for real data analysis
  • does not assume any prior shape (e.g. elliptical) on data clusters
  • can handle arbitrary feature spaces
  • only ONE parameter to choose
  • h (window size) has a physical meaning, unlike k-means
Mean Shift weaknesses
  • the window size (bandwidth selection) is not trival
  • inappropriate window size can cause modes to be merged, or generate additional "shallow" modes, so it should use adaptive window size
Applications
  • pattern recognition
    • clustering
  • image processing
    • filtering
    • segmentation
      • run filtering (discontinuity preserving smoothing)
      • cluster the clusters which are closer than window size
    • discontinuity preserving smoothing

  • density estimation
    • particle filter
  • mid-level application
    • tracking
    • background subtraction
Application - tracking
  • target representation (start from the position of the model in the current frame)

  • candidate representation (search in the model's neighborhood in next frame)

  • bhattacharyya distance - it is the angle between the two vectors (find best candidate by maximizing a similarity function)



  • adaptive scale
    • solution: run localization 3 times with different h, chooseh that achieves maximum similarity
2D LOG filter with scale sigma



  • tracking through scale space - use interleaved spatial/scale mean-shift
Sure! Here's one possible implementation of the mean-shift algorithm: ```python def mean_shift(xs: np.ndarray, num_iter: int = 50, k_type: str = 'rbf', bandwidth: float = 0.1) -> np.ndarray: """ Implement the mean-shift algorithm :param xs: a set of samples with size (N, D), where N is the number of samples, D is the dimension of features :param num_iter: the number of iterations :param k_type: the type of kernels, including 'rbf', 'gate', 'triangle', 'linear' :param bandwidth: the hyperparameter controlling the width of rbf/gate/triangle kernels :return: the estimated means with size (N, D) """ N, D = xs.shape means = xs.copy() for i in range(num_iter): for j, x in enumerate(xs): # compute the kernel weights if k_type == 'rbf': w = np.exp(-0.5 * np.sum((x - means) ** 2, axis=1) / bandwidth ** 2) elif k_type == 'gate': w = np.exp(-np.sqrt(np.sum((x - means) ** 2, axis=1)) / bandwidth) elif k_type == 'triangle': w = np.maximum(0, 1 - np.sqrt(np.sum((x - means) ** 2, axis=1)) / bandwidth) elif k_type == 'linear': w = np.sum((x - means) * xs, axis=1) / (np.linalg.norm(x - means, axis=1) * np.linalg.norm(x)) else: raise ValueError("Unsupported kernel type: {}".format(k_type)) # update the mean by weighted average means[j] = np.sum(w[:, np.newaxis] * xs, axis=0) / np.sum(w) return means ``` In this implementation, we start with the initial means being the same as the input samples, and then iteratively update the means by computing the kernel weights between each sample and the current means, and then computing the weighted average of the samples using these weights. The kernel can be selected using the `k_type` parameter, and the kernel width can be controlled by the `bandwidth` parameter. The number of iterations can be controlled by the `num_iter` parameter. Finally, the estimated means are returned.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值