Can I use arbitrary metrics to search KD-Trees?

后端 未结 2 940
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 23:44

I just finished implementing a kd-tree for doing fast nearest neighbor searches. I\'m interested in playing around with different distance metrics other than the Euclidean d

相关标签:
2条回答
  • 2020-12-09 00:28

    I don't think you're tied to euclidean distance - as j_random_hacker says, you can probably use Manhattan distance - but I'm pretty sure you're tied to geometries that can be represented in cartesian coordinates. So you couldn't use a kd-tree to index a metric space, for example.

    0 讨论(0)
  • 2020-12-09 00:37

    The nearest-neighbour search procedure described on the Wikipedia page you linked to can certainly be generalised to other distance metrics, provided you replace "hypersphere" with the equivalent geometrical object for the given metric, and test each hyperplane for crossings with this object.

    Example: if you are using the Manhattan distance instead (i.e. the sum of the absolute values of all differences in vector components), your hypersphere would become a (multidimensional) diamond. (This is easiest to visualise in 2D -- if your current nearest neighbour is at distance x from the query point p, then any closer neighbour behind a different hyperplane must intersect a diamond shape that has width and height 2x and is centred on p). This might make the hyperplane-crossing test more difficult to code or slower to run, however the general principle still applies.

    0 讨论(0)
提交回复
热议问题