feat(Sobol): add non-finite (NaN/Inf) result filtering across nboot, … - #261
Open
bmchun722 wants to merge 4 commits into
Open
feat(Sobol): add non-finite (NaN/Inf) result filtering across nboot, …#261bmchun722 wants to merge 4 commits into
bmchun722 wants to merge 4 commits into
Conversation
…S2, batch, and multioutput
bmchun722
force-pushed
the
sciml-sobol-filter
branch
from
August 19, 2026 13:01
396970c to
dc855b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…S2, batch, and multioutput
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.
PR Description
Feature Summary
When conducting Global Sensitivity Analysis (GSA) on complex physical or ODE models, specific parameter combinations may lead to non-convergence, stiffness failures, or numerical overflow/underflow, resulting in non-finite outputs ($S_1, S_2, S_T$ , $V(Y)$ , and confidence intervals).
NaN/Inf). Without filtering, even a singleNaNsample propagates through Monte Carlo variance decompositions and pollutes the entire Sobol output (This PR introduces a robust, generalized sample filtering mechanism (
_compact_all_y_nonfinite!) toGlobalSensitivity.Sobol(src/sobol_sensitivity.jl). It automatically identifies and filters out non-finite sample points while maintaining design matrix alignment across:nboot ≥ 1)order = [0, 1, 2])batch = true/false)In addition,
SobolResultis updated to report:VY: total output variancen: count of valid, non-filtered design sample points ($nk = \text{count}(keep)$)Memory Layout & Masking Mechanism
1. Unified Linear Memory Layout
In
GlobalSensitivity.Sobol, model evaluationsall_yare flattened into a contiguous 1D vector (for scalar outputs) or a 2D matrix of shape(num_outputs, total_evaluations)(for multioutput models).Given:
second_order = false):second_order = true):The total number of evaluations across all bootstrap replicates and blocks is$N_{\text{total}} = nboot \times nblocks \times n$ .$k \in {1 \dots n}$ , bootstrap replicate $b$ , and block $bl$ , the linear column index in
For a specific sample point
all_yis:2. Unified Masking Logic with
keepTo ensure mathematical consistency across all design blocks, bootstrap replicates, and output components, the masking logic is unified across all dimensions:
keep = Base.fill(true, n)of sizekeep[k] = true) if and only if the evaluation at3. Block-wise Compact Copying
If$nk = \text{count}(keep) < n$ , a compact buffer $nboot \times nblocks \times nk$ (or $nk$ entries for each block and replicate are copied in-place while preserving the block sequence:
filteredof size(num_outputs, nboot * nblocks * nk)for 2D) is allocated. The validThe resulting$nk$ . The valid sample count $nk$ is returned as
filteredarray retains the exact layout expected bygsa_sobol_all_y_analysis, with each block now having lengthSobolResult.n.Verification & Testing
test/sobol_method.jl):ishi_nan,ishi_nan_batch,ishi_linear_nan) that explicitly returnNaNfor subset bounds to verify filtering under 1st order, 2nd order, bootstrap runs (nboot = 5), batch mode, and multioutput setups.Pkg.test()):Pkg.test(): All 12 GSA test suites passed 100% (Sobol 42/42, Morris 23/23, Shapley 13/13, etc.).Runic.main(["--check", "src/sobol_sensitivity.jl"]).This description and the code was generated with the assist of LLM