Boost logo

Boost Users :

Subject: Re: [Boost-users] can not compile nearest neighbors in d dimensions
From: Mateusz Łoskot (mateusz_at_[hidden])
Date: 2014-04-16 09:27:01


On 16 April 2014 14:32, Georgios Samaras <georgesamarasdit_at_[hidden]> wrote:
> Thanks for the replies, now it is clearer. However, the minimum dimension I
> have in my datasets is 100 and I want to run NN with dimension 10000.
>
> So, how I am going to initialize a point?
>
> template <int CompileTimeDimension>
> void fill(point& tmp)
> {
> for(int j = CompileTimeDimension - 1 ; j >= 0 ; --j) {
> bg::set<CompileTimeDimension-->(tmp, 5);
> }
> }
>
> Even I can see that the above code won't even compile. Writting manually
> bg::set<0>(tmp, 5), ..., bg::set<10000>(tmp, 5) does not really sound a good
> idea. So what should I do?

Once again, dimension is a compile-time property.

#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/algorithms/assign.hpp>
namespace bg = boost::geometry;

template <std::size_t D, std::size_t N>
struct fill
{
    template <typename Point>
    static void apply(Point& p, typename
bg::coordinate_type<Point>::type const& v)
    {
        bg::set<D>(p, v);
        fill<D + 1, N>::apply(p, v);
    }
};
template <std::size_t N>
struct fill<N, N>
{
    template <typename Point>
    static void apply(Point&, typename
bg::coordinate_type<Point>::type const&) {}
};

int main()
{
   bg::model::point<double, 1000, bg::cs::cartesian> p1;
   fill<0, 1000>::apply(p1, 5);
   return 0;
}

But, you will likely hit compiler limits asking for 10K dimensions.

> Maybe boost nearest's neighbors are meant to be used in higher dimensions?

Your problem has *nothing* to do with the NN algorithm as it is
implemented in Boost.Geometry.

Best regards,

-- 
Mateusz  Łoskot, http://mateusz.loskot.net

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net