Skip to content

fix(inference): preserve non-finite uncertainty after Rust SE migration - #725

Merged
seonghobae merged 1 commit into
mainfrom
fix/inference-nonfinite-uncertainty-green
Aug 11, 2026
Merged

fix(inference): preserve non-finite uncertainty after Rust SE migration#725
seonghobae merged 1 commit into
mainfrom
fix/inference-nonfinite-uncertainty-green

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Why

Advances #722. After #647, standard_errors_from_vcov clamped every non-positive or non-finite diagonal to 0.0, reporting perfect certainty for undefined or unbounded variance. Non-finite Hessians could also produce uncontrolled covariance artifacts.

What

  • Preserve NaN and infinite diagonal uncertainty; clamp only finite non-positive diagonals to zero.
  • Reject non-finite Hessian entries with a stable finite-entry contract.
  • Python contracts + Rust unit coverage + APA doctoring.

Supersedes draft #722 once green.

Summary by CodeRabbit

  • Bug Fixes

    • Preserved NaN and infinite uncertainty values in standard-error results.
    • Rejected covariance calculations when Hessian inputs contain non-finite values.
    • Continued handling finite non-positive uncertainty values safely by clamping them to zero.
  • Documentation

    • Clarified uncertainty behavior and validation rules in the documentation and changelog.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 250ca495-dbfc-4ed7-bec8-b19d0f67a060

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The inference APIs now reject non-finite Hessian entries and preserve non-finite covariance diagonal values during standard-error conversion. Rust and Python tests and documentation define the behavior. Changelog entries record these and other release changes.

Changes

Inference uncertainty handling

Layer / File(s) Summary
Non-finite inference contract
crates/mlsirm-core/src/inference.rs, python/fast_mlsirm/inference.py, tests/test_inference_nonfinite_uncertainty.py, docs/changelog.d/722-inference-nonfinite-uncertainty.md, docs/doctoring/inference_nonfinite_uncertainty.md
vcov_from_hessian rejects NaN and infinite Hessian entries. Standard-error conversion preserves non-finite covariance diagonals and clamps finite non-positive values to zero. Tests and documentation cover the contract.

Release changelog updates

Layer / File(s) Summary
Unreleased changelog entries
CHANGELOG.md
The changelog records governed RAG scoring, Rust inference ownership, bounded Git metadata lookup, non-finite uncertainty handling, and bounded ranking materialization.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: preserving non-finite inference uncertainty after the Rust standard-error migration.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/inference-nonfinite-uncertainty-green

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/doctoring/inference_nonfinite_uncertainty.md (1)

13-18: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add source links and source-specific rationale.

This change defines an interpretation-facing uncertainty contract. The document cites two sources, but it does not provide stable links or explain how either source supports preserving non-finite covariance diagonals and clamping finite non-positive diagonals. Add those links and a short paper-basis summary before merging.

As per coding guidelines, substantive feature or process PRs must include relevant academic paper PDFs with full citations when redistribution is permissible; otherwise include a citation, link, and summary. Estimator and interpretation-facing output changes also require relevant literature research and a paper basis in the plan.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/doctoring/inference_nonfinite_uncertainty.md` around lines 13 - 18, Add
stable source links for both references in the References section and add a
concise source-specific rationale explaining how each supports preserving
non-finite covariance diagonals and clamping finite non-positive diagonals.
Include the required literature basis using full citations plus PDFs when
redistribution is permitted, or otherwise provide each citation, link, and
summary.

Source: Coding guidelines

🧹 Nitpick comments (1)
tests/test_inference_nonfinite_uncertainty.py (1)

12-20: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Cover negative infinity in the regression tests. The implementation and documentation preserve signed infinities, but the tests cover only NaN and +∞. Add negative-infinity cases to keep the Python and Rust contracts symmetric.

  • tests/test_inference_nonfinite_uncertainty.py#L12-L20: include -np.inf and assert np.isneginf(result[5]).
  • tests/test_inference_nonfinite_uncertainty.py#L23-L32: assert negative-infinity preservation for both the direct Rust and public results.
  • crates/mlsirm-core/src/inference.rs#L216-L231: add f64::NEG_INFINITY and assert is_infinite() && is_sign_negative().
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_inference_nonfinite_uncertainty.py` around lines 12 - 20, Extend
negative-infinity coverage for standard errors: in
tests/test_inference_nonfinite_uncertainty.py lines 12-20, add -np.inf to the
covariance input and assert result[5] is negative infinity; in lines 23-32,
assert negative-infinity preservation for both direct Rust and public results;
in crates/mlsirm-core/src/inference.rs lines 216-231, add f64::NEG_INFINITY and
verify it remains infinite with a negative sign.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docs/doctoring/inference_nonfinite_uncertainty.md`:
- Around line 13-18: Add stable source links for both references in the
References section and add a concise source-specific rationale explaining how
each supports preserving non-finite covariance diagonals and clamping finite
non-positive diagonals. Include the required literature basis using full
citations plus PDFs when redistribution is permitted, or otherwise provide each
citation, link, and summary.

---

Nitpick comments:
In `@tests/test_inference_nonfinite_uncertainty.py`:
- Around line 12-20: Extend negative-infinity coverage for standard errors: in
tests/test_inference_nonfinite_uncertainty.py lines 12-20, add -np.inf to the
covariance input and assert result[5] is negative infinity; in lines 23-32,
assert negative-infinity preservation for both direct Rust and public results;
in crates/mlsirm-core/src/inference.rs lines 216-231, add f64::NEG_INFINITY and
verify it remains infinite with a negative sign.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 887cac9d-0ebf-4045-970c-644d7b9eb31c

📥 Commits

Reviewing files that changed from the base of the PR and between 9b73354 and 305353f.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • crates/mlsirm-core/src/inference.rs
  • docs/changelog.d/722-inference-nonfinite-uncertainty.md
  • docs/doctoring/inference_nonfinite_uncertainty.md
  • python/fast_mlsirm/inference.py
  • tests/test_inference_nonfinite_uncertainty.py

Stop converting NaN/infinite covariance diagonals into false zero
uncertainty. Fail closed when observed information contains non-finite
entries so uncontrolled covariance artifacts cannot be published.
@seonghobae
seonghobae force-pushed the fix/inference-nonfinite-uncertainty-green branch from a0665a3 to aa931ad Compare August 11, 2026 10:32
@seonghobae
seonghobae merged commit 412c259 into main Aug 11, 2026
35 checks passed
@seonghobae
seonghobae deleted the fix/inference-nonfinite-uncertainty-green branch August 11, 2026 10:39
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.

1 participant