|
14 | 14 | class AADEvaluator(ConiferestEvaluator): |
15 | 15 | def __init__(self, aad): |
16 | 16 | super(AADEvaluator, self).__init__(aad, map_value=aad.map_value) |
| 17 | + self.budget = aad.budget |
17 | 18 | self.weights = np.full(shape=(self.n_leaves,), fill_value=np.reciprocal(np.sqrt(self.n_leaves))) |
18 | 19 |
|
| 20 | + def _q_tau(self, scores): |
| 21 | + if isinstance(self.budget, int): |
| 22 | + if self.budget >= len(scores): |
| 23 | + return np.max(scores) |
| 24 | + |
| 25 | + return np.partition(scores, self.budget)[self.budget] |
| 26 | + elif isinstance(self.budget, float): |
| 27 | + return np.quantile(scores, self.budget) |
| 28 | + |
| 29 | + raise ValueError("self.budget must be an int or float") |
| 30 | + |
19 | 31 | def score_samples(self, x, weights=None): |
20 | 32 | """ |
21 | 33 | Perform the computations. |
@@ -250,17 +262,6 @@ def _build_trees(self, data): |
250 | 262 | self.trees = self.build_trees(data, self.n_trees) |
251 | 263 | self.evaluator = AADEvaluator(self) |
252 | 264 |
|
253 | | - def _q_tau(self, scores): |
254 | | - if isinstance(self.budget, int): |
255 | | - if self.budget >= len(scores): |
256 | | - return np.max(scores) |
257 | | - |
258 | | - return np.partition(scores, self.budget)[self.budget] |
259 | | - elif isinstance(self.budget, float): |
260 | | - return np.quantile(scores, self.budget) |
261 | | - |
262 | | - raise ValueError("self.budget must be an int or float") |
263 | | - |
264 | 265 | def fit(self, data, labels=None): |
265 | 266 | """ |
266 | 267 | Build the trees with the data `data`. |
@@ -324,7 +325,7 @@ def fit_known(self, data, known_data=None, known_labels=None): |
324 | 325 | return self |
325 | 326 |
|
326 | 327 | scores = self.score_samples(data) |
327 | | - q_tau = self._q_tau(scores) |
| 328 | + q_tau = self.evaluator._q_tau(scores) |
328 | 329 |
|
329 | 330 | anomaly_count = np.count_nonzero(known_labels == Label.ANOMALY) |
330 | 331 | nominal_count = np.count_nonzero(known_labels == Label.REGULAR) |
|
0 commit comments