Computes the relationship between probability threshold
        and classification accuracy.
979856
def accuracy_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.accuracy)
            taus.append(tau)

            # update threshold
            tau = sorted_probs[k]

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

        self.threshold = orig_thresh
        return scores, taus
194328
def compute_threshold(smoothed_errors, error_buffer, sd_limit=12.0):
    
    mu = np.mean(smoothed_errors)
    sigma = np.std(smoothed_errors)

    max_epsilon = 0
    sd_threshold = sd_limit

    # The treshold is determined dynamically by testing multiple Zs.
    # z is drawn from an ordered set of positive values representing the
    # number of standard deviations above mean(smoothed_errors)

    # here we iterate in increments of 0.5 on the range that the NASA paper found to be good
    for z in np.arange(2.5, sd_limit, 0.5):
        epsilon = mu + (sigma * z)
        below_epsilon, below_indices, above_epsilon = [], [], []

        for i in range(len(smoothed_errors)):
            e = smoothed_errors[i]
            if e < epsilon:
                # save to compute delta mean and delta std
                # these are important for epsilon calculation
                below_epsilon.append(e)
                below_indices.append(i)

            if e > epsilon:
                # above_epsilon values are anomalies
                for j in range(0, error_buffer):
                    if (i + j) not in above_epsilon and (i + j) < len(smoothed_errors):
                        above_epsilon.append(i + j)

                    if (i - j) not in above_epsilon and (i - j) >= 0:
                        above_epsilon.append(i - j)

        if len(above_epsilon) == 0:
            continue

        # generate sequences
        above_epsilon = sorted(list(set(above_epsilon)))
        groups = [list(group) for group in mit.consecutive_groups(above_epsilon)]
        above_sequences = [(g[0], g[-1]) for g in groups if not g[0] == g[-1]]

        mean_perc_decrease = (mu - np.mean(below_epsilon)) / mu
        sd_perc_decrease = (sigma - np.std(below_epsilon)) / sigma
        epsilon = (mean_perc_decrease + sd_perc_decrease) /\
                  (len(above_sequences)**2 + len(above_epsilon))

        # update the largest epsilon we've seen so far
        if epsilon > max_epsilon:
            sd_threshold = z
            max_epsilon = epsilon

    # sd_threshold can be multiplied by sigma to get epsilon
    return max_epsilon, sd_threshold
281540
def _thresholds_init(self):
        
        thresholds = getattr(self._py3status_module, "thresholds", [])
        self._thresholds = {}
        if isinstance(thresholds, list):
            try:
                thresholds.sort()
            except TypeError:
                pass
            self._thresholds[None] = [(x[0], self._get_color(x[1])) for x in thresholds]
            return
        elif isinstance(thresholds, dict):
            for key, value in thresholds.items():
                if isinstance(value, list):
                    try:
                        value.sort()
                    except TypeError:
                        pass
                    self._thresholds[key] = [
                        (x[0], self._get_color(x[1])) for x in value
                    ]
1295626
def evaluate_accuracy(data_iterator, net):
    """"""
    acc = mx.metric.Accuracy()
    for data, label in data_iterator:
        output = net(data)
        predictions = nd.argmax(output, axis=1)
        predictions = predictions.reshape((-1, 1))
        acc.update(preds=predictions, labels=label)
    return acc.get()[1]
406028
def matches_sample(output, target, threshold, is_correct, actual_output):
        
        return (bool(output > threshold) == bool(target)) == is_correct and actual_output == bool(output > threshold)
577953
def call
      probability = 1.0

      graders.each do |lambda|
        instance = lambda.call(description)
        probability *= instance.call.to_f ** instance.weight
      end

      probability
    end
