[mlpack-git] [mlpack] Mean shift clustering (#388)

Ryan Curtin notifications at github.com
Mon Jan 26 21:46:13 EST 2015


> +    
> +    size_t completedIterations = 0;
> +    
> +    //initial centroid is the point itself.
> +    allCentroids.col(i) = data.col(i);
> +    
> +    while (true) {
> +      
> +      // new centroid
> +      arma::Col<double> newCentroid = arma::zeros(data.n_rows, 1);
> +      
> +      double sumWeight = 0;
> +      for (size_t j = 0; j < data.n_cols; ++j) {
> +        
> +        // calc weight for each point
> +        double weight = kernel.Evaluate(allCentroids.col(i), data.col(j));

This is only correct for the Gaussian kernel, because d/dx(exp(-x/h)) = -1/h exp(-x/h).  For other kernels the expression g(x) might be substantially different (my notation comes from http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/TUZEL1/MeanShift.pdf ).  I would suggest writing a standalone function that calculates the weight for a point, and then using a template specialization for the `GaussianKernel` and other kernels where you can just use the kernel evaluation.  In cases where the kernel is not radially symmetric, the case may be even more different (I have not derived that case myself).  Otherwise, you will probably have to require that each kernel has a `Gradient()` function and then you can call that when one of the template specializations is not being used.

---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/388/files#r23583955
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20150126/19dc0541/attachment.html>


More information about the mlpack-git mailing list