Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Addressed review question about why np.linalg.inv(S) is considered numerically unstable in the Kalman gain computation.

Explanation provided

The current implementation on line 62 of kf_emulator.py:

K = Sigma_pred @ self.H.T @ np.linalg.inv(S)

Computing explicit matrix inverse amplifies numerical errors for ill-conditioned matrices. In Kalman filtering, the innovation covariance S can become ill-conditioned when observation noise is small or predicted covariance has disparate magnitudes across dimensions.

Using np.linalg.solve(S, rhs) instead:

  • Solves the linear system directly via LU decomposition without computing the inverse
  • Reduces floating-point operations by ~33%
  • Produces more accurate results when S is nearly singular

The mathematically equivalent but more stable form:

K = np.linalg.solve(S, (Sigma_pred @ self.H.T).T).T

No code changes made in this PR—purely explanatory response to review comment.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI mentioned this pull request Oct 30, 2025
Copilot AI changed the title [WIP] Address feedback on Kf experiments intercept explanation Explain numerical stability concerns with matrix inversion in Kalman filter Oct 30, 2025
Copilot AI requested a review from LevanBokeria October 30, 2025 10:55
Copilot finished work on behalf of LevanBokeria October 30, 2025 10:55
@LevanBokeria LevanBokeria marked this pull request as ready for review October 30, 2025 13:14
@LevanBokeria LevanBokeria merged commit c80e969 into kf-experiemnts-intercpt Oct 30, 2025
@LevanBokeria LevanBokeria deleted the copilot/sub-pr-68 branch October 30, 2025 13:15
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.

3 participants