Skip to content

Fix Sobol analysis for partially constant multi-output columns - #678

Merged
ConnectedSystems merged 5 commits into
SALib:mainfrom
DresdenGman:fix/sobol-partial-constant-output
Jul 17, 2026
Merged

ConnectedSystems merged 5 commits into
SALib:mainfrom
DresdenGman:fix/sobol-partial-constant-output

Conversation

@DresdenGman

Copy link
Copy Markdown
Contributor

Fixes #619.

For multi-output analysis, the previous scalar np.ptp(y) check could miss constant output columns and produce invalid Sobol indices. This applies per-column zero-variance handling and adds regression coverage for mixed constant and varying outputs.

When y is 2D with some columns constant and others varying,
np.ptp(y) returns a scalar over the flattened array, missing
per-column zero-variance.  Use np.divide with per-column
where= clause to avoid producing NaN for constant columns.

Closes SALib#619
@ConnectedSystems

Copy link
Copy Markdown
Member

Thanks for the PR @DresdenGman

Could you follow the instructions here to resolve the linting issue https://github.com/SALib/SALib/actions/runs/28746038699/job/85308403437?pr=678#step:4:140

If you are seeing this message in CI, reproduce locally with: `pre-commit run --all-files`.
To run `pre-commit` as part of git workflow, use `pre-commit install`.
All changes made by hooks:
diff --git a/tests/test_sobol.py b/tests/test_sobol.py
index 5f7cef5..e051174 100644
--- a/tests/test_sobol.py
+++ b/tests/test_sobol.py

I haven't had a close look, but it seems like it's complaining that the warnings package is unused.

@DresdenGman

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer. I pushed a small lint-only fix in 534ed2e removing the unused warnings import from tests/test_sobol.py.

I also reran python -m pytest tests/test_sobol.py -q locally, and the Sobol tests still pass.

@ConnectedSystems

Copy link
Copy Markdown
Member

This looks acceptable to me, although there is an open question of how we'd handle this more formally across all methods in the longer term.

@tupui unless you have comments/concerns I'll merge this soon

@tupui tupui left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one comment on my end. Thanks for the ping 😃

Comment thread src/SALib/analyze/sobol.py Resolved
first_order and total_order guard against per-column zero variance,
but second_order's Vjk computation still divided by np.var(y, axis=0)
directly, producing NaN for constant columns when other columns vary.
@ConnectedSystems

Copy link
Copy Markdown
Member

Reviewed and this looks ready to merge, with one addition: second_order's Vjk computation still divided by np.var(y, axis=0)
so NaNs could still be produced.

Pushed d2b9787 to apply the same pattern as for first/total order and added a regression test.

I shall merge once CI passes.

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.

Divided by zero in the Sobol's confidence level calculation

3 participants