def select_active(self, domain, data, formula, active_indices): all_violations = list( AllViolationsStrategy.select_active(self, domain, data, formula, active_indices)) self.last_violations = all_violations sample_size = min(self.sample_size, len(all_violations)) import sampling return sampling.sample_weighted( zip(all_violations, [self.weights[i] for i in all_violations]), sample_size)
def get_initial_indices(self): if self.initial is None: return list(range(len(self.data))) elif self.initial == "random": return random.sample(range(len(self.data)), self.initial_size) elif self.initial == "dt_weighted": import sampling return sampling.sample_weighted(zip(range(len(self.data)), self.get_dt_weights()), self.initial_size) else: raise RuntimeError("Unknown initial type {}".format(self.initial))
def select_active( self, domain, data, labels, formula, active_indices) -> Tuple[np.ndarray, np.ndarray, List[int]]: data, labels, all_violations = AllViolationsStrategy.select_active( self, domain, data, labels, formula, active_indices) self.last_violations = list(all_violations) sample_size = min(self.sample_size, len(self.last_violations)) import sampling return data, labels, sampling.sample_weighted( zip(self.last_violations, [self.weights[i] for i in self.last_violations]), sample_size)