[mlpack] KMeans and non-static metric

Ryan Curtin gth671b at mail.gatech.edu
Fri Oct 31 17:01:32 EDT 2014


On Thu, Oct 30, 2014 at 12:12:49PM +0100, Felix Widmaier wrote:
> Hi everybody,
> 
> First of all, in case that it is relevant: Since I am stuck with Ubuntu
> 12.04 which has only boost 1.48 in its repositories, I have to use
> mlpack version 1.0.8 instead of the current 1.0.10.
> 
> I am currently trying to implement my own metric class and use that with
> kmeans.
> It worked with a simple static metric class. However the metric I want
> to use is stateful so I made the Evaluate() method of the metric class
> non-static. Now I get compiler errors, as KMeans::Cluster() is const and
> usage of non-const, non-static Evaluate() within Cluster() discards
> qualifiers.
> 
> MahalanobisDistance is also not working for the same reason (at least
> the code snippet from
> http://www.mlpack.org/doxygen.php?doc=kmtutorial.html#kmeans_metric_kmtut does
> not work for me)
> 
> Do I miss something here or are stateful metrics for kmeans indeed not
> possible due to the const?

Hi Felix,

I'm sorry for the slow response; I've been traveling.

You are right that KMeans<>::Cluster() being marked const causes
problems.  This bug unfortunately persists in 1.0.10, but is not an
issue in trunk/ due to some significant refactoring (which also includes
the implementation of some faster k-means algorithms).  So it seems like
your possibilities are:

 * Modify 1.0.8 to remove the const qualifier from the Cluster()
   methods.

 * Move to trunk/ and disable the boost 1.49 functionality which is used
   in src/mlpack/core/tree/cosine_tree/ (so, you'd basically need to
   comment out the requirement for boost 1.49, then remove the
   cosine_tree/ directory from src/mlpack/core/tree/CMakeLists.txt and
   remove the quic_svd/ directory from
   src/mlpack/methods/CMakeLists.txt.  I think that's all that would be
   necessary to get trunk compiling with boost 1.48.  But this is
   somewhat hackish and not a good long term solution, so the third
   option...

 * Wait for the next release, although we don't yet have a planned date.

I've tested your code and modified it to use the Mahalanobis distance
against trunk/, and this compiles and appears to run successfully
(though the API for KMeans has changed a little bit; you will have to
remove the overclustering parameter from the constructor).

I hope this is helpful...

Thanks,

Ryan

-- 
Ryan Curtin    | "Do they hurt?"
ryan at ratml.org |   - Jessica 6


More information about the mlpack mailing list