-
Notifications
You must be signed in to change notification settings - Fork 492
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
Fixes for Boolean Input Tensors #666
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from tests.helpers.basic_models import ( | ||
BasicModel_MultiLayer, | ||
BasicModel_MultiLayer_MultiInput, | ||
BasicModelBoolInput, | ||
) | ||
|
||
|
||
|
@@ -39,6 +40,29 @@ def test_simple_shapley_sampling_with_mask(self) -> None: | |
perturbations_per_eval=(1, 2, 3), | ||
) | ||
|
||
def test_simple_shapley_sampling_boolean(self) -> None: | ||
net = BasicModelBoolInput() | ||
inp = torch.tensor([[True, False, True]]) | ||
self._shapley_test_assert( | ||
net, | ||
inp, | ||
[35.0, 35.0, 35.0], | ||
feature_mask=torch.tensor([[0, 0, 1]]), | ||
perturbations_per_eval=(1, 2, 3), | ||
) | ||
|
||
def test_simple_shapley_sampling_boolean_with_baseline(self) -> None: | ||
net = BasicModelBoolInput() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another way of testing would be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I double checked the values manually, they seem correct. |
||
inp = torch.tensor([[True, False, True]]) | ||
self._shapley_test_assert( | ||
net, | ||
inp, | ||
[-40.0, -40.0, 0.0], | ||
feature_mask=torch.tensor([[0, 0, 1]]), | ||
baselines=True, | ||
perturbations_per_eval=(1, 2, 3), | ||
) | ||
|
||
def test_simple_shapley_sampling_with_baselines(self) -> None: | ||
net = BasicModel_MultiLayer() | ||
inp = torch.tensor([[20.0, 50.0, 30.0]]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to inputs being boolean or is it so that we can use
~
operator ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is necessary since if this mask is an int / float, multiplying by a boolean still casts product to int / float causing the masked input to not be a boolean.