Skip to content

Commit 2f7028e

Browse files
Fix/anchor base coverage update (#919)
* Fixed AnchorBased coverage updated for proposed anchors after computation. * Removed commented lines and removed unecessary dummy updates of coverage from tests.
1 parent 5c07c14 commit 2f7028e

File tree

2 files changed

+0
-8
lines changed

2 files changed

+0
-8
lines changed

alibi/explainers/anchors/anchor_base.py

-2
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ def update_state(self, covered_true: np.ndarray, covered_false: np.ndarray, labe
458458
self.state['t_idx'][anchor].update(idxs)
459459
self.state['t_nsamples'][anchor] += n_samples
460460
self.state['t_positives'][anchor] += labels.sum()
461-
if coverage > -1:
462-
self.state['t_coverage'][anchor] = coverage
463461
self.state['t_covered_true'][anchor] = covered_true
464462
self.state['t_covered_false'][anchor] = covered_false
465463
self.state['data'][idxs] = data

alibi/explainers/tests/test_anchor_base.py

-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def test_anchor_base_beam(rf_classifier, at_defaults, at_iris_explainer):
1616
# inputs
1717
n_anchors_to_sample = 6
1818
coverage_samples = 500
19-
dummy_coverage = - 0.55 # used to test coverage updates on sampling
2019

2120
X_test, explainer, predict_fn, predict_type = at_iris_explainer
2221
explain_defaults = at_defaults
@@ -37,15 +36,10 @@ def test_anchor_base_beam(rf_classifier, at_defaults, at_iris_explainer):
3736
to_sample.append(tuple(anchor))
3837
to_sample = list(set(to_sample))
3938
current_state = deepcopy(anchor_beam.state)
40-
for anchor in to_sample:
41-
if anchor not in current_state['t_nsamples']:
42-
anchor_beam.state['t_coverage'][anchor] = dummy_coverage
4339
pos, total = anchor_beam.draw_samples(to_sample, explain_defaults['batch_size'])
4440
for p, t, anchor in zip(pos, total, to_sample):
4541
assert anchor_beam.state['t_nsamples'][anchor] == current_state['t_nsamples'][anchor] + t
4642
assert anchor_beam.state['t_positives'][anchor] == current_state['t_positives'][anchor] + p
47-
if anchor: # empty anchor has dummy coverage
48-
assert anchor_beam.state['t_coverage'][anchor] != dummy_coverage
4943

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

0 commit comments

Comments
 (0)