Skip to content
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

Fix/anchor base coverage update #919

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions alibi/explainers/anchors/anchor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ def update_state(self, covered_true: np.ndarray, covered_false: np.ndarray, labe
self.state['t_idx'][anchor].update(idxs)
self.state['t_nsamples'][anchor] += n_samples
self.state['t_positives'][anchor] += labels.sum()
if coverage > -1:
self.state['t_coverage'][anchor] = coverage
self.state['t_covered_true'][anchor] = covered_true
self.state['t_covered_false'][anchor] = covered_false
self.state['data'][idxs] = data
Expand Down
6 changes: 0 additions & 6 deletions alibi/explainers/tests/test_anchor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_anchor_base_beam(rf_classifier, at_defaults, at_iris_explainer):
# inputs
n_anchors_to_sample = 6
coverage_samples = 500
dummy_coverage = - 0.55 # used to test coverage updates on sampling

X_test, explainer, predict_fn, predict_type = at_iris_explainer
explain_defaults = at_defaults
Expand All @@ -37,15 +36,10 @@ def test_anchor_base_beam(rf_classifier, at_defaults, at_iris_explainer):
to_sample.append(tuple(anchor))
to_sample = list(set(to_sample))
current_state = deepcopy(anchor_beam.state)
for anchor in to_sample:
if anchor not in current_state['t_nsamples']:
anchor_beam.state['t_coverage'][anchor] = dummy_coverage
pos, total = anchor_beam.draw_samples(to_sample, explain_defaults['batch_size'])
for p, t, anchor in zip(pos, total, to_sample):
assert anchor_beam.state['t_nsamples'][anchor] == current_state['t_nsamples'][anchor] + t
assert anchor_beam.state['t_positives'][anchor] == current_state['t_positives'][anchor] + p
if anchor: # empty anchor has dummy coverage
assert anchor_beam.state['t_coverage'][anchor] != dummy_coverage

# testing resampling works
# by sampling all features, we are guaranteed that partial anchors might not exist
Expand Down