Returns the tie correction value for U.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.tiecorrect.html
193297
def _tie_correct(sample):
    
    tc = 0
    n = sum(sample.values())

    if n < 2:
        return 1.0  # Avoid a ``ZeroDivisionError``.

    for k in sorted(sample.keys()):
        tc += math.pow(sample[k], 3) - sample[k]
    tc = 1 - tc / (math.pow(n, 3) - n)

    return tc
1027812
def get_comparable_values(self):
        
        return (int(self.order), str(self.label), str(self.name))
1068047
def tie_weights(self):
        
        # sampled softmax
        if self.sample_softmax > 0:
            if self.config.tie_weight:
                self.out_layer.weight = self.transformer.word_emb.weight
        # adaptive softmax (including standard softmax)
        else:
            if self.config.tie_weight:
                for i in range(len(self.crit.out_layers)):
                    self.crit.out_layers[i].weight = self.transformer.word_emb.emb_layers[i].weight
            if self.config.tie_projs:
                for i, tie_proj in enumerate(self.config.tie_projs):
                    if tie_proj and self.config.div_val == 1 and self.config.d_model != self.config.d_embed:
                        self.crit.out_projs[i] = self.transformer.word_emb.emb_projs[0]
                    elif tie_proj and self.config.div_val != 1:
                        self.crit.out_projs[i] = self.transformer.word_emb.emb_projs[i]
689491
def _apply_adjustments(COEFFS, C_ADJ, tau_ss, mean, stddevs, sites, rup, dists,
                       imt, stddev_types, log_phi_ss, NL=None, tau_value=None):
    
    c1_dists = _compute_C1_term(C_ADJ, dists)
    phi_ss = _compute_phi_ss(
        C_ADJ, rup.mag, c1_dists, log_phi_ss, C_ADJ['mean_phi_ss']
    )

    mean_corr = np.exp(mean) * C_ADJ['k_adj'] * \
        _compute_small_mag_correction_term(C_ADJ, rup.mag, dists)

    mean_corr = np.log(mean_corr)

    std_corr = _get_corr_stddevs(COEFFS[imt], tau_ss, stddev_types,
                                 len(sites.vs30), phi_ss, NL, tau_value)

    stddevs = np.array(std_corr)

    return mean_corr, stddevs
1297758
def _u_centered_imp(a, out=None):
    
    out = _float_copy_to_out(out, a)

    dim = np.size(a, 0)

    u_mu = np.sum(a) / ((dim - 1) * (dim - 2))
    sum_cols = np.sum(a, 0, keepdims=True)
    sum_rows = np.sum(a, 1, keepdims=True)
    u_mu_cols = np.ones((dim, 1)).dot(sum_cols / (dim - 2))
    u_mu_rows = (sum_rows / (dim - 2)).dot(np.ones((1, dim)))

    # Do one operation at a time, to improve broadcasting memory usage.
    out -= u_mu_rows
    out -= u_mu_cols
    out += u_mu

    # The diagonal is zero
    out[np.eye(dim, dtype=bool)] = 0

    return out
1266311
def _compute_distance_term(self, C, mag, rrup):
        
        term1 = C['b'] * rrup
        term2 = - np.log(rrup + C['c'] * np.exp(C['d'] * mag))

        return term1 + term2
558411
def get_conversion_factor(self, new_unit):
        
        uo_base, ofactor = self.as_base_units
        un_base, nfactor = Unit(new_unit).as_base_units
        units_new = sorted(un_base.items(),
                           key=lambda d: _UNAME2UTYPE[d[0]])
        units_old = sorted(uo_base.items(),
                           key=lambda d: _UNAME2UTYPE[d[0]])
        factor = ofactor / nfactor
        for uo, un in zip(units_old, units_new):
            if uo[1] != un[1]:
                raise UnitError("Units %s and %s are not compatible!" % (uo, un))
            c = ALL_UNITS[_UNAME2UTYPE[uo[0]]]
            factor *= (c[uo[0]] / c[un[0]]) ** uo[1]
        return factor
994419
def get_anchor(self):
        """"""
        temp = np.empty([self.n_nodes, 2])
        temp[:, 0] = np.arange(self.n_nodes, dtype=int)
        temp[:, 1] = np.sum(abs(self.tau_matrix), 1)
        anchor = int(temp[0, 0])
        return anchor
923704
def npar_adj(self):
        
        pass
        np = 0
        for t in self.parameter_data.partrans:
            if t not in ["fixed", "tied"]:
                np += 1
        return np
143223
def percent_point(self, U):
        
        self.check_fit()

        return scipy.optimize.brentq(self._brentq_cdf(U), -1000.0, 1000.0)
1054497
def r2_score(pred:Tensor, targ:Tensor)->Rank0Tensor:
    ""
    pred,targ = flatten_check(pred,targ)
    u = torch.sum((targ - pred) ** 2)
    d = torch.sum((targ - targ.mean()) ** 2)
    return 1 - u / d
165255
def _get_triplet_value(self, graph, identity, rdf_type):
        
        value = graph.value(subject=identity, predicate=rdf_type)
        return value.toPython() if value is not None else value
585164
def rerank
      tie_break_methods, tie_break_order, tie_break_hash = tie_break_data
      @player.values.sort do |a,b|
        cmp = 0
        tie_break_methods.each do |m|
          cmp = (tie_break_hash[m][a.num] <=> tie_break_hash[m][b.num]) * tie_break_order[m] if cmp == 0
        end
        cmp
      end.each_with_index do |p,i|
        p.rank = i + 1
      end
      self
    end
663564
def _get_bcpOut(self):
        
        nextSegment = self._nextSegment
        offCurves = nextSegment.offCurve
        if offCurves:
            bcp = offCurves[0]
            x, y = relativeBCPOut(self.anchor, (bcp.x, bcp.y))
        else:
            x = y = 0
        return (x, y)
76230
def Get_RpRs(d, **kwargs):
    '''
    

    '''
    if ps is None:
            raise Exception("Unable to import `pysyzygy`.")

    def Depth(RpRs, **kwargs):
        return 1 - ps.Transit(RpRs=RpRs, **kwargs)([kwargs.get('t0', 0.)])

    def DiffSq(r):
        return 1.e10 * (d - Depth(r, **kwargs)) ** 2

    return fmin(DiffSq, [np.sqrt(d)], disp=False)
735927
def U(self):
        
        if self._U is None:
            sinv = N.diag(1/self.singular_values)
            self._U = dot(self.arr,self.V.T,sinv)
        return self._U
239100
def U(self):
        
        u = self.call("U")
        if u is not None:
            mat_name = u.getClass().getSimpleName()
            if mat_name == "RowMatrix":
                return RowMatrix(u)
            elif mat_name == "IndexedRowMatrix":
                return IndexedRowMatrix(u)
            else:
                raise TypeError("Expected RowMatrix/IndexedRowMatrix got %s" % mat_name)