classLabellingBudgetStoppingCriterion(StoppingCriterion):"""Stops when the labelling budget is exhausted."""def__init__(self,active_dataset:ActiveLearningDataset,labelling_budget:int):super().__init__(active_dataset)self._start_length=len(active_dataset)self.labelling_budget=labelling_budgetdefshould_stop(self,metrics:Dict[str,float],uncertainty:Iterable[float])->bool:return(len(self._active_ds)-self._start_length)>=self.labelling_budget
Bases: StoppingCriterion
Stops when the average uncertainty is on average below a threshold.
classLowAverageUncertaintyStoppingCriterion(StoppingCriterion):"""Stops when the average uncertainty is on average below a threshold."""def__init__(self,active_dataset:ActiveLearningDataset,avg_uncertainty_thresh:float):super().__init__(active_dataset)self.avg_uncertainty_thresh=avg_uncertainty_threshdefshould_stop(self,metrics:Dict[str,float],uncertainty:Iterable[float])->bool:arr=np.array(uncertainty)returnbool(np.mean(arr)<self.avg_uncertainty_thresh)
Bases: StoppingCriterion
Early stopping on a particular metrics.
Notes:
We don't have any mandatory dependency with an early stopping implementation.
So we have our own.
classEarlyStoppingCriterion(StoppingCriterion):"""Early stopping on a particular metrics. Notes: We don't have any mandatory dependency with an early stopping implementation. So we have our own. """def__init__(self,active_dataset:ActiveLearningDataset,metric_name:str,patience:int=10,epsilon:float=1e-4,):super().__init__(active_dataset)self.metric_name=metric_nameself.patience=patienceself.epsilon=epsilonself._acc:List[float]=[]defshould_stop(self,metrics:Dict[str,float],uncertainty:Iterable[float])->bool:self._acc.append(metrics[self.metric_name])near_threshold=np.isclose(np.array(self._acc),self._acc[-1],atol=self.epsilon)returnlen(near_threshold)>=self.patienceandbool(near_threshold[-(self.patience+1):].all())