def noisy_max(logits, lap_scale, return_clean_votes=False):
 labels = labels_from_probs(logits)
 labels_shape = np.shape(labels)
 labels = labels.reshape((labels_shape[0], labels_shape[1]))
 result = np.zeros(int(labels_shape[1]))
 if return_clean_votes:
  clean_votes = np.zeros((int(labels_shape[1]), 10))
 for i in xrange(int(labels_shape[1])):
  label_counts = np.bincount(labels[:, i], minlength=10)
  if return_clean_votes:
   clean_votes[i] = label_counts
  label_counts = np.asarray(label_counts, dtype=np.float32)
  for item in xrange(10):
   label_counts[item] += np.random.laplace(loc=0.0, scale=float(lap_scale))
  result[i] = np.argmax(label_counts)
 result = np.asarray(result, dtype=np.int32)
 if return_clean_votes:
  return (result, clean_votes, labels)
 else:
  return result

def noisy_max ( logits , lap_scale , return_clean_votes = False ) : labels = labels_from_probs ( logits ) labels_shape = np . shape ( labels ) labels = labels . reshape ( ( labels_shape [ 0 ] , labels_shape [ 1 ] ) ) result = np . zeros ( int ( labels_shape [ 1 ] ) ) if return_clean_votes : clean_votes = np . zeros ( ( int ( labels_shape [ 1 ] ) , 10 ) ) for i in xrange ( int ( labels_shape [ 1 ] ) ) : label_counts = np . bincount ( labels [ : , i ] , minlength = 10 ) if return_clean_votes : clean_votes [ i ] = label_counts label_counts = np . asarray ( label_counts , dtype = np . float32 ) for item in xrange ( 10 ) : label_counts [ item ] += np . random . laplace ( loc = 0.0 , scale = float ( lap_scale ) ) result [ i ] = np . argmax ( label_counts ) result = np . asarray ( result , dtype = np . int32 ) if return_clean_votes : return ( result , clean_votes , labels ) else : return result
this aggregation mechanism takes the softmax/logit output of several models resulting from inference on identical inputs and computes the noisy-max of the votes for candidate classes to select a label for each sample: it adds laplacian noise to label counts and returns the most frequent label .