Skip to content

bug fix for stacked_bar plot #335

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

Merged
merged 2 commits into from
Mar 17, 2025
Merged

bug fix for stacked_bar plot #335

merged 2 commits into from
Mar 17, 2025

Conversation

Advueu963
Copy link
Collaborator

@Advueu963 Advueu963 commented Mar 16, 2025

TLDR: The fix comprises updating the get_n_order_values in Interactionvalues as it necessary for the stacked bar plot to work properly.

Currently the stacked_bar plot inflates the bars incorrectly and thus makes the interpretation difficult.
If given the following simple game setup

import matplotlib.pyplot as plt
import numpy as np

from shapiq import ExactComputer, powerset, Game
from shapiq.games.benchmark import SOUM

class SimpleGame(Game):
    def __init__(self) -> None:
        super().__init__(n_players=3, normalize=True, normalization_value=0)

    def value_function(self, coalitions: np.ndarray) -> np.ndarray:
        coalition_values = {
            (): 0,
            (0,): 0,
            (1,): 0,
            (2,): 0,
            (0, 1): 100,
            (0, 2): 100,
            (1, 2): 100,
            (0, 1, 2): 300,
        }

        values = np.array([coalition_values[tuple(np.where(x)[0])] for x in coalitions])

        return values

game = SimpleGame()


exact_computer = ExactComputer(n_players=game.n_players, game=game)

moebius = exact_computer("Moebius")
moebius.plot_stacked_bar(show=True)

For this game the interaction values of (0,1), (0,2) and (1,2) equal 100 and the rest is zero.
While this is correctly computed the problem lies in the visualisation:
image

With the fix it correctly becomes:
image

@Advueu963 Advueu963 requested a review from mmschlk March 16, 2025 12:13
@Advueu963 Advueu963 self-assigned this Mar 16, 2025
Copy link
Owner

@mmschlk mmschlk left a comment

Choose a reason for hiding this comment

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

Ah, I see. This makes sense!

@mmschlk mmschlk self-requested a review March 17, 2025 10:10
Copy link
Owner

@mmschlk mmschlk left a comment

Choose a reason for hiding this comment

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

Could you document this in the CHANGELOG.md as well?

Copy link
Owner

@mmschlk mmschlk left a comment

Choose a reason for hiding this comment

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

<3

@mmschlk mmschlk merged commit 6a5b1cf into main Mar 17, 2025
7 checks passed
@mmschlk mmschlk deleted the fix_stacked_bar_plot branch March 17, 2025 10:26
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.

2 participants