Skip to content

Add Game.compute function and related test to the Game class #397

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 7 commits into from
Jun 12, 2025

Conversation

IsaH57
Copy link
Collaborator

@IsaH57 IsaH57 commented Jun 4, 2025

This pull request adds a Game.compute() function to the shapiq.Game class. After computing the game values, it returns the normalized game values, the coalition_lookup, and the normalization_value. Notably, using the compute function does not alter the state of the Game object. This PR also adds an utility function generate_interaction_lookup_from_coalitions for creating an interaction lookup dict from an arbitrary coalition array.

@IsaH57 IsaH57 linked an issue Jun 4, 2025 that may be closed by this pull request
@mmschlk
Copy link
Owner

mmschlk commented Jun 4, 2025

This PR closes #345

@@ -419,6 +419,30 @@ def precompute(self, coalitions: np.ndarray | None = None) -> None:
self.coalition_lookup = coalitions_dict
self.precompute_flag = True

def compute(
self, coalitions: np.ndarray | None = None, *, return_normalization: bool = False
Copy link
Owner

Choose a reason for hiding this comment

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

could you actually always return the normalization_value as the third thing and not normalize the values in line 440. Then this function would be more usable because it's the "raw" computation.

coalitions: The coalitions to evaluate.

Returns:
A tuple containing:
Copy link
Owner

Choose a reason for hiding this comment

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

I deleted the return types because sphinx will display automatically and then we do not have to maintain two parts of the code. :)

@mmschlk mmschlk changed the title Add compute() function and related test to the Game class Add Game.compute function and related test to the Game class Jun 12, 2025
@mmschlk mmschlk changed the title Add Game.compute function and related test to the Game class Add Game.compute function and related test to the Game class Jun 12, 2025
@mmschlk mmschlk merged commit 4b487a8 into main Jun 12, 2025
7 checks passed
@mmschlk mmschlk deleted the 345-add-a-compute-method-to-the-game-class branch June 12, 2025 15:02
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.

add a compute() method to the Game class
2 participants