Skip to content

Stabilize IMM transition-matrix normalization - #4297

Closed
FlorianPfaff wants to merge 17 commits into
mainfrom
fix/imm-transition-normalization-overflow
Closed

Stabilize IMM transition-matrix normalization#4297
FlorianPfaff wants to merge 17 commits into
mainfrom
fix/imm-transition-normalization-overflow

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

  • normalize nonnegative IMM transition rows after scaling by their largest entry
  • avoid overflow when individually finite row weights have a non-finite direct sum
  • add a focused regression using maximum finite floating-point weights

Bug

InteractingMultipleModelFilter._prepare_transition_matrix() normalized non-unit rows with a direct row sum:

transition_matrix / transition_matrix.sum(axis=1)[:, None]

A row can contain valid, finite, nonnegative weights whose sum overflows. For example, [finfo.max, finfo.max / 2] has the well-defined ratio 2:1, but its floating-point sum is inf. The old normalization therefore produced [0, 0], leaving a transition row with no probability mass.

Fix

Use each row's maximum entry as a scale before summing. The scaled entries lie in [0, 1], retain the original ratios, and can be normalized without overflowing. Already normalized rows remain unchanged and do not emit the existing renormalization warning.

Validation

  • isolated numerical reproduction: old result [0, 0]; fixed result [2/3, 1/3]
  • regression runs under np.errstate(over="raise", invalid="raise", divide="raise")
  • branch comparison against main: two commits ahead, zero behind; one source file and one focused test file changed

The full repository test matrix is delegated to GitHub Actions.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 23.94s
✅ JSON prettier 7 0 0 0 1.17s
✅ JSON v8r 7 0 0 3.51s
✅ MARKDOWN markdownlint 68 0 0 0 2.19s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.59s
✅ PYTHON black 1490 183 0 0 93.82s
✅ PYTHON isort 1490 328 0 0 2.62s
✅ REPOSITORY betterleaks yes no no 2.47s
✅ REPOSITORY checkov yes no no 54.09s
✅ REPOSITORY gitleaks yes no no 15.25s
✅ REPOSITORY git_diff yes no no 0.43s
✅ REPOSITORY secretlint yes no no 59.5s
✅ REPOSITORY syft yes no no 5.79s
✅ REPOSITORY trivy-sbom yes no no 7.09s
✅ REPOSITORY trufflehog yes no no 30.95s
✅ YAML prettier 11 0 0 0 0.75s
✅ YAML v8r 11 0 0 11.75s
✅ YAML yamllint 11 0 0 0.67s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@9.6.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@FlorianPfaff
FlorianPfaff force-pushed the fix/imm-transition-normalization-overflow branch from f69caee to f9cee17 Compare July 13, 2026 16:29
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