Calculate accuracy.

    :param TP: true positive
    :type TP : int
    :param TN: true negative
    :type TN : int
    :param FP: false positive
    :type FP : int
    :param FN: false negative
    :type FN : int
    :return: accuracy as float
2754
def ACC_calc(TP, TN, FP, FN):
    
    try:
        result = (TP + TN) / (TP + TN + FN + FP)
        return result
    except ZeroDivisionError:
        return "None"
694614
def zero_one_loss_calc(TP, POP):
    
    try:
        length = POP
        return (length - sum(TP.values()))
    except Exception:
        return "None"
1090697
def accuracy(self):
        
        sub_observed = np.array([self.observed.metadata[i] for i in self.observed.arr])
        return float((self.model_predictions() == sub_observed).sum()) / self.data_size
357224
def accuracy(self, label, pred):
        
        hit = 0.
        total = 0.
        batch_size = label.shape[0]
        for i in range(batch_size):
            l = self._remove_blank(label[i])
            p = []
            for k in range(self.seq_len):
                p.append(np.argmax(pred[k * batch_size + i]))
            p = self.ctc_label(p)
            if len(p) == len(l):
                match = True
                for k, _ in enumerate(p):
                    if p[k] != int(l[k]):
                        match = False
                        break
                if match:
                    hit += 1.0
            total += 1.0
        assert total == batch_size
        return hit / total
938705
def get_accuracy(self, scalar=None):
        """"""
        # to get a Series instead of a dict:
        # (np.diag(c).astype(float) / c.T.sum())
        #     == pd.Series(self.sensitivity)
        if ((not self._scalar_stats and not scalar and self._num_classes > 2) or
                ((scalar is False or self._scalar_stats is False) and self._num_classes > 1)):
            return pd.Series(PrettyDict([(k, safe_div(self[k][k], self._num_total)) for k in self.columns]))
        return self._binary_accuracy
338861
def val_accuracy(show_swap):
    """"""
    kv = kernel_ver()
    pid = os.getpid()
    swap_accuracy = -1
    if kv[:2] == (2,4):
        if proc.open('meminfo').read().find("Inact_") == -1:
            return 1, swap_accuracy
        return 0, swap_accuracy
    elif kv[:2] == (2,6):
        if os.path.exists(proc.path(pid, 'smaps')):
            swap_accuracy = 1
            if proc.open(pid, 'smaps').read().find("Pss:")!=-1:
                return 2, swap_accuracy
            else:
                return 1, swap_accuracy
        if (2,6,1) <= kv <= (2,6,9):
            return -1, swap_accuracy
        return 0, swap_accuracy
    elif kv[0] > 2 and os.path.exists(proc.path(pid, 'smaps')):
        swap_accuracy = 1
        if show_swap and proc.open(pid, 'smaps').read().find("SwapPss:")!=-1:
            swap_accuracy = 2
        return 2, swap_accuracy
    else:
        return 1, swap_accuracy
1231278
def getFloat(t):
    
    d = c_double()
    if PL_get_float(t, byref(d)):
        return d.value
    else:
        raise InvalidTypeError("float")
108059
def f1_curve(self, delta_tau=0.01):
        
        # compute thresholds based on the sorted probabilities
        orig_thresh = self.threshold
        sorted_labels, sorted_probs = self.sorted_values

        scores = []
        taus = []
        tau = 0
        for k in range(len(sorted_labels)):
            # compute new accuracy
            self.threshold = tau
            scores.append(self.f1_score)
            taus.append(tau)

            # update threshold
            tau = sorted_probs[k]

        # add last datapoint
        tau = 1.0
        self.threshold = tau
        scores.append(self.f1_score)
        taus.append(tau)

        self.threshold = orig_thresh
        return scores, taus
1032196
def class_wise_accuracy(self, event_label, factor=0.5):
        

        sensitivity = metric.sensitivity(
            Ntp=self.class_wise[event_label]['Ntp'],
            Nfn=self.class_wise[event_label]['Nfn']
        )

        specificity = metric.specificity(
            Ntn=self.class_wise[event_label]['Ntn'],
            Nfp=self.class_wise[event_label]['Nfp']
        )

        balanced_accuracy = metric.balanced_accuracy(
            sensitivity=sensitivity,
            specificity=specificity,
            factor=factor
        )

        accuracy = metric.accuracy(
            Ntp=self.class_wise[event_label]['Ntp'],
            Ntn=self.class_wise[event_label]['Ntn'],
            Nfp=self.class_wise[event_label]['Nfp'],
            Nfn=self.class_wise[event_label]['Nfn']
        )

        return {
            'accuracy': accuracy,
            'balanced_accuracy': balanced_accuracy,
            'sensitivity': sensitivity,
            'specificity': specificity
        }