817450
def _count_classified_pixels(self):
        
        class_values = self.class_dictionary.values()

        classification_count = np.array([[[np.count_nonzero(prediction[np.nonzero(mask)] == class_val)
                                           for prediction, mask in zip(self.classification_masks, masktype)]
                                          for masktype in self.truth_masks]
                                         for class_val in class_values])

        classification_count = np.moveaxis(classification_count, 0, -1)
        classification_count = np.moveaxis(classification_count, 0, -2)

        if self.pixel_classification_counts is None:
            self.pixel_classification_counts = np.copy(classification_count)
        else:
            self.pixel_classification_counts = np.concatenate((self.pixel_classification_counts, classification_count))
221119
def neighborhood_probability(self, threshold, radius):
        
        weights = disk(radius, dtype=np.uint8)
        thresh_data = np.zeros(self.data.shape[1:], dtype=np.uint8)
        neighbor_prob = np.zeros(self.data.shape, dtype=np.float32)
        for t in np.arange(self.data.shape[0]):
            thresh_data[self.data[t] >= threshold] = 1
            maximized = fftconvolve(thresh_data, weights, mode="same")
            maximized[maximized > 1] = 1
            maximized[maximized < 1] = 0
            neighbor_prob[t] = fftconvolve(maximized, weights, mode="same")
            thresh_data[:] = 0
        neighbor_prob[neighbor_prob < 1] = 0
        neighbor_prob /= weights.sum()
        return neighbor_prob
819324
def _check_prob_and_prob_vector(predictions):
    
    from .._deps import numpy

    ptype = predictions.dtype
    import array
    if ptype not in [float, numpy.ndarray, array.array, int]:
        err_msg  = "Input `predictions` must be of numeric type (for binary "
        err_msg += "classification) or array (of probability vectors) for "
        err_msg += "multiclass classification."
        raise TypeError(err_msg)
1035605
def up_threshold(x, s, p):
    """"""
    if 1.0 * x/s >= p:
        return True
    elif stat.binom_test(x, s, p) > 0.01:
        return True
    return False
383341
def confidence_interval_hazard_(self):
        
        return self._compute_confidence_bounds_of_transform(self._hazard, self.alpha, self._ci_labels)
48318
function assertThreshold(value, other, threshold) {
  if (!threshold && value > other) throw new ThresholdError();
  const ratio = 1 - (value / other);
  if (ratio < threshold) throw new ThresholdError();
}
1074154
def is_correlated(self, threshold=0):
        
        return self.correlation_result if self.correlation_result.coefficient >= threshold else False
806630
def thresholds(self):
        """"""
        return numpy.array(
            sorted(self._key2float(key) for key in self._coefs), dtype=float)
954394
def accuracy(logits, labels):
  """"""
  is_correct = tf.nn.in_top_k(logits, labels, 1)
  correct = tf.reduce_sum(tf.cast(is_correct, tf.int32))
  incorrect = tf.reduce_sum(tf.cast(tf.logical_not(is_correct), tf.int32))
  correct_count = tf.Variable(0, False)
  incorrect_count = tf.Variable(0, False)
  correct_count_update = tf.assign_add(correct_count, correct)
  incorrect_count_update = tf.assign_add(incorrect_count, incorrect)
  accuracy_op = tf.cast(correct_count, tf.float32) / tf.cast(
      correct_count + incorrect_count, tf.float32)
  return [correct_count_update, incorrect_count_update], accuracy_op
729559
def threshold(image, block_size=DEFAULT_BLOCKSIZE, mask=None):
    
    if mask is None:
        mask = np.zeros(image.shape[:2], dtype=np.uint8)
        mask[:] = 255

    if len(image.shape) > 2 and image.shape[2] == 4:
        image = cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)
    res = _calc_block_mean_variance(image, mask, block_size)
    res = image.astype(np.float32) - res.astype(np.float32) + 255
    _, res = cv2.threshold(res, 215, 255, cv2.THRESH_BINARY)
    return res
663270
def _correctArtefacts(self, image, threshold):
        '''
        
        '''
        image = np.nan_to_num(image)
        medianThreshold(image, threshold, copy=False)
        return image