def nonconformity(self, knns_labels):
    """
    Given an dictionary of nb_data x nb_classes dimension, compute the nonconformity of
    each candidate label for each data point: i.e. the number of knns whose label is
    different from the candidate label.
    """
    nb_data = knns_labels[self.layers[0]].shape[0]
    knns_not_in_class = np.zeros((nb_data, self.nb_classes), dtype=np.int32)
    for i in range(nb_data):
      # Compute number of nearest neighbors per class
      knns_in_class = np.zeros(
          (len(self.layers), self.nb_classes), dtype=np.int32)
      for layer_id, layer in enumerate(self.layers):
        knns_in_class[layer_id, :] = np.bincount(
            knns_labels[layer][i], minlength=self.nb_classes)

      # Compute number of knns in other class than class_id
      for class_id in range(self.nb_classes):
        knns_not_in_class[i, class_id] = np.sum(
            knns_in_class) - np.sum(knns_in_class[:, class_id])
    return knns_not_in_class
def nonconformity ( self , knns_labels ) : nb_data = knns_labels [ self . layers [ 0 ] ] . shape [ 0 ] knns_not_in_class = np . zeros ( ( nb_data , self . nb_classes ) , dtype = np . int32 ) for i in range ( nb_data ) : knns_in_class = np . zeros ( ( len ( self . layers ) , self . nb_classes ) , dtype = np . int32 ) for layer_id , layer in enumerate ( self . layers ) : knns_in_class [ layer_id , : ] = np . bincount ( knns_labels [ layer ] [ i ] , minlength = self . nb_classes ) for class_id in range ( self . nb_classes ) : knns_not_in_class [ i , class_id ] = np . sum ( knns_in_class ) - np . sum ( knns_in_class [ : , class_id ] ) return knns_not_in_class
Given an dictionary of nb_data x nb_classes dimension, compute the nonconformity of
    each candidate label for each data point: i.e. the number of knns whose label is
    different from the candidate label.