-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactors Regression into RegressionSII and RegressionFSI
- Loading branch information
Showing
9 changed files
with
154 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""This module contains the regression-based approximators to estimate Shapley interaction values. | ||
""" | ||
from ._base import Regression | ||
from .sii import RegressionSII | ||
from .fsi import RegressionFSI | ||
|
||
__all__ = ["Regression"] | ||
__all__ = ["RegressionSII", "RegressionFSI"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Regression with Faithful Shapley Interaction (FSI) index approximation.""" | ||
from typing import Optional | ||
|
||
from ._base import Regression | ||
from .._base import NShapleyMixin | ||
|
||
|
||
class RegressionFSI(Regression, NShapleyMixin): | ||
"""Estimates the FSI values using the weighted least square approach. | ||
Args: | ||
n: The number of players. | ||
max_order: The interaction order of the approximation. | ||
random_state: The random state of the estimator. Defaults to `None`. | ||
Attributes: | ||
n: The number of players. | ||
N: The set of players (starting from 0 to n - 1). | ||
max_order: The interaction order of the approximation. | ||
min_order: The minimum order of the approximation. For FSI, min_order is equal to 1. | ||
iteration_cost: The cost of a single iteration of the regression FSI. | ||
Example: | ||
>>> from games import DummyGame | ||
>>> from approximator import RegressionFSI | ||
>>> game = DummyGame(n=5, interaction=(1, 2)) | ||
>>> approximator = RegressionFsi(n=5, max_order=2) | ||
>>> approximator.approximate(budget=100, game=game) | ||
InteractionValues( | ||
index=FSI, order=2, estimated=False, estimation_budget=32, | ||
values={ | ||
(0,): 0.2, | ||
(1,): 0.7, | ||
(2,): 0.7, | ||
(3,): 0.2, | ||
(4,): 0.2, | ||
(0, 1): 0, | ||
(0, 2): 0, | ||
(0, 3): 0, | ||
(0, 4): 0, | ||
(1, 2): 1.0, | ||
(1, 3): 0, | ||
(1, 4): 0, | ||
(2, 3): 0, | ||
(2, 4): 0, | ||
(3, 4): 0 | ||
} | ||
) | ||
""" | ||
|
||
def __init__(self, n: int, max_order: int, random_state: Optional[int] = None): | ||
super().__init__(n, max_order, index="FSI", random_state=random_state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Regression with Shapley interaction index (SII) approximation.""" | ||
from typing import Optional | ||
|
||
from ._base import Regression | ||
from .._base import NShapleyMixin | ||
|
||
|
||
class RegressionSII(Regression, NShapleyMixin): | ||
"""Estimates the SII values using the weighted least square approach. | ||
Args: | ||
n: The number of players. | ||
max_order: The interaction order of the approximation. | ||
random_state: The random state of the estimator. Defaults to `None`. | ||
Attributes: | ||
n: The number of players. | ||
N: The set of players (starting from 0 to n - 1). | ||
max_order: The interaction order of the approximation. | ||
min_order: The minimum order of the approximation. For the regression estimator, min_order | ||
is equal to 1. | ||
iteration_cost: The cost of a single iteration of the regression SII. | ||
Example: | ||
>>> from games import DummyGame | ||
>>> from approximator import RegressionSII | ||
>>> game = DummyGame(n=5, interaction=(1, 2)) | ||
>>> approximator = RegressionSII(n=5, max_order=2) | ||
>>> approximator.approximate(budget=100, game=game) | ||
InteractionValues( | ||
index=SII, order=2, estimated=False, estimation_budget=32, | ||
values={ | ||
(0,): 0.2, | ||
(1,): 0.7, | ||
(2,): 0.7, | ||
(3,): 0.2, | ||
(4,): 0.2, | ||
(0, 1): 0, | ||
(0, 2): 0, | ||
(0, 3): 0, | ||
(0, 4): 0, | ||
(1, 2): 1.0, | ||
(1, 3): 0, | ||
(1, 4): 0, | ||
(2, 3): 0, | ||
(2, 4): 0, | ||
(3, 4): 0 | ||
} | ||
) | ||
""" | ||
|
||
def __init__(self, n: int, max_order: int, random_state: Optional[int] = None): | ||
super().__init__(n, max_order, index="SII", random_state=random_state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters