Uncertainty Propagation

How Sounio propagates measurement uncertainty through calculations

Uncertainty Propagation

Sounio implements GUM-compliant uncertainty propagation, automatically tracking how measurement errors affect computed results.

The Problem

Consider calculating BMI from measured weight and height:

let mass = 75.3    // kg, but measured with ±0.5 kg accuracy
let height = 1.82  // m, but measured with ±0.01 m accuracy

let bmi = mass / (height * height)  // What's the uncertainty?

Without proper uncertainty tracking, you’d report 22.73 kg/m² with no indication of reliability.

Sounio’s Solution

let mass: Knowledge<kg> = measure(
    value: 75.3,
    uncertainty: 0.5,
    source: "scale"
)

let height: Knowledge<m> = measure(
    value: 1.82,
    uncertainty: 0.01,
    source: "stadiometer"
)

let bmi = mass / (height * height)
print(bmi.to_string())
// Output: 22.73 ± 0.31 kg/m²

GUM Rules

Sounio follows the Guide to the Expression of Uncertainty in Measurement (GUM):

Addition and Subtraction

For c = a ± b:

u(c) = √(u(a)² + u(b)²)
let a: Knowledge<f64> = measure(value: 10.0, uncertainty: 0.1, source: "A")
let b: Knowledge<f64> = measure(value: 5.0, uncertainty: 0.2, source: "B")

let sum = a + b
// sum.uncertainty = √(0.1² + 0.2²) = √0.05 ≈ 0.224

Multiplication and Division

For c = a × b or c = a / b, relative uncertainties combine:

u_rel(c) = √(u_rel(a)² + u_rel(b)²)

where u_rel(x) = u(x) / x

let area = length * width
// Relative uncertainties add in quadrature

Powers

For c = aⁿ:

u_rel(c) = |n| × u_rel(a)
let volume = side.pow(3)
// Relative uncertainty triples

General Functions

For y = f(x):

u(y) = |df/dx| × u(x)

Sounio computes derivatives automatically:

let angle: Knowledge<radians> = measure(value: 0.5, uncertainty: 0.01, source: "gyro")
let sine = sin(angle)
// u(sine) = |cos(0.5)| × 0.01 ≈ 0.00878

Correlated Inputs

When inputs share a common source, correlations affect propagation:

let temp = sensor.read()
let diff = temp - temp  // Should be exactly 0, not √2 × u(temp)

// Sounio tracks provenance and handles correlations
print(diff.uncertainty)  // 0.0, not √2 × temp.uncertainty

Monte Carlo Propagation

For complex functions, Sounio can use Monte Carlo simulation:

let result = monte_carlo(
    samples: 10000,
    || complex_calculation(a, b, c)
)
// result includes empirical uncertainty distribution

Confidence Levels

Uncertainty can be expressed at different confidence levels:

let temp = measure(value: 23.5, uncertainty: 0.2, source: "sensor")

// 1σ (68% confidence)
print(temp.uncertainty)  // 0.2

// 2σ (95% confidence)
print(temp.expanded_uncertainty(0.95))  // 0.4

// 3σ (99.7% confidence)
print(temp.expanded_uncertainty(0.997))  // 0.6

Coverage Intervals

let interval = measurement.coverage_interval(0.95)
// interval.lower = value - k × uncertainty
// interval.upper = value + k × uncertainty
// where k is the coverage factor for 95%

Best Practices

  1. Use appropriate uncertainty: Don’t underestimate measurement errors
  2. Check propagation: Verify uncertainty grows appropriately
  3. Consider correlations: Shared sources create dependencies
  4. Report expanded uncertainty: Use 95% confidence for final results

What’s Next?