Skip to content

Fix uncertainty propagation for negative and zero values in uncertain_measurement - #479

Open
bhaskargurram-ai wants to merge 1 commit into
llnl:mainfrom
bhaskargurram-ai:fix/uncertain-propagation-sign
Open

bhaskargurram-ai wants to merge 1 commit into
llnl:mainfrom
bhaskargurram-ai:fix/uncertain-propagation-sign

Conversation

@bhaskargurram-ai

Copy link
Copy Markdown

Fixes #478

Products, quotients, scaling by a constant and pow on uncertain_measurement computed the new uncertainty as value * 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_product and simple_divide also 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), and simple_product: |u1*v2| + |u2*v1|
  • operator/: sqrt((u1/v2)^2 + (v1*u2/v2^2)^2), and simple_divide: the sum of the absolute values of the same terms
  • scaling by a double, a float or a measurement, and c / x: use |c|
  • pow: |n * v^(n-1)| * u

For positive non-zero operands the results are the same as before. A small constexpr detail::absolute_value helper was added next to sqr_power so that the constexpr operators stay constexpr.

Tests: uncertainOps.negativeValues and uncertainOps.zeroValue in test_uncertain_measurements.cpp fail 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.

…_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

No deployments
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.

uncertain_measurement gives negative or NaN uncertainty for negative or zero values

1 participant