Skip to content

Commit 68f21c1

Browse files
authored
Relax interaction values eq function (mmschlk#427)
* relax eq condition for interaction values * fix pre-commit issues
1 parent 01f7694 commit 68f21c1

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/shapiq/interaction_values.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def __eq__(self, other: object) -> bool:
436436
or self.max_order != other.max_order
437437
or self.min_order != other.min_order
438438
or self.n_players != other.n_players
439-
or self.baseline_value != other.baseline_value
439+
or not np.allclose(self.baseline_value, other.baseline_value)
440440
):
441441
return False
442442
if not np.allclose(self.values, other.values):

tests/test_interaction_values.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from __future__ import annotations
2+
3+
import numpy as np
4+
5+
from shapiq.interaction_values import InteractionValues
6+
7+
8+
def test_interaction_values_eq():
9+
iv1 = InteractionValues(
10+
index="SV",
11+
max_order=1,
12+
min_order=0,
13+
estimated=False,
14+
estimation_budget=None,
15+
n_players=8,
16+
baseline_value=2.0719469373788755,
17+
values=np.array([0.0] * 300),
18+
)
19+
iv2 = InteractionValues(
20+
index="SV",
21+
max_order=1,
22+
min_order=0,
23+
estimated=False,
24+
estimation_budget=None,
25+
n_players=8,
26+
baseline_value=2.071946937378876, # Note the slight difference
27+
values=np.array([0.0] * 300),
28+
)
29+
assert iv1 == iv2

0 commit comments

Comments
 (0)