[mlpack] Custom metric question

Ryan Curtin ryan at ratml.org
Tue Feb 9 10:32:24 EST 2016


On Mon, Feb 08, 2016 at 10:23:18PM +0100, Alasdair Newson wrote:
> Hello Ryan,
> 
> Thanks for your reply ! I tried to declare the following nearest neighbor
> search tree :
> 
> typedef NeighborSearch<
>     NearestNeighborSort,
>     customMetric,
>     BinarySpaceTree<BallBound<2>,
>                           QueryStat<NearestNeighborSort> >
> > customNeighborSearch;
> 
> Where custom metric is as follows :
> 
>     class customMetric
>     {
>         public:
>         /***
>         * Default constructor does nothing, but is required to satisfy the
> Metric
>         * policy.
>         */
>         customMetric(){}
>         template<typename VecTypeA, typename VecTypeB>
>          double Evaluate(const VecTypeA& a, const VecTypeB& b);
>     };
> 
> When I compile, I receive the following message :
> 
> error: type/value mismatch at argument 1 in template parameter list for
> ‘template<class VecType, class TMetricType> class mlpack::bound::BallBound’
>      BinarySpaceTree<BallBound<2>,
> 
> I am sure I am doing something silly, but I do not know exactly what. I
> tried to follow the example on the following web page :
> 
> http://www.mlpack.org/docs/mlpack-2.0.1/doxygen.php?doc=nstutorial.html#neighborsearch_nstut

Hi Alasdair,

You're not doing anything silly, what's silly is that the documentation
is wrong.  I'm sorry for that, and I've fixed it in commit 79fd639.  The
third template parameter for NeighborSearch is actually the matrix type,
and the fourth is the TreeType (which has changed a bit since the
documentation you read).  So you could try this:

typedef NeighborSearch<
    NearestNeighborSort,
    customMetric,
    arma::mat,
    tree::BallTree
> customNeighborSearch;

One of the nice things about the new API is that it uses template
template parameters, so you don't have to fully specify every bit of the
tree type.  Other choices you could use for the tree include
tree::StandardCoverTree.  I'd also suggest the R-tree and the R*-tree,
but those are limited to the Euclidean metric, so I don't think those
can be used in your case.

I've updated the documentation here:

http://mlpack.org/docs/mlpack-git/doxygen.php?doc=nstutorial.html#neighborsearch_nstut

If this doesn't fix your issue, let me know.  Thanks for bringing the
out-of-date documentation to light!

Ryan

-- 
Ryan Curtin    | "You got to stick with your principles."
ryan at ratml.org |   - Harry Waters



More information about the mlpack mailing list