def _calculate_topk_ndces(self, k):
"""
Calculate the indices of the k specialists with highest b-value,
including the base classifier regardless of its b-value.
Args:
k: int >= 0, approximately specifying the number of derived specialists to select.
Precisely, the best k (by Wilson error bound) are taken, along with the
base classifier if it is not already one of the best k.
Returns:
A list containing the indices of the top k classifiers.
The list always at least contains the base classifier's index (i.e. 0).
Therefore, the list is of length k if the base classifier is one of the top k,
and length k+1 otherwise. If k is greater than the total number of derived
specialists, returns all of them.
"""
assert self.label_corrs is not None , "Label correlations must be calculated before top k indices."
if k < len(self.label_corrs):
topk_ndces = set(np.argpartition(-self.label_corrs, k)[:k]) #Only does a partial sort of b!
else:
topk_ndces = set(range(len(self.label_corrs)))
topk_ndces.add(0)
return list(topk_ndces & set(self._relevant_ndces))
评论列表
文章目录