Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heatmap plot in sobol analysis with groups #612

Open
nikithiel opened this issue Apr 18, 2024 · 7 comments
Open

Heatmap plot in sobol analysis with groups #612

nikithiel opened this issue Apr 18, 2024 · 7 comments

Comments

@nikithiel
Copy link

Hey there,

First of all, thanks for the great package! It integrates well into my coding project and helps me a lot.

R.n. I'm doing a Sobol analysis using grouping of my 24 input parameters. When I call problem.heatmap() after the analysis, I get the following heatmap, which I guess isn't exactly the right behavior:

image

The heatmap shows the results for groups 2, 1, 3 and 4, but the labels are incorrect. In heatmap.py, heatmap() uses the following as x-axis labels:

# Get unique groups (if defined) while maintaining order of group names
disp_names = sp["groups"]
if disp_names is None:
disp_names = sp["names"]
ax.xaxis.set_ticks(range(0, len(disp_names)))
ax.xaxis.set_ticklabels(disp_names, rotation=90)

I think the correct behavior would be something like this:

groups = _check_groups(problem)

if not groups:
    namesGSA = problem['names']
else:
    namesGSA, _ = extract_group_names(groups)

Let me know what you think about it. Maybe I got something wrong here.

@ConnectedSystems
Copy link
Member

Hi @nikithiel thanks for reporting this.

Is it possible to share a minimum working example? Or at least your problem specification? It would help confirm, or track down the cause.

Thank you!

@nikithiel
Copy link
Author

Hey @ConnectedSystems,

I'm using SALib v1.4.7. I created a small MWE that is based on the example in .../examples/sobol/sobol.py. I change it slightly to work with ProblemSpec() and groups:

from SALib.test_functions import Ishigami
from SALib import ProblemSpec
import matplotlib.pyplot as plt

# Example from '.../examples/sobol/sobol.py' using ProblemSpec() class
# Parameters from '../../src/SALib/test_functions/params/Ishigami_groups.txt'
paramsSobol = {
    'names': ['x1', 'x2', 'x3'],
    'bounds': [[-3.14159265359, 3.14159265359], [-3.14159265359, 3.14159265359], [-3.14159265359, 3.14159265359]],
    'num_vars': 3,
    'groups': ['Group_1', 'Group_2', 'Group_2'],
    'dists': None,
    'sample_scaled': True
}

problem = ProblemSpec(
    {
        'num_vars': paramsSobol['num_vars'],
        'names': paramsSobol['names'],
        'bounds': paramsSobol['bounds'],
        'groups': paramsSobol['groups']
    }
)

problem.sample_sobol(1024, calc_second_order=True, skip_values=2048)
Y = Ishigami.evaluate(problem.samples)

problem.set_results(Y)
problem.analyze_sobol(calc_second_order=True, conf_level=0.95, print_to_console=True)
problem.heatmap()
plt.show()

Let me know, what you think.

@ConnectedSystems
Copy link
Member

ConnectedSystems commented Apr 19, 2024

Hmmm, it works as expected for me on main (though there does seem to be an indexing issue with the plot).

from SALib.test_functions import Ishigami
from SALib import ProblemSpec
import matplotlib.pyplot as plt

# Example from '.../examples/sobol/sobol.py' using ProblemSpec() class
# Parameters from '../../src/SALib/test_functions/params/Ishigami_groups.txt'
problem = ProblemSpec(
    {
        'names': ['x1', 'x2', 'x3'],
        'bounds': [[-3.14159265359, 3.14159265359], [-3.14159265359, 3.14159265359], [-3.14159265359, 3.14159265359]],
        'num_vars': 3,
        'groups': ['Group_1', 'Group_2', 'Group_2'],
        'dists': None,
        'sample_scaled': True
    }
)

problem.sample_sobol(1024, calc_second_order=True, skip_values=2048)
problem.evaluate(Ishigami.evaluate)
problem.analyze_sobol(calc_second_order=True, conf_level=0.95, print_to_console=False)
problem.heatmap()
plt.show()

image

Could you try the most recent development version?

pip uninstall SALib
pip install git+https://github.com/SALib/SALib.git#egg=SALib

@ConnectedSystems
Copy link
Member

Added a minor tweak to address the issue above:

image

@nikithiel
Copy link
Author

Hey, thanks for checking the MWE. This indexing problem is exactly what I've meant. Results generally look the same for me.

@ConnectedSystems
Copy link
Member

ConnectedSystems commented Apr 19, 2024

Hey, thanks for checking the MWE. This indexing problem is exactly what I've meant. Results generally look the same for me.

Oh okay, I misunderstood. I interpreted the G1, G2, ..., as the equivalent to x1, x2 etc, and that you were seeing groups being ignored.

The fix will be merged in shortly if you would like to try the dev version. I will release a patched version over the weekend.

@nikithiel
Copy link
Author

Great. Thanks for the prompt fix!

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

No branches or pull requests

2 participants