Repository navigation
Fix uncertainty propagation for negative and zero values in uncertain_measurement - #479
Open
bhaskargurram-ai wants to merge 1 commit into
Open
bhaskargurram-ai wants to merge 1 commit into
bhaskargurram-ai wants to merge 1 commit into
Conversation
…_measurement Products, quotients, scaling and pow computed the new uncertainty as value * relative_uncertainty. A negative operand made the uncertainty negative, and a zero operand made it NaN (0 * inf). Compute the propagated uncertainty from absolute terms instead, so it is always non-negative and finite when the operands are.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #478
Products, quotients, scaling by a constant and
powonuncertain_measurementcomputed the new uncertainty asvalue * relative_uncertainty. A negative operand made the uncertainty negative, which also broke==against the exact value. A zero operand made it NaN (0 * inf).simple_productandsimple_dividealso got the wrong magnitude for operands of mixed sign.This change computes the propagated uncertainty from absolute terms:
operator*:sqrt((u1*v2)^2 + (u2*v1)^2), andsimple_product:|u1*v2| + |u2*v1|operator/:sqrt((u1/v2)^2 + (v1*u2/v2^2)^2), andsimple_divide: the sum of the absolute values of the same termsdouble, afloator ameasurement, andc / x: use|c|pow:|n * v^(n-1)| * uFor positive non-zero operands the results are the same as before. A small constexpr
detail::absolute_valuehelper was added next tosqr_powerso that the constexpr operators stay constexpr.Tests:
uncertainOps.negativeValuesanduncertainOps.zeroValueintest_uncertain_measurements.cppfail on main and pass with this change. The existing uncertain-measurement, measurement, unit_ops, math and string tests still pass, in both the compiled and the header-only builds.