978583
def fnr(y, z):
    
    tp, tn, fp, fn = contingency_table(y, z)
    return fn / (fn + tp)
915122
def average_precision(truth, recommend):
    
    if len(truth) == 0:
        if len(recommend) == 0:
            return 1.
        return 0.

    tp = accum = 0.
    for n in range(recommend.size):
        if recommend[n] in truth:
            tp += 1.
            accum += (tp / (n + 1.))
    return accum / truth.size
939985
def evaluate_accuracy(data_iterator, net, ctx, loss_fun, num_classes):
    
    acc = mx.metric.Accuracy()
    loss_avg = 0.
    for i, ((data, length), label) in enumerate(data_iterator):
        data = data.as_in_context(ctx)  # .reshape((-1,784))
        length = length.astype('float32').as_in_context(ctx)
        label = label.as_in_context(ctx)
        output = net(data, length)
        loss = loss_fun(output, label)
        preds = []
        if num_classes == 2:
            preds = (nd.sign(output) + 1) / 2
            preds = preds.reshape(-1)
        else:
            preds = nd.argmax(output, axis=1)
        acc.update(preds=preds, labels=label)
        loss_avg = loss_avg * i / (i + 1) + nd.mean(loss).asscalar() / (i + 1)
    return acc.get()[1], loss_avg
1027710
def write_fix_accuracy(self, accuracy=None):
        

        if accuracy is None:
            accuracy = 500

        accuracy = int(accuracy)
        if not 0 < accuracy < 1000:
            raise ValueError('Invalid fix accuracy')

        self.write_fr_header('FXA', '%03d' % accuracy)
1198270
def padded_sequence_accuracy(logits, labels):
  """"""
  with tf.variable_scope("padded_sequence_accuracy", values=[logits, labels]):
    logits, labels = _pad_tensors_to_same_length(logits, labels)
    weights = tf.to_float(tf.not_equal(labels, 0))
    outputs = tf.to_int32(tf.argmax(logits, axis=-1))
    padded_labels = tf.to_int32(labels)
    not_correct = tf.to_float(tf.not_equal(outputs, padded_labels)) * weights
    axis = list(range(1, len(outputs.get_shape())))
    correct_seq = 1.0 - tf.minimum(1.0, tf.reduce_sum(not_correct, axis=axis))
    return correct_seq, tf.constant(1.0)
1107015
def accuracy(self, mode: OsuMode):
        
        if mode is OsuMode.osu:
            return (
                (6 * self.count300 + 2 * self.count100 + self.count50) /
                (6 * (self.count300 + self.count100 + self.count50 + self.countmiss)))
        if mode is OsuMode.taiko:
            return (
                (self.count300 + self.countgeki + (0.5*(self.count100 + self.countkatu))) /
                (self.count300 + self.countgeki + self.count100 + self.countkatu + self.countmiss))
        if mode is OsuMode.mania:
            return (
                (6 * (self.countgeki + self.count300) + 4 * self.countkatu + 2 * self.count100 + self.count50) /
                (6 * (self.countgeki + self.count300 + self.countkatu + self.count100 + self.count50 + self.countmiss)))
        if mode is OsuMode.ctb:
            return (
                (self.count50 + self.count100 + self.count300) /
                (self.count50 + self.count100 + self.count300 + self.countmiss + self.countkatu))
544294
def accuracy(y_true, y_pred, round=True):
    
    y_true, y_pred = _mask_value_nan(y_true, y_pred)
    if round:
        y_true = np.round(y_true)
        y_pred = np.round(y_pred)
    return skm.accuracy_score(y_true, y_pred)
138555
def F_calc(TP, FP, FN, beta):
    
    try:
        result = ((1 + (beta)**2) * TP) / \
            ((1 + (beta)**2) * TP + FP + (beta**2) * FN)
        return result
    except ZeroDivisionError:
        return "None"