You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Maybe tolerance error for test_zero_constrained, macOS #5158
=================================== FAILURES ===================================
______________ TestGenericNegativeBinomial.test_zero_constrained _______________
../venv/lib/python2.7/site-packages/statsmodels/base/tests/test_generic_methods.py:220: in test_zero_constrained
assert_allclose(res1.resid, res2.resid, rtol=1e-10)
E AssertionError:
E Not equal to tolerance rtol=1e-10, atol=0
E
E (mismatch 0.302129767211%)
E x: array([-3.174188, -1.174188, -3.174188, ..., 5.713472, 5.686109,
E 3.730759])
E y: array([-3.174188, -1.174188, -3.174188, ..., 5.713472, 5.686109,
E 3.730759])
Is there a common feature in the environment for the 4 failing python environments?
rtol is strict and imposes convergence to very similar parameters in 2 equivalent, numerically almost identical models.
The failing assert is followed by two more asserts in the test method. It is likely that some of the other ones will also fail if we increase to eg. rtol=1e-9
I'm looking at the example on my computer with --pdb, In my case the results are identical, i.e. rtol=0 still passes. Aside: optimizer in this Negbin case is bfgs.
The resid closest to zero:
(Pdb) np.min(np.abs(res2.resid))
0.00038779800106381046
so we could try to add atol=1e-12 and try to keep rtol=1e-10
One OSX for PRs would be very useful.
Trying to fix precision problems that might need several iterations by going through master is not very efficient (and makes for a messy git/github history)
I merged #5164 hoping the atol works
I'm not sure if the tolerance change helped, Python 2.7 and 3.7 don't have this failure on this run, but before the fix, Python 3.6 didn't have the failure, so it seems to have some random component.
not good, both cases have the same result in the convergence print, also it passes the comparison for params at rtol=1e-10 earlier in the unit test.
I have no guess which operation might have sufficient random noise to cause this.
To hopefully get rid of this we can increase rtol to rtol=1e-8 which is still a tight result in terms of the statistics, but it lowers the bar that two essentially identical ways to compute agree at high precision.
Given that I'm not a OSX user, I have no clue what might be the problem. prediction and resid should be essentially exp and dot.
prediction and resid should be essentially exp and dot.
Do we know more generally which operations are subject to this particular kind of noise? e.g. if there were some narrow subset of scipy functions that were vulnerable, we could track them down and look for workarounds.
To hopefully get rid of this we can increase rtol to rtol=1e-8
Ideally (well, 2nd-best or 3rd-best really) we'd use the tightest valid tolerance on each platform/config. Might be a use case for the e.g. DECIMAL_8 = 8 pattern in many test modules.
DECIMAL_x is outdated, it was before assert_allclose now it's rtol and atol (but we don't have that platform dependent)
Testing replicability is not really the point of the test, convergence tolerance would be only between 1e-5 and 1e-8. The rest is "bonus", i.e. irrelevant for checking that I/we don't have a bug. (Although it's nice to see that I do get identical results on Windows with MKL.)
I leave it to OSX users to figure out where their random noise comes from. Numerical noise is a moving target that might change with changes in implementation details, and possible bugs and bug fixes in underlying libraries,
The problem is that for example some extra tiny numerical noise could put bfgs on a slightly different convergence path so at the end the accumulated error is 1e-11 for params which could imply 1e-8 or 1e-9 for prediction. It's still a correct answer because it is still easily within the required convergence tolerance of bfgs.
So neither we nor the underlying libraries might have a bug, but we don't get the "bonus" numerical replicability.
(aside: the failure is not important enough that I go through all my zero_constrained code again to check where some extra numerical noise might enter.)
Now that I've looked back through my notes, I'm inclined to think there may be other issues in the pertinent code that should be addressed before looking at tolerances: #4414 (comment)
4414 is for the mixedlm test failure on OSX, not for zero_constrained.
(numerical derivative hessian are often sensitive to step length choice. The only more reliable way in general would be to use an adaptive method as in numdifftools, but that is much slower)
@bashtage - from the above, my prediction would be that you will see the failure about half the time. I guess it's conceivable that it's specific to (all) Python.org Pythons, but that does seem unlikely.
I think it's mostly propagation of floating point noise. There is no guarantee that floating point noise is deterministic, i.e. the same in repeated calls or across machines.
I will change the unit test to an assert for linear prediction which removes the exp transformation and might be numerically more stable.
Another check to see whether the param estimate itself is off, is to tighten the tolerance there. (but again, bfgs is not required to provide that precision for params)
The param estimates are almost always different on OSX by about 1e-13. On Windows they are always exactly the same. I saw one run where the parameters have 0 difference on OSX.
edit IGNORE, the following is for test_zero_collinear and not for test_zero_constrained which is similar but not the reported failing test
I'm running into this now in #5255 but where convergence tolerance limits the precision which is much lower than here. (resid wasn't tested for GLM and discrete because it is currently not available.)
The most likely source for the difference in converged params is that GLM unit test doesn't use the same start_params in the two models. In that case we get only rtol=5e-5 or atol=1e-5 for resid, and a bit better for fittedvalues.
The unit test for GLM don't get the information about start_params which is missing in the results instance.
RLM and QuantileRegression do not allow start_params as fit arguments yet.
So, I will weaken the tolerance requirement in the unit test all the way to the one limited by convergence tolerance criteria.
update
All tests pass at current precision after changing GLM unit test to use the same start_params. GEE test pass at current precision, AFAICS, because both models use default start_params, zeros, GEE is skipped in the
RLM is included and uses default start_params in both models
Activity
josef-pkt commentedon Sep 9, 2018
Is there a common feature in the environment for the 4 failing python environments?
rtol is strict and imposes convergence to very similar parameters in 2 equivalent, numerically almost identical models.
The failing assert is followed by two more asserts in the test method. It is likely that some of the other ones will also fail if we increase to eg. rtol=1e-9
I'm looking at the example on my computer with --pdb, In my case the results are identical, i.e. rtol=0 still passes. Aside: optimizer in this Negbin case is bfgs.
The resid closest to zero:
(Pdb) np.min(np.abs(res2.resid))
0.00038779800106381046
so we could try to add
atol=1e-12and try to keep rtol=1e-10matthew-brett commentedon Sep 9, 2018
These are all on macOS instead of Linux (or Windows). So, maybe different libm, or different OpenBLAS routines?
jbrockmendel commentedon Sep 9, 2018
xref #2069
BF: drop tolerance of a zero_constrained test
matthew-brett commentedon Sep 10, 2018
I did a PR with you suggested tolerance change. It's not super-easy to test whether this helps until it's merged, making #2069 even more pertinent.
bashtage commentedon Sep 10, 2018
Maybe there should be a single OSX build on Travis. Latest packages? IME OSX builds aren't so slow anymore.
josef-pkt commentedon Sep 10, 2018
One OSX for PRs would be very useful.
Trying to fix precision problems that might need several iterations by going through master is not very efficient (and makes for a messy git/github history)
I merged #5164 hoping the atol works
this issue can be closed when it works.
matthew-brett commentedon Sep 10, 2018
Sadly not fixed - see:
I'm not sure if the tolerance change helped, Python 2.7 and 3.7 don't have this failure on this run, but before the fix, Python 3.6 didn't have the failure, so it seems to have some random component.
josef-pkt commentedon Sep 10, 2018
not good, both cases have the same result in the convergence print, also it passes the comparison for params at rtol=1e-10 earlier in the unit test.
I have no guess which operation might have sufficient random noise to cause this.
To hopefully get rid of this we can increase rtol to
rtol=1e-8which is still a tight result in terms of the statistics, but it lowers the bar that two essentially identical ways to compute agree at high precision.Given that I'm not a OSX user, I have no clue what might be the problem. prediction and resid should be essentially
expanddot.jbrockmendel commentedon Sep 10, 2018
Do we know more generally which operations are subject to this particular kind of noise? e.g. if there were some narrow subset of
scipyfunctions that were vulnerable, we could track them down and look for workarounds.Ideally (well, 2nd-best or 3rd-best really) we'd use the tightest valid tolerance on each platform/config. Might be a use case for the e.g.
DECIMAL_8 = 8pattern in many test modules.josef-pkt commentedon Sep 11, 2018
DECIMAL_x is outdated, it was before
assert_allclosenow it's rtol and atol (but we don't have that platform dependent)Testing replicability is not really the point of the test, convergence tolerance would be only between 1e-5 and 1e-8. The rest is "bonus", i.e. irrelevant for checking that I/we don't have a bug. (Although it's nice to see that I do get identical results on Windows with MKL.)
I leave it to OSX users to figure out where their random noise comes from. Numerical noise is a moving target that might change with changes in implementation details, and possible bugs and bug fixes in underlying libraries,
The problem is that for example some extra tiny numerical noise could put bfgs on a slightly different convergence path so at the end the accumulated error is 1e-11 for params which could imply 1e-8 or 1e-9 for prediction. It's still a correct answer because it is still easily within the required convergence tolerance of bfgs.
So neither we nor the underlying libraries might have a bug, but we don't get the "bonus" numerical replicability.
(aside: the failure is not important enough that I go through all my zero_constrained code again to check where some extra numerical noise might enter.)
jbrockmendel commentedon Sep 11, 2018
Now that I've looked back through my notes, I'm inclined to think there may be other issues in the pertinent code that should be addressed before looking at tolerances: #4414 (comment)
josef-pkt commentedon Sep 11, 2018
4414 is for the mixedlm test failure on OSX, not for zero_constrained.
(numerical derivative hessian are often sensitive to step length choice. The only more reliable way in general would be to use an adaptive method as in numdifftools, but that is much slower)
bashtage commentedon Sep 11, 2018
Not reproducible locally on OSX using pip installed numpy, scipy, pandas.
matthew-brett commentedon Sep 11, 2018
@bashtage - from the above, my prediction would be that you will see the failure about half the time. I guess it's conceivable that it's specific to (all) Python.org Pythons, but that does seem unlikely.
bashtage commentedon Sep 11, 2018
Can't reproduce after multiple runs on Homebrew 3.7 + pip everything else. Might be CPU-specific.
matthew-brett commentedon Sep 11, 2018
Might be - OpenBLAS can select different kernels at run-time. What do you get for:
?
bashtage commentedon Sep 11, 2018
Core: Sandybridge
bashtage commentedon Sep 11, 2018
The errors are seemingly random across the python versions.
max(abs(resid1-resid2))produced:Blas problem?
bashtage commentedon Sep 11, 2018
Quite a few test runs indicate that atol=1e-10 is safe to use.
josef-pkt commentedon Sep 11, 2018
I think it's mostly propagation of floating point noise. There is no guarantee that floating point noise is deterministic, i.e. the same in repeated calls or across machines.
I will change the unit test to an assert for linear prediction which removes the exp transformation and might be numerically more stable.
Another check to see whether the param estimate itself is off, is to tighten the tolerance there. (but again, bfgs is not required to provide that precision for params)
josef-pkt commentedon Sep 11, 2018
("You can't comment at this time." github is still not back to normal)
bashtage commentedon Sep 11, 2018
The param estimates are almost always different on OSX by about 1e-13. On Windows they are always exactly the same. I saw one run where the parameters have 0 difference on OSX.
josef-pkt commentedon Sep 11, 2018
Thanks, that's most likely enough to explain the difference in resid.
I will open a PR tonight base on this.
bashtage commentedon Sep 11, 2018
I ran with atol=1e-10 and all passed.
josef-pkt commentedon Sep 25, 2018
edit IGNORE, the following is for
test_zero_collinearand not fortest_zero_constrainedwhich is similar but not the reported failing testI'm running into this now in #5255 but where convergence tolerance limits the precision which is much lower than here. (resid wasn't tested for GLM and discrete because it is currently not available.)
The most likely source for the difference in converged params is that GLM unit test doesn't use the same start_params in the two models. In that case we get only rtol=5e-5 or atol=1e-5 for resid, and a bit better for fittedvalues.
The unit test for GLM don't get the information about start_params which is missing in the results instance.
RLM and QuantileRegression do not allow start_params as fit arguments yet.
So, I will weaken the tolerance requirement in the unit test all the way to the one limited by convergence tolerance criteria.
update
All tests pass at current precision after changing GLM unit test to use the same start_params.
GEE test pass at current precision, AFAICS, because both models use default start_params, zeros,GEE is skipped in theRLM is included and uses default start_params in both models