Skip to content

Commit

Permalink
fixed the setter of _empty/_grand values
Browse files Browse the repository at this point in the history
  • Loading branch information
mmschlk committed Oct 25, 2024
1 parent d944f80 commit 0b3da72
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions shapiq/games/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,8 @@ def __init__(
# define some handy coalition variables
self.empty_coalition = np.zeros(self.n_players, dtype=bool)
self.grand_coalition = np.ones(self.n_players, dtype=bool)
# don't know if the following is kosher (probably not)
try:
self._empty_coalition_value = self._empty_coalition_value
except AttributeError:
self._empty_coalition_value = None
try:
self._grand_coalition_value = self._grand_coalition_value
except AttributeError:
self._grand_coalition_value = None
self._empty_coalition_value_property = None
self._grand_coalition_value_property = None

self.verbose = verbose

Expand Down Expand Up @@ -423,16 +416,16 @@ def get_game_name(cls) -> str:
@property
def empty_coalition_value(self) -> float:
"""Return the value of the empty coalition."""
if self._empty_coalition_value is None:
self._empty_coalition_value = float(self(self.empty_coalition))
return self._empty_coalition_value
if self._empty_coalition_value_property is None:
self._empty_coalition_value_property = float(self(self.empty_coalition))
return self._empty_coalition_value_property

@property
def grand_coalition_value(self) -> float:
"""Return the value of the grand coalition."""
if self._grand_coalition_value is None:
self._grand_coalition_value = float(self(self.grand_coalition))
return self._grand_coalition_value
if self._grand_coalition_value_property is None:
self._grand_coalition_value_property = float(self(self.grand_coalition))
return self._grand_coalition_value_property

def __getitem__(self, item: tuple[int, ...]):
"""Return the value of the given coalition. Only retrieves precomputed/store values.
Expand Down

0 comments on commit 0b3da72

Please sign in to comment.