Skip to content

Conversation

QiJune
Copy link
Member

@QiJune QiJune commented Aug 4, 2017

numpy.isclose:

absolute(a - b) <= (atol + rtol * absolute(b))

numpy.testing.assert_almost_equal:

abs(desired-actual) < 1.5 * 10**(-decimal)

isclose is more appropriate for comparing two floats.

@QiJune QiJune requested review from gangliao and reyoung August 4, 2017 10:21
# has some diff, and could not pass unittest. So I set decimal 3 here.
# And I will check this in future.
numpy.testing.assert_almost_equal(actual, expect, decimal=3)
numpy.isclose(actual, expect)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that numpy.isclose compares the relative difference, and numpy.testing.assert_almost_equal compares the absolute difference. Why should we use relative other than absolute difference here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error of 0.00001 is appropriate for numbers around one, too big for numbers around 0.00001, and too small for numbers around 10,000. A more generic way of comparing two numbers – that works regardless of their range, is to check the relative error. Relative error is measured by comparing the error to the expected result.
Please refer to http://www.cygnus-software.com/papers/comparingfloats/Comparing%20floating%20point%20numbers.htm

@QiJune QiJune merged commit 10ee3dc into PaddlePaddle:develop Aug 5, 2017
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 this pull request may close these issues.

2 participants