Skip to content

Is that a good practice to increase uncertainty when clamping occurs #80

@mgrouch

Description

@mgrouch

Whether increasing uncertainty when clamping occurs is a good practice depends on the specific context and system requirements. Here's a balanced analysis:

When It's Good Practice ✅

  1. Safety-Critical Systems

    • Clamping indicates the filter is operating at its limits
    • Increasing uncertainty properly reflects reduced confidence in the estimate
    • Prevents the filter from being overconfident in an artificial boundary
  2. Physical Systems with Known Limits

    • For wave height estimation, if you hit the ±10m clamp:
      if (x(1) == -MAX_HEAVE || x(1) == MAX_HEAVE) {
          P(1,1) = std::max(P(1,1), MAX_HEAVE); // Reflect heave uncertainty
      }
    • Mathematically represents: "We're at a physical limit, so our estimate is less certain"
  3. Fault Detection

    • A sudden covariance increase can trigger maintenance alerts
    • Useful for diagnostics (e.g., "System has been at max heave for 10 cycles")

When It's Problematic ❌

  1. Overly Conservative Systems

    • May cause unnecessary rejection of good measurements
    • Example issue:
      // Bad - blindly increasing covariance
      P *= 2.0;  // Overly aggressive
  2. Oscillation Risk

    • If the covariance grows too much → Kalman gain decreases → system stops correcting → remains clamped
  3. Masking Real Errors

    • Could hide sensor faults by always blaming "uncertainty"

Recommended Implementation

For your wave estimation filter, a balanced approach would be:

void enforceStateBounds() {
    constexpr float MAX_HEAVE = 10.0f;
    constexpr float COVARIANCE_PENALTY = 2.0f;  // 2x uncertainty
    
    if (x(1) != std::clamp(x(1), -MAX_HEAVE, MAX_HEAVE)) {
        // Only increase uncertainty if clamping was actually needed
        x(1) = std::clamp(x(1), -MAX_HEAVE, MAX_HEAVE);
        
        // Gradual covariance increase (avoids oscillations)
        P(1,1) = std::max(P(1,1), metrics.position_std_dev * COVARIANCE_PENALTY);
        
        // Optional: Log this event for diagnostics
        metrics.bounds_clamped = true;
    }
    // Repeat for other states...
}

Alternatives to Consider

  1. Soft Constraints (Better for many cases):

    // Add penalty term to measurement update when near bounds
    if (std::abs(x(1)) > 0.9 * MAX_HEAVE) {
        R(0,0) *= 1.5f;  // Decrease trust in position measurements
    }
  2. Projection-Based Methods:

    $$P_{clamped} = P - K(HPH^T)K^T$$

    Where ( K ) is a projection matrix that enforces constraints while preserving consistency.


Best Practice for Your Use Case

For wave estimation:
Do increase uncertainty when clamping (but moderately) because:

  • Waves have physical limits
  • Prevents filter overconfidence at boundaries
  • Matches real-world behavior (extreme waves are harder to model)

Don't use aggressive covariance inflation (e.g., 10x) as it could destabilize the bias estimation.

Would you like me to show how to implement the soft constraints approach as an alternative?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions