<p>In <a href="https://github.com/mlpack/mlpack/pull/388#discussion_r23583955">src/mlpack/methods/mean_shift/mean_shift_impl.hpp</a>:</p>
<pre style='color:#555'>&gt; +    
&gt; +    size_t completedIterations = 0;
&gt; +    
&gt; +    //initial centroid is the point itself.
&gt; +    allCentroids.col(i) = data.col(i);
&gt; +    
&gt; +    while (true) {
&gt; +      
&gt; +      // new centroid
&gt; +      arma::Col&lt;double&gt; newCentroid = arma::zeros(data.n_rows, 1);
&gt; +      
&gt; +      double sumWeight = 0;
&gt; +      for (size_t j = 0; j &lt; data.n_cols; ++j) {
&gt; +        
&gt; +        // calc weight for each point
&gt; +        double weight = kernel.Evaluate(allCentroids.col(i), data.col(j));
</pre>
<p>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 <a href="http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/TUZEL1/MeanShift.pdf">http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/TUZEL1/MeanShift.pdf</a> ).  I would suggest writing a standalone function that calculates the weight for a point, and then using a template specialization for the <code>GaussianKernel</code> 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 <code>Gradient()</code> function and then you can call that when one of the template specializations is not being used.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/pull/388/files#r23583955">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFKO1apm0RBxdRlu0Ss_16ehrI8a5ks5nlvN1gaJpZM4DTzb1.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
  <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
    <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/388/files#r23583955"></link>
    <meta itemprop="name" content="View Pull Request"></meta>
  </div>
  <meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>