New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Match absolute tolerance of assert_allclose
with allclose
and `isclo...
#4880
Conversation
…close` Note that `rtol` wasn't altered to reduce backward incompatibility. Using an absolute tolerance of 0 prevents many common cases from passing. Also, matching the absolute tolerance of `allclose` and `isclose` makes debugging much easier.
LGTM, thanks Tony. |
Note that @josef-pkt has a non-trivial objection to this on the mailing list. I still think we ought to do it, but more discussion might be needed first. |
statsmodels has 399 We are almost only using now assert_allclose, since we have a minimum version of numpy that has it. When I'm changing old tests then I replace assert_almost_equal with assert_allclose because it's more precise. And if we have values close to zero, then often close to zero is much smaller, e.g.
changing the default dilutes the current test suite of packages that use assert_allclose, and we would start to convert and add atol=0 to all affected tests.
|
Maybe I'm missing something, but when I mentioned testing values close to zero, I didn't mean testing an array of all zeros. For example, if you have some values which should be 1 and some that should be 0, then round off error will cause the test to fail: eps = np.finfo(np.double).eps
assert_allclose([1, 0], [1, eps], rtol=5e-10, atol=1e-25) I think it's reasonable to set |
@tonysyu As I tried to show on some examples on the mailing list. But the general rule is that we are ok with rtol, but need atol>0 only in a minority of cases, and then atol=1e-8 would be much too large most of the time, forcing us to add atol=0 to the majority of cases instead of relying on the default. |
@josef-pkt: I understand your use-case, and I can see that this change would cause problems. I just think my use-case is very common, and should be the default, but you probably think your use-case is more common. I'm not really sure how to break the deadlock. |
Tony- would adding zerotol argument with non-zero default, and setting the atol + rtol * desired + (zerotol if desired == 0 else 0) handle your use case? On Sat, Jul 19, 2014 at 9:30 PM, Tony S Yu notifications@github.com wrote:
Nathaniel J. Smith |
just browing a few pages on github code search "numpy assert_allclose" almost 5000 results, very few define atol, and then some do in case of desired is zero, some don't even in that case.
|
I don't have any data, but I'd guess that I usually use the default tolerances, and I rarely specify atol except to compare vs. arrays with a desired 0. I've wasted time tracking down problems due to different default tolerances in allclose vs. assert_allclose. |
I think agriffing's comment would be a good argument to set the default atol=0 in np.allclose. It improves the unit tests for "default" users.
In any case it will affect a lot of code, github search for |
@josef-pkt: Does it help if I promise no one is going to go breaking all I don't see how agriffing's comment is an argument for atol=0 being more The defaults really need to work ok, somehow, for someone who doesn't
|
I like the @njsmith are you proposing to change |
Eh, if we're going to mess with this stuff we should probably do it right so we don't have to deal with it again later. Here's a concrete proposal to discuss:
(actual values to be determined!) The way we do this is to emit a |
I guess one downside to this proposal is that supporting 3 arguments indefinitely is kind of ugly, esp. when we'd be recommending that everyone use |
I don't really like The easiest change in my opinion for backward compat would be to just bump The Any change in any case will result to people having to revise hundreds of test cases using allclose or assert_allclose, and curse our name because we are changing stuff for aesthetic reasons. We need to be sure consistency is worth the hassle of changing anything at all, and I am undecided on this point. (Personally, I also think that the default tolerances should be more like |
@pv changing to Released versions of libraries libraries like |
@rgommers: indeed, so the warning message should then recommend setting explicitly The warning issue will probably turn up in any scheme that spews warnings. If it is done similarly as @njsmith suggests above (only on calls that produce different results), then it'll be slightly less bad. |
@pv I expect that the difference wil be huge. Maybe even no warnings at all for scipy, because all uses of There's no ideal solution here, but to me 100s of warnings is worse than just documenting the inconsistency. |
AFAIU, the issue is that there is lots of code that depends on Also, both of these kinds of code will continue to be written, and it is The idea of zerotol is that in fact this is what everyone really wants, and (Assuming for the moment that we don't formally deprecate atol= anytime On Sun, Jul 20, 2014 at 5:30 PM, Pauli Virtanen notifications@github.com
Nathaniel J. Smith |
I lean towards Ralf on this one, the number of fixes that would need to go in would be enormous. That said, it might be possible to make a script to do that job and submit PR's to the bigger users of assert_allclose, then make the change. |
I'm against changing assert_allclose to the large defaults of allclose now mainly for strategic reason. I think in the long term it's better if the scipy related testing culture keeps increasing and uses tools that have reasonably strict tests as default (instead of automatically defaulting to true for any small values). I also agree with Ralf that any change that would produce a huge number of warnings if someone updates numpy but doesn't have a statsmodels that handles it would be pretty bad. In terms of actual changes to the code, I think I would just add a wrapper function in a statsmodels.testing module and change the imports instead of trying to change most of the assert_equal. That's inconvenient since we are very used to I think Nathaniel's proposal is ok. That removing assert equal for exact zeros will not have much effect on statsmodels, for example. There might be just a few cases that would be affected. (I guess most intentional cases use assert_equal in that case.) |
Another possibility is to make the change(s), and if the test fails, then repeat with the old default and if it passes, raise a FutureWarning. That would probably get rid of most of the warnings. |
@charris that only works if you make the test requirement more strict, but not if you weaken them. |
Re: zerotol --- the Additionally (also in manually typed cases), you usually don't want different tolerances for zero and nonzero values if |
Pauli- yeah, the very nature of this problem means that all solutions have On Sun, Jul 20, 2014 at 7:20 PM, Pauli Virtanen notifications@github.com
Nathaniel J. Smith |
I think in cases where you know what to put into Re: (b) In any case, 3rd party projects will need to do some review on their tests. I'd guess that for the most part, tolerance changes have little effect, since often the point of allclose tests is to check that results are not ridiculously wrong. However, the intent of each test is not easy to guess, and at least for Scipy it varies, so someone needs to go through the grep outputs. Changes to |
Hmm, yeah, I can see an argument for making the end-goal default something What do you all think? Obviously the current (a) inconsistency, (b) lack of On Sun, Jul 20, 2014 at 9:16 PM, Pauli Virtanen notifications@github.com
Nathaniel J. Smith |
My summary:
My opinion: the current situation isn't that bad that it justifies the effort, especially if we can't end up with the optimal solution after all. +0.5 for just documenting current behavior better. |
I'm with @rgommers on this one, so closing. If anyone feels strongly that it still needs to be addressed, please reopen. |
Noting for the record that I actually think a nonzero zerotol is actually a On Mon, Aug 4, 2014 at 10:35 PM, Charles Harris notifications@github.com
Nathaniel J. Smith |
Note that
rtol
wasn't altered to reduce backward incompatibility. Using an absolute tolerance of 0 prevents many common cases from passing. Also, matching the absolute tolerance ofallclose
andisclose
makes debugging much easier.See discussion:
http://mail.scipy.org/pipermail/numpy-discussion/2014-July/070602.html