Skip to content

Commit ac56146

Browse files
authored
ExactComputer Refactor Types and Making n_players optional. (#450)
* makes n_players optional * adds tests for new behaviour * refactored ExactComputer to be type safe and closes * adds tests for checking wrong indices * updates CHANGELOG.md * fixed broken tests
1 parent 676d00a commit ac56146

14 files changed

Lines changed: 362 additions & 315 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This restructuring aims to improve maintainability and development scalability.
2020
### Maintenance and Development
2121
- refactored the `shapiq.Games` and `shapiq.InteractionValues` API by adding an interactions and game_values dictionary as the main data structure to store the interaction scores and game values. This allows for more efficient storage and retrieval of interaction values and game values, as well as easier manipulation of the data. [#419](https://github.com/mmschlk/shapiq/pull/419)
2222
- addition and subtraction of InteractionValues objects (via `shapiq.InteractionValues.__add__`) now also works for different indices, which will raise a warning and will return a new InteractionValues object with the index set of the first. [#422](https://github.com/mmschlk/shapiq/pull/422)
23+
- refactors the `shapiq.ExactComputer` to allow for initialization without passing n_players when a `shapiq.Game` object is passed [#388](https://github.com/mmschlk/shapiq/issues/388). Also introduces a tighter type hinting for the `index` parameter using `Literal` types. [#450](https://github.com/mmschlk/shapiq/pull/450)
2324

2425
### Docs
2526
- added an example notebook for `InteractionValues`, highlighting *Initialization*, *Modification*, *Visualization* and *Save and Loading*.

examples/api_examples/interaction_values.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@
122122
}
123123
],
124124
"source": [
125-
"from shapiq.game_theory.indices import ALL_AVAILABLE_INDICES\n",
125+
"from shapiq.game_theory.indices import AllIndices\n",
126126
"\n",
127-
"ALL_AVAILABLE_INDICES"
127+
"AllIndices"
128128
]
129129
},
130130
{

src/shapiq/game.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
CoalitionTuple,
2828
GameScores,
2929
GameValues,
30+
IndexType,
3031
JSONType,
3132
MetadataBlock,
3233
)
@@ -712,7 +713,7 @@ def __str__(self) -> str:
712713
"""Return a string representation of the game."""
713714
return self.__repr__()
714715

715-
def exact_values(self, index: str, order: int) -> InteractionValues:
716+
def exact_values(self, index: IndexType, order: int) -> InteractionValues:
716717
"""Uses the ExactComputer to compute the exact interaction values.
717718
718719
Args:
@@ -733,7 +734,7 @@ def exact_values(self, index: str, order: int) -> InteractionValues:
733734
stacklevel=2,
734735
)
735736

736-
exact_computer = ExactComputer(self.n_players, game=self)
737+
exact_computer = ExactComputer(game=self, n_players=self.n_players)
737738
return exact_computer(index=index, order=order)
738739

739740
@property

0 commit comments

Comments
 (0)