Discussion:
[Numpy-discussion] [Feature Suggestion]More comparison functions for floating point numbers
cy18
2015-10-19 10:06:31 UTC
Permalink
I think these would be useful and easy to implement.

greater_close(a, b) = greater_equal(a, b) | isclose(a, b)
less_close(a, b) = less_equal(a, b) | isclose(a, b)
greater_no_close = greater(a, b) & ~isclose(a, b)
less_no_close = less(a, b) & ~isclose(a, b)

The results are element-wise, just like the original functions.

I'm not sure if it is useful enough to be a part of numpy. If so, I will
try to implement them and make a pull request.
Chris Barker
2015-10-19 19:46:27 UTC
Permalink
Post by cy18
I think these would be useful and easy to implement.
greater_close(a, b) = greater_equal(a, b) | isclose(a, b)
less_close(a, b) = less_equal(a, b) | isclose(a, b)
greater_no_close = greater(a, b) & ~isclose(a, b)
less_no_close = less(a, b) & ~isclose(a, b)
What's the use-case here? we need is_close because we want to test
equality, but precision errors are such that two floats may be as close to
equal as they can be given the computations done. And the assumption is
that you don't care about the precision to the point you specify.

But for a greater_than (or equiv) comparison, if you the precision is not
important beyond a certain level, then it's generally not important whether
you get greater than or less than when it's that close....

And this would great a wierd property that some values would be greater
than, less than, and equal to a target value -- pretty weird!

note that you can get the same effect by subtracting a bit from your
comparison value for a greater than check...

But maybe there is a common use-case that I'm not thinking of..

-CHB
--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

***@noaa.gov
cy18
2015-10-19 20:51:28 UTC
Permalink
It would be useful when we need to subtracting a bit before comparing by
greater or less. By subtracting a bit, we only have an absolute error
tolerance and with the new functions, we can have both absolute and
relative error tolerance. This is how isclose(a, b) better than
abs(a-b)<=atol.
Post by Chris Barker
Post by cy18
I think these would be useful and easy to implement.
greater_close(a, b) = greater_equal(a, b) | isclose(a, b)
less_close(a, b) = less_equal(a, b) | isclose(a, b)
greater_no_close = greater(a, b) & ~isclose(a, b)
less_no_close = less(a, b) & ~isclose(a, b)
What's the use-case here? we need is_close because we want to test
equality, but precision errors are such that two floats may be as close to
equal as they can be given the computations done. And the assumption is
that you don't care about the precision to the point you specify.
But for a greater_than (or equiv) comparison, if you the precision is not
important beyond a certain level, then it's generally not important whether
you get greater than or less than when it's that close....
And this would great a wierd property that some values would be greater
than, less than, and equal to a target value -- pretty weird!
note that you can get the same effect by subtracting a bit from your
comparison value for a greater than check...
But maybe there is a common use-case that I'm not thinking of..
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Robert Kern
2015-10-19 21:04:45 UTC
Permalink
Post by cy18
It would be useful when we need to subtracting a bit before comparing by
greater or less. By subtracting a bit, we only have an absolute error
tolerance and with the new functions, we can have both absolute and
relative error tolerance. This is how isclose(a, b) better than
abs(a-b)<=atol.

You just adjust the value by whichever tolerance is greatest in magnitude.

--
Robert Kern

Loading...