Computes the relationship between probability threshold
        and classification phi coefficient.
540501
def phi_coef_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.phi_coef)
            taus.append(tau)

            # update threshold
            tau = sorted_probs[k]

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

        self.threshold = orig_thresh
        return scores, taus
806630
def thresholds(self):
        """"""
        return numpy.array(
            sorted(self._key2float(key) for key in self._coefs), dtype=float)
535080
private static boolean checkCriticalValue(double score, int h, double aLevel, int p, int q) { //p and q are used only in ARIMA Models (p,0,q).
        double probability=ContinuousDistributions.chisquareCdf(score,h - p - q);

        boolean rejectH0=false;

        double a=aLevel;
        if(probability>=(1-a)) {
            rejectH0=true;
        }

        return rejectH0;
    }
500359
private double calcEntropy(final List<Match> matches, final boolean include_brute_force)
    {
        double entropy = 0;
        for (Match match : matches)
        {
            if (include_brute_force || !(match instanceof BruteForceMatch))
            {
                entropy += match.calculateEntropy();
            }
        }
        return entropy;
    }
121494
def scores_to_preds(self, threshold, use_probs = True):
        
        self.threshold = threshold

        if use_probs:
            if self.probs is None:
                raise DataError("Probabilities are not available to make "
                                "predictions.")
            else:
                word = "probabilities"
                scores = self.probs
        else:
            if self.scores is None:
                raise DataError("Scores are not available to make predictions.")
            else:
                word = "scores"
                scores = self.scores

        if threshold > np.max(scores) or threshold < np.min(scores):
            warnings.warn("Threshold {} is outside the range of the "
                          "{}.".format(self.threshold, word))

        if self.preds is not None:
            warnings.warn("Overwriting predictions")
        self.preds = (scores >= threshold)*1
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
1046152
def _gaussian_membership_sigma(smoothness, eps = 0.0005): # 275us @ smothness=10
    
    """
    error = 0
    deltas = [0.1, 0.01, 0.001, 0.0001]
    sigma = smoothness * 0.3
    point = -1. * (smoothness + 0.5)
    for delta in deltas:
        while error < eps:
            sigma += delta
            error = scipy.stats.norm.cdf(0.5, point, sigma) - scipy.stats.norm.cdf(-0.5, point, sigma) # x, mu, sigma
        sigma -= delta
    return sigma
679230
private int computePk1Measure(double[] objectiveScores,
                                  double pk1Threshold) {
        LOGGER.fine("Computing the PK1 measure");

        // Compute the average of the objective scores.
        double average = 0;
        for (int k = 0; k < objectiveScores.length; ++k)
            average += objectiveScores[k];
        average /= objectiveScores.length;

        // Compute the standard deviation of the objective scores.
        double stdev = 0;
        for (int k = 0; k < objectiveScores.length; ++k)
            stdev += Math.pow(objectiveScores[k], 2);
        stdev /= objectiveScores.length;
        stdev = Math.sqrt(stdev);

        // Find the smallest k such that the pk1 score surpasses the threshold.
        for (int k = 0; k < objectiveScores.length; ++k) {
            objectiveScores[k] = (objectiveScores[k] - average) / stdev;
            if (objectiveScores[k] > pk1Threshold)
                return k;
        }

        return 0;
    }
260418
def hpd_threshold(mu_in, post, alpha, tol):
    '''
    
    '''
    norm_post = normalize_pdf(mu_in, post)
    # initialize bisection search
    p_minus = 0.0
    p_plus = max(post)
    while abs(hpd_coverage(mu_in, norm_post, p_minus) -
              hpd_coverage(mu_in, norm_post, p_plus)) >= tol:
        p_test = (p_minus + p_plus) / 2.
        if hpd_coverage(mu_in, post, p_test) >= alpha:
            # test value was too low or just right
            p_minus = p_test
        else:
            # test value was too high
            p_plus = p_test
    # p_minus never goes above the required threshold and p_plus never goes below
    # thus on exiting p_minus is at or below the required threshold and the
    # difference in coverage is within tolerance
    return p_minus
511638
def cross_entropy_calc(TOP, P, POP):
    
    try:
        result = 0
        for i in TOP.keys():
            reference_likelihood = P[i] / POP[i]
            response_likelihood = TOP[i] / POP[i]
            if response_likelihood != 0 and reference_likelihood != 0:
                result += reference_likelihood * \
                    math.log(response_likelihood, 2)
        return -result
    except Exception:
        return "None"
1074154
def is_correlated(self, threshold=0):
        
        return self.correlation_result if self.correlation_result.coefficient >= threshold else False
152948
def predict_proba(self, X):
        """"""
        return F.softmax(self.forward(X), dim=1).data.cpu().numpy()
993772
def get_threshold(self):
        """"""
        value_map = dict()
        for key, value in list(self.threshold_classes.items()):
            value_map[key] = [
                value[0].value(),
                value[1].value(),
            ]
        return value_map
574945
def _compute_schoenfeld_within_strata(self, X, T, E, weights):
        
        # TODO: the diff_against is gross
        # This uses Efron ties.

        n, d = X.shape

        if not np.any(E):
            # sometimes strata have no deaths. This means nothing is returned
            # in the below code.
            return np.zeros((n, d))

        # Init risk and tie sums to zero
        risk_phi, tie_phi = 0, 0
        risk_phi_x, tie_phi_x = np.zeros((1, d)), np.zeros((1, d))

        # Init number of ties and weights
        weight_count = 0.0
        tie_count = 0

        scores = weights * np.exp(np.dot(X, self.hazards_))

        diff_against = []

        schoenfeld_residuals = np.empty((0, d))

        # Iterate backwards to utilize recursive relationship
        for i in range(n - 1, -1, -1):
            # Doing it like this to preserve shape
            ti = T[i]
            ei = E[i]
            xi = X[i : i + 1]
            score = scores[i : i + 1]
            w = weights[i]

            # Calculate phi values
            phi_i = score
            phi_x_i = phi_i * xi

            # Calculate sums of Risk set
            risk_phi = risk_phi + phi_i
            risk_phi_x = risk_phi_x + phi_x_i

            # Calculate sums of Ties, if this is an event
            diff_against.append((xi, ei))
            if ei:

                tie_phi = tie_phi + phi_i
                tie_phi_x = tie_phi_x + phi_x_i

                # Keep track of count
                tie_count += 1  # aka death counts
                weight_count += w

            if i > 0 and T[i - 1] == ti:
                # There are more ties/members of the risk set
                continue
            elif tie_count == 0:
                for _ in diff_against:
                    schoenfeld_residuals = np.append(schoenfeld_residuals, np.zeros((1, d)), axis=0)
                diff_against = []
                continue

            # There was atleast one event and no more ties remain. Time to sum.
            weighted_mean = np.zeros((1, d))

            for l in range(tie_count):

                numer = risk_phi_x - l * tie_phi_x / tie_count
                denom = risk_phi - l * tie_phi / tie_count

                weighted_mean += numer / (denom * tie_count)

            for xi, ei in diff_against:
                schoenfeld_residuals = np.append(schoenfeld_residuals, ei * (xi - weighted_mean), axis=0)

            # reset tie values
            tie_count = 0
            weight_count = 0.0
            tie_phi = 0
            tie_phi_x = np.zeros((1, d))
            diff_against = []

        return schoenfeld_residuals[::-1]
370474
def _get_phi(self, imt, mag):
        
        phi = get_phi_ss(imt, mag, self.PHI_SS)
        if self.ergodic:
            C = self.PHI_S2SS[imt]
            phi = np.sqrt(phi ** 2. + C["phi_s2ss"] ** 2.)
        return phi
866581
def _prob_match(self, features):
        

        # compute the probabilities
        probs = self.kernel.predict_proba(features)

        # get the position of match probabilities
        classes = list(self.kernel.classes_)
        match_class_position = classes.index(1)

        return probs[:, match_class_position]
1033408
def compare(self, other, r_threshold=1e-3):
        
        return compute_rmsd(self.r, other.r) < r_threshold