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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let a1, a2, a3 have quite big same magnitudes, then we see that Qcubed and R * R have same terms a1^6/729 and -(a1^4 a2)/81 (which will be reduced in d), but they level out the other terms (these terms have 6th and 5th degree and other terms - less or equal than 4th degree).
So, if these terms will participate in the calculation, this will lead to a huge round-off error.
But if we expand the expression, then round-off error should be less
d = Qcubed - R * R = 1/108 (a1^2 a2^2 - 4 a2^3 - 4 a1^3 a3 + 18 a1 a2 a3 - 27 a3^2)
@MaximSmolskiy, thank you for the patch! I think, generally this is the right direction to modify the function, and in this particular example it helps, but can it be improved even further in the same patch?
Generally, when you have (K*a*b - K*a*c)/(N*K), it makes sense to reduce it to (b-c)*a/N, because the largest source of rounding errors is when you add or subtract two big numbers or when you divide one big number by another big one, and so the methodology to reduce rounding errors is to reduce (to a reasonable level) magnitude of values that you add/subtract.
here you greatly reduce magnitude of the two subtracted items and thus probably achieve higher accuracy. Probably the first part of d formula can be simplified as well.
Numeric methods are always very tricky, and probably here we need to spend a little more time in order to improve accuracy in most cases, not only in some cases.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Readiness Checklist
Fix #27323
The problem that coefficients have quite big magnitudes and current calculations are subject to round-off error
Let
a1
,a2
,a3
have quite big same magnitudes, then we see thatQcubed
andR * R
have same termsa1^6/729
and-(a1^4 a2)/81
(which will be reduced ind
), but they level out the other terms (these terms have6
th and5
th degree and other terms - less or equal than4
th degree).So, if these terms will participate in the calculation, this will lead to a huge round-off error.
But if we expand the expression, then round-off error should be less
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.