2

In rtree, how can I specify the threshold for float equality testing?

When checking nearest neighbours, rtree can return more than the specified number of results, as if two points are equidistant, it returns both them. To check this equidistance, it must have some threshold since the distances are floats. I want to be able to control this threshold.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194

1 Answers1

0

Actually it does not need to have a threshold to handle ties. They just happen.

Assuming you have the data points (1.,0.) and (0.,1.) and query point (0.,0.), any implementation I've seen of Euclidean distance will return the exact same distance for both, without any threshold.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
  • Wouldn't it be a good idea for them to include thresholds, and make the value changeable by API ? It would be easy on their part to do this, but would be very difficult for someone who's using them as an API, say from Python. – SherjilOzair Nov 23 '12 at 04:08
  • Why? What do you expect to *benefit* from that? Just use a larger query window or get a few more neighbors? Or use an incremental nearest neighbor API, then you can decide when to stop polling in your code. There clearly is no need to fuzz the results. – Has QUIT--Anony-Mousse Nov 23 '12 at 07:52
  • I'm pretty sure floats and doubles should always be tested for equality using a THRESHOLD. That's what they taught me in Scientific Computing 101. – SherjilOzair Feb 04 '13 at 11:44
  • You don't test for equality. You use `<=`. – Has QUIT--Anony-Mousse Feb 04 '13 at 12:21