Calculates the entropy for a labeling.

    Parameters
    ----------
    labels : list-like
        List of labels.

    Returns
    -------
    entropy : float
        Entropy of the labeling.

    .. note:: Based on sklearn.metrics.cluster.entropy
428889
def _entropy(labels):
    
    if len(labels) == 0:
        return 1.0
    label_idx = np.unique(labels, return_inverse=True)[1]
    pi = np.bincount(label_idx).astype(np.float)
    pi = pi[pi > 0]
    pi_sum = np.sum(pi)
    # log(a / b) should be calculated as log(a) - log(b) for
    # possible loss of precision
    return -np.sum((pi / pi_sum) * (np.log(pi) - np.log(pi_sum)))
453089
def find_max_label_length(labels):
    """"""
    length = 0
    for i in range(len(labels)):
        if len(labels[i]) > length:
            length = len(labels[i])

    return length
425810
def entropy(data):
    

    if len(data) == 0:
        return None

    n = sum(data)

    _op = lambda f: f * math.log(f)
    return - sum(_op(float(i) / n) for i in data)
285380
def get_label(self, label, params=None):
        
        return self.label(label, action='GET', params=params)
353179
def _get_labels_and_weights(self, content, comments):
        
        # extract content and comments
        if 'content' in self.to_extract and 'comments' in self.to_extract:
            labels = np.logical_or(content[0], comments[0]).astype(int)
            weights = content[1],
        # extract content only
        elif 'content' in self.to_extract:
            labels = content[0]
            weights = content[1]
        # extract comments only
        else:
            labels = comments[0]
            weights = comments[1]
        if self.max_block_weight is None:
            weights = np.minimum(weights, self.max_block_weight)

        return labels, weights
818832
def get_spacer_label(self):
        

        spacer = QLabel()
        spacer.setObjectName("Spacer_label")
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        return spacer
407715
def mutual_info_score(self, reference_clusters):
        
        return mutual_info_score(self.get_labels(self), self.get_labels(reference_clusters))
1314099
def labels(self):
        
        if not self.__labels:
            self.__labels = Labels(self.__connection)
        return self.__labels
1305847
def get_labels(labels):
    """"""
    label_u = unique_labels(labels)
    label_u_line = [i + "_line" for i in label_u]
    return label_u, label_u_line
62634
def info(self, val):
        """"""
        if self._labelname_set.intersection(val.keys()):
            raise ValueError('Overlapping labels for Info metric, metric: %s child: %s' % (
                self._labelnames, val))
        with self._lock:
            self._value = dict(val)
118058
def update(self, labels, preds):
        
        # get generated multi label from network
        cls_prob = preds[0].asnumpy()
        loc_loss = preds[1].asnumpy()
        cls_label = preds[2].asnumpy()
        valid_count = np.sum(cls_label >= 0)
        # overall accuracy & object accuracy
        label = cls_label.flatten()
        mask = np.where(label >= 0)[0]
        indices = np.int64(label[mask])
        prob = cls_prob.transpose((0, 2, 1)).reshape((-1, cls_prob.shape[1]))
        prob = prob[mask, indices]
        self.sum_metric[0] += (-np.log(prob + self.eps)).sum()
        self.num_inst[0] += valid_count
        # smoothl1loss
        self.sum_metric[1] += np.sum(loc_loss)
        self.num_inst[1] += valid_count
298472
def __learn_labels(self, labels):
        
        if self.feature_length > 0:
            result = list(self.labels.classes_)
        else:
            result = []

        for label in labels:
            result.append(label)
        self.labels.fit(result)
1101816
def labels(self):
        
        all_labels = set(self.token_patterns.keys())
        all_labels.update(self.phrase_patterns.keys())
        return tuple(all_labels)
715992
def labels(self):
        
        if self._labels is None:
            self._labels = map(self.labelFormat().format, self.values())
        return self._labels
1151659
def labels(self):
        
        labelings = OrderedDict()
        for tree in self:
            for label, line in tree.to_labeled_lines():
                labelings[line] = label
        return labelings
879632
def check(labels):
        
        # type checking
        if not isinstance(labels, list):
            raise IOError('labels are not in a list')
        if not len(labels):
            raise IOError('the labels list is empty')
        if not all([isinstance(l, np.ndarray) for l in labels]):
            raise IOError('all labels must be numpy arrays')

        # dimension checking
        ndim = labels[0].ndim
        if ndim not in [1, 2]:
            raise IOError('labels dimension must be 1 or 2')
        if not all([l.ndim == ndim for l in labels]):
            raise IOError('all labels dimensions must be equal')
        if ndim == 2:
            shape1 = labels[0].shape[1]
            if not all([l.shape[1] == shape1 for l in labels]):
                raise IOError('all labels must have same shape on 2nd dim')

        # sort checking
        for label in labels:
            index = (np.argsort(label) if label.ndim == 1
                     else np.lexsort(label.T))
            # print label, index
            # print len(index), label.shape[0]
            assert len(index) == label.shape[0]
            if not all(n == index[n] for n in range(label.shape[0]-1)):
                raise IOError('labels are not sorted in increasing order')
551424
def make_labels(mapping):
    
    labels = mapping.copy()
    for ae in labels:
        labels[ae] = strip_calculated_markers(labels[ae])
    return labels