Skip to content

Expanded support for group analysis - #707

Merged
ConnectedSystems merged 11 commits into
mainfrom
feature/group-analysis
Nov 15, 2026
Merged

ConnectedSystems merged 11 commits into
mainfrom
feature/group-analysis

Conversation

@ConnectedSystems

@ConnectedSystems ConnectedSystems commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Previously, group handling in SALib.analyze was inconsistent: only sobol,
morris, and delta-family methods had partial support, the older analyzers
(pawn, discrepancy, rsa) used a different mechanism with divergent
edge-case behavior, and radial_ee ignored groups entirely. This PR
standardizes group aggregation across all analysis methods, using one shared
convention, and documents the support matrix.

Changes

New shared utilities (SALib.util):

  • extract_group_names() — unique group names in order of first appearance
    (falls back to factor names when no groups are defined)
  • compute_groups_matrix() — factor-membership matrix (now returns names as a
    plain list, consistent with Si["names"] everywhere)
  • _group_metric() — masked-mean aggregation of per-factor metrics across
    group members

Analyzers gaining group support:

  • delta, dgsm, fast, rbd_fast — per-factor analysis, results averaged
    per group
  • radial_ee — group support mirroring the Morris conventions (sigma
    reported as NaN for multi-member groups)
  • pawn, discrepancy, rsa — converted from the legacy _check_groups
    mechanism to the shared convention

Behavior decisions:

  • A problem defining a single group (e.g. groups=["G1", "G1", "G1"]) now
    reports one aggregated row named G1, consistently across every analyzer.
    Previously pawn/discrepancy/rsa silently fell back to per-factor output
    while sobol/morris aggregated.
  • shapley (sampler and analyzer) now warns and ignores group definitions
    instead of raising, matching the ff/hdmr convention. Group aggregation is
    deliberately not performed: Shapley effects combine over a bundle by
    summation, not averaging, so mean-based aggregation would be mathematically
    incorrect. Results remain per-factor.

Documentation:

  • advanced.rst / README-advanced.md: group-sampling section rewritten —
    lists the samplers that take groups into account (sobol, saltelli via the
    same scheme, morris, latin) and the analyzer support matrix;
    warn-and-ignore methods (ff, hdmr, enhanced_hdmr, shapley) clearly
    marked.
  • Docstrings across analyzers now describe grouped output shape and the
    aggregation convention, including caveats: averaged signed metrics can
    exhibit cancellation, and confidence intervals are averaged across members
    (indicative only — they understate true group-level uncertainty).

Tests:

  • New tests/test_group_analysis.py (15 tests): per-analyzer aggregation
    correctness against manual means, single-group collapse, radial_ee sigma
    convention.
  • New group-warning tests for ff, hdmr, enhanced_hdmr; shapley
    raise-tests converted to warn-tests.

Notes

  • _check_groups() remains in use by the sobol/saltelli samplers with its
    existing semantics; this PR changes the analysis side only.
  • Grouped analyses at sampling time inherently do not resolve interactions
    between members of the same group; this is a property of grouped sampling,
    unchanged here.

Deferred for now

  • Shared aggregation entry point + ungrouped output: consolidate the
    per-analyzer extract_group_names / _group_metric call sites into a single
    helper and expose the pre-aggregation per-factor values (e.g.
    Si["ungrouped"]), so users can see which group member drives a group
    average. Needs deliberate design (special cases: Morris/radial sigma
    convention, Sobol S2 is group-resolved by construction) and is kept out of
    this PR to keep its scope reviewable.

  • Group-aware Shapley effects via summation over group members (bundle
    property), if a demand emerges.

  • Minor cleanups noticed along the way: NaN propagation behavior in grouped
    delta, shared grouped-sigma helper between morris and radial_ee.

    AI Disclosure

    This PR and message above was put together with the assistance of AI - Qwen3.8-Flash-Next

Port of PR #358 changes onto current main: per-variable indices are averaged per group via a shared util._group_metric helper, with results labeled by group names. FF and (legacy) HDMR warn when groups are provided. Morris now delegates its grouped-metric helper to the shared implementation. Supersedes PR #358.
When all factors share one group name, extract_group_names short-circuits and returns the original variable names while results were still aggregated per group, causing a length mismatch in to_df(). Derive names from the grouping only when _check_groups reports multiple groups, matching the convention used by the other analyzers.
discrepancy: results were aggregated per group but Si['names'] still
listed all variable names, so to_df() raised a length-mismatch error
whenever groups were defined. Names now reflect the unique groups.

rsa: the grouping mask was built from extract_group_names() output
(unique group names, length n_groups) instead of problem['groups']
(length num_vars), causing an IndexError for any grouped problem. The
mask now uses the per-variable group labels; ungrouped/single-group
cases keep the original variable names.
Single-group problems now report one aggregated row across all analyzers (pawn, discrepancy, rsa converted to the extract_group_names/_group_metric convention). Standardized aggregation notes in docstrings, added runtime warning and docstring note for enhanced_hdmr, documented CI averaging in _group_metric, updated user guide/README group-sampling sections, and added single-group tests.
Aligns the Shapley sampler and analyzer with the ff/hdmr convention: a groups entry triggers a warning, the definitions are dropped, and results are reported per individual factor. Docs updated accordingly.
Fix subject-verb agreement ('mean ... are' -> 'average ... is') and note that confidence intervals are averaged and may understate group-level uncertainty, matching the _group_metric Notes.
Also fix 'Interpretaion' typo in the delta method description.
Name lists now match extract_group_names and Si['names'] across analyzers; verified no consumer relies on the numpy array return.
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