Skip to content

Fix pawn analysis for problems with groups#636

Merged
ConnectedSystems merged 2 commits into
SALib:mainfrom
Zapiano:bug_635
Sep 9, 2024
Merged

Fix pawn analysis for problems with groups#636
ConnectedSystems merged 2 commits into
SALib:mainfrom
Zapiano:bug_635

Conversation

@Zapiano
Copy link
Copy Markdown
Contributor

@Zapiano Zapiano commented Sep 9, 2024

At in title.

I wrote the bare minimum test file just to be sure this particular bug is fixed.

Close #635

@ConnectedSystems
Copy link
Copy Markdown
Member

Confirming the issue exists (with a separate example I had lying around to for sample/result setting) and that the proposed fix addresses the issue.

import numpy as np
from SALib import ProblemSpec


X =  np.random.rand(10, 3)
y =  np.random.rand(10)

sp = ProblemSpec({
    'names': ['x1', 'x2', 'x3'],
    'bounds': [
        (0.0, 1.0),
        (0.0, 1.0),
        (0.0, 1.0)
    ],
    'groups': ["g1", "g2", "g1"]
})

sp.set_samples(X)
sp.set_results(y)

sp.analyze_pawn()
sp.to_df()

# File C:\projects\SALib\src\SALib\analyze\pawn.py:153, in analyze(problem, X, Y, S, print_to_console, seed)
#     [151](file:///C:/projects/SALib/src/SALib/analyze/pawn.py:151) unique_grps = np.array(unique_grps)
#     [152](file:///C:/projects/SALib/src/SALib/analyze/pawn.py:152) for grp_id, grp in enumerate(unique_grps):
# --> [153](file:///C:/projects/SALib/src/SALib/analyze/pawn.py:153)     tmp[grp_id, :] = np.mean(results[unique_grps == grp, :], axis=0)
#     [155](file:///C:/projects/SALib/src/SALib/analyze/pawn.py:155) results = tmp
#     [156](file:///C:/projects/SALib/src/SALib/analyze/pawn.py:156) tmp = None

# IndexError: boolean index did not match indexed array along axis 0; size of axis is 3 but size of corresponding boolean axis is 2

@ConnectedSystems ConnectedSystems merged commit 1305f85 into SALib:main Sep 9, 2024
@ConnectedSystems
Copy link
Copy Markdown
Member

Thanks @Zapiano !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PAWN analysis not working when problem uses groups attribute

2 participants