Skip to content

Default atol value in assert_allclose_dense_sparse is too low #13977

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

Closed
oleksandr-pavlyk opened this issue May 29, 2019 · 4 comments · Fixed by #13978
Closed

Default atol value in assert_allclose_dense_sparse is too low #13977

oleksandr-pavlyk opened this issue May 29, 2019 · 4 comments · Fixed by #13978

Comments

@oleksandr-pavlyk
Copy link
Contributor

Description

daal4py's estimator RandomForestRegressor, powered by Intel(R) DAAL fails check_fit_idempotent, see uxlfoundation/scikit-learn-intelex#102

The failure is small:

AssertionError:
Not equal to tolerance rtol=1e-07, atol=1e-09

Mismatch: 25%
Max absolute difference: 1.1920929e-07
Max relative difference: 3.2737175e-06
 x: array([ 0.504864,  0.239177, -0.960478, -0.204671,  0.731089,  0.262303,
       -0.675667, -0.779623,  0.362969, -2.344096,  0.38684 ,  0.104189,
       -0.363802, -0.199642, -0.482426,  0.326316,  0.003698, -0.714691,
       -0.858935,  0.370866], dtype=float32)
 y: array([ 0.504864,  0.239177, -0.960478, -0.204671,  0.731089,  0.262303,
       -0.675667, -0.779623,  0.362969, -2.344096,  0.38684 ,  0.104189,
       -0.363802, -0.199642, -0.482426,  0.326316,  0.003698, -0.714691,
       -0.858935,  0.370866], dtype=float32)

This issue questions the choice of atol default parameter value of 1e-7 in assert_allclose_dense_sparse, see sklearn/utils/testing.py#L404.

The default value is smaller than epsilon of single precision floating number:

In [2]: np.finfo(np.float32).eps
Out[2]: 1.1920929e-07

Any threaded execution, can not guarantee bit-wise reproducibility due to possible changes in the order of associative operations, such as adddition or multiplication.

If there are no objections, I would open a PR to increase it to a small multiple of np.finfo(np.float32).eps.

@jeremiedbb
Copy link
Member

It seems more than reasonable. Actually I think it would make more sense to have 2 tolerances in general. One for float32 and one for float64 through the whole test suite (this is what I did for the _cython_blas tests).

oleksandr-pavlyk added a commit to oleksandr-pavlyk/scikit-learn that referenced this issue May 29, 2019
Check for closeness of new_result and the previously compute result
should depend on the dtype of the result, and can not be less than
that precision's epsilon.
@jnothman
Copy link
Member

jnothman commented May 30, 2019 via email

@jeremiedbb
Copy link
Member

Would you propose just checking the dtypes of the input and determining the tol from that, @jeremiedbb? Use the tol corresponding to the less precise dtype of input?

I would go with the first solution. A fixture should make it not too painful to implement I guess.

@rth
Copy link
Member

rth commented Jun 4, 2019

Also related to #10562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants