Skip to content

Commit 20b06d5

Browse files
committed
ORL: Fix tuple error when removed every instance
1 parent 2cb7821 commit 20b06d5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

adlib/learners/outlier_removal_learner.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ def train(self):
5050
iteration = 0
5151

5252
while cutoff < max_cutoff:
53-
fvs, labels = self._remove_outliers(fvs, labels, cutoff)
53+
try:
54+
fvs, labels = self._remove_outliers(fvs, labels, cutoff)
55+
except: # Failure - usually when there are no instances left (removes all)
56+
if self.verbose:
57+
print('\nORL Iteration:', iteration, '- factor:', factor,
58+
'- cutoff:', cutoff, '- FAILURE\n')
59+
60+
factor += 1
61+
cutoff = base_cutoff * factor
62+
fvs, labels = deepcopy(orig_fvs), deepcopy(orig_labels)
63+
iteration += 1
5464

5565
self.w = np.full(fvs.shape[1], 0.0)
5666
for i, fv in enumerate(fvs):
@@ -97,7 +107,7 @@ def _remove_outliers(self, fvs, labels, cutoff):
97107
while old_number_of_instances != len(labels):
98108
# Assume at least 50% are non-poisonous instances
99109
if iteration > 0 and old_number_of_instances < 0.5 * original_num_instances:
100-
break
110+
raise ValueError()
101111

102112
if self.verbose:
103113
print('Iteration:', iteration, '- num_instances:', len(labels))

0 commit comments

Comments
 (0)