The diversity estimated for each base classifier
_, idx_neighbors = self._get_region_competence(query)
idx_neighbors = idx_neighbors.reshape(1, -1)
hit_result = self.processed_dsel[idx_neighbors, :]
predicted_matrix = self.BKS_dsel[idx_neighbors, :]
// calculate the classifiers mean accuracy for all samples
competences = np.mean(hit_result, axis=1)
After Change
_, idx_neighbors = self._get_region_competence(query)
// calculate the classifiers mean accuracy for all samples/base classifier
accuracy = np.mean(self.processed_dsel[idx_neighbors, :], axis=1)
predicted_matrix = self.BKS_dsel[idx_neighbors, :]
targets = self.DSEL_target[idx_neighbors]
// TODO: try to optimize this part with numpy instead of for
// Calculate the more_diverse matrix. It becomes computationally expensive
// When the region of competence is high
diversity = np.zeros((query.shape[0], self.n_classifiers))
for sample_idx in range(query.shape[0]):
for clf_index in range(self.n_classifiers):
for clf_index2 in range(clf_index + 1, self.n_classifiers):
this_diversity = self.diversity_func(targets[sample_idx, :],
predicted_matrix[sample_idx, :, clf_index],
predicted_matrix[sample_idx, :, clf_index2])
diversity[sample_idx, clf_index] += this_diversity
diversity[sample_idx, clf_index2] += this_diversity
competences = {"accuracy" : accuracy, "diversity" : diversity}
return competences
def select(self, competences):