Analysis kappa number with Landis-Koch benchmark.

    :param kappa: kappa number
    :type kappa : float
    :return: strength of agreement as str
320818
def kappa_analysis_koch(kappa):
    
    try:
        if kappa < 0:
            return "Poor"
        if kappa >= 0 and kappa < 0.2:
            return "Slight"
        if kappa >= 0.20 and kappa < 0.4:
            return "Fair"
        if kappa >= 0.40 and kappa < 0.6:
            return "Moderate"
        if kappa >= 0.60 and kappa < 0.8:
            return "Substantial"
        if kappa >= 0.80 and kappa <= 1:
            return "Almost Perfect"
        return "None"
    except Exception:  # pragma: no cover
        return "None"
232231
def _dist_kw_arg(self, k):
        
        if self._dist_kw_args is not None:
            return {
                key:self._dist_kw_args[key][k,:]
                for key in self._dist_kw_args.keys()
            }
        else:
            return {}
567485
def _ttr(self, k, dist, cache):
        """"""
        a,b = evaluation.evaluate_recurrence_coefficients(dist, k)
        return -a, b
826378
def _vmf_normalize(kappa, dim):
    
    num = np.power(kappa, dim / 2. - 1.)

    if dim / 2. - 1. < 1e-15:
        denom = np.power(2. * np.pi, dim / 2.) * i0(kappa)
    else:
        denom = np.power(2. * np.pi, dim / 2.) * iv(dim / 2. - 1., kappa)

    if np.isinf(num):
        raise ValueError("VMF scaling numerator was inf.")

    if np.isinf(denom):
        raise ValueError("VMF scaling denominator was inf.")

    if np.abs(denom) < 1e-15:
        raise ValueError("VMF scaling denominator was 0.")

    return num / denom
857727
def factor_kkt(S_LU, R, d):
    
    nBatch, nineq = d.size()
    neq = S_LU[1].size(1) - nineq
    # TODO: There's probably a better way to add a batched diagonal.
    global factor_kkt_eye
    if factor_kkt_eye is None or factor_kkt_eye.size() != d.size():
        # print('Updating batchedEye size.')
        factor_kkt_eye = torch.eye(nineq).repeat(
            nBatch, 1, 1).type_as(R).byte()
    T = R.clone()
    T[factor_kkt_eye] += (1. / d).squeeze().view(-1)

    T_LU = btrifact_hack(T)

    global shown_btrifact_warning
    if shown_btrifact_warning or not T.is_cuda:
        # TODO: Don't use pivoting in most cases because
        # torch.btriunpack is inefficient here:
        oldPivotsPacked = S_LU[1][:, -nineq:] - neq
        oldPivots, _, _ = torch.btriunpack(
            T_LU[0], oldPivotsPacked, unpack_data=False)
        newPivotsPacked = T_LU[1]
        newPivots, _, _ = torch.btriunpack(
            T_LU[0], newPivotsPacked, unpack_data=False)

        # Re-pivot the S_LU_21 block.
        if neq > 0:
            S_LU_21 = S_LU[0][:, -nineq:, :neq]
            S_LU[0][:, -nineq:,
                    :neq] = newPivots.transpose(1, 2).bmm(oldPivots.bmm(S_LU_21))

        # Add the new S_LU_22 block pivots.
        S_LU[1][:, -nineq:] = newPivotsPacked + neq

    # Add the new S_LU_22 block.
    S_LU[0][:, -nineq:, -nineq:] = T_LU[0]
908668
def K(self):
        
        K = np.eye(3, dtype=np.float64)
        K[0, 0] = self.focal[0]
        K[1, 1] = self.focal[1]
        K[0, 2] = self.resolution[0] / 2.0
        K[1, 2] = self.resolution[1] / 2.0
        return K
1223736
def _score_clusters(self, X, y=None):
        
        stype = self.scoring.lower() # scoring method name

        if stype == "membership":
            return np.bincount(self.estimator.labels_)

        raise YellowbrickValueError("unknown scoring method '{}'".format(stype))
318569
def effective_einstein_radius(self, kwargs_lens_list, k=None, spacing=1000):
        
        if 'center_x' in kwargs_lens_list[0]:
            center_x = kwargs_lens_list[0]['center_x']
            center_y = kwargs_lens_list[0]['center_y']
        elif self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']:
            center_x, center_y = 0, 0
        else:
            center_x, center_y = 0, 0
        numPix = 200
        deltaPix = 0.05
        x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix)
        x_grid += center_x
        y_grid += center_y
        kappa = self._lensModel.kappa(x_grid, y_grid, kwargs_lens_list, k=k)
        if self._lensModel.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']:
            center_x = x_grid[kappa == np.max(kappa)]
            center_y = y_grid[kappa == np.max(kappa)]
        kappa = util.array2image(kappa)
        r_array = np.linspace(0.0001, numPix*deltaPix/2., spacing)
        for r in r_array:
            mask = np.array(1 - mask_util.mask_center_2d(center_x, center_y, r, x_grid, y_grid))
            sum_mask = np.sum(mask)
            if sum_mask > 0:
                kappa_mean = np.sum(kappa*mask)/np.sum(mask)
                if kappa_mean < 1:
                    return r
        print(kwargs_lens_list, "Warning, no Einstein radius computed!")
        return r_array[-1]
885460
def get_signature_size(msg):
    
    if isinstance(msg, (TxinGen, TxinToScript, TxinToScriptHash)):
        return 0
    elif isinstance(msg, TxinToKey):
        return len(msg.key_offsets)
    else:
        raise ValueError('Unknown tx in')
210545
def maryland_values(self):
        
        pas=self.principal_axis_system
        sigma_iso=pas.trace() / 3
        omega=np.diag(pas)[2] - np.diag(pas)[0]
        # There is a typo in equation 20 from Magn. Reson. Chem. 2008, 46, 582–598, the sign is wrong.
        # There correct order is presented in Solid State Nucl. Magn. Reson. 1993, 2, 285-288.
        kappa=3.0 * (np.diag(pas)[1] - sigma_iso) / omega
        return self.MarylandNotation(sigma_iso, omega, kappa)
219995
def _human_score_map(human_consensus, methods_attrs):
    

    v = 1 - min(np.sum(np.abs(methods_attrs - human_consensus)) / (np.abs(human_consensus).sum() + 1), 1.0)
    return v
741590
def Kdiag(self, X):
        """"""
        K_ff = np.ones(X.shape[0])
        for i,x in enumerate(X):
            for il,l in enumerate(self.lengthscale):
                idx = il*2
                K_ff[i] *= self.k_ff(x[idx],x[idx],l)
        return K_ff * self.variances[0]
997329
def estimateAbsoluteMagnitude(spectralType):
    

    from .astroclasses import SpectralType

    specType = SpectralType(spectralType)

    if specType.classLetter == '':
        return np.nan
    elif specType.classNumber == '':
        specType.classNumber = 5  # approximation using mid magnitude value

    if specType.lumType == '':
        specType.lumType = 'V'  # assume main sequence

    LNum = LClassRef[specType.lumType]
    classNum = specType.classNumber
    classLet = specType.classLetter

    try:
        return absMagDict[classLet][classNum][LNum]
    # value not in table. Assume the number isn't there (Key p2.7, Ind p3+)
    except (KeyError, IndexError):
        try:
            classLookup = absMagDict[classLet]
            values = np.array(list(classLookup.values()))[
                :, LNum]  # only select the right L Type
            return np.interp(classNum, list(classLookup.keys()), values)
        except (KeyError, ValueError):
            return np.nan
934201
def acor(self, k = 5):
        
        try:
            import acor
        except ImportError:
            print("Can't import acor, please download it.")
            return 0
        n = np.shape(self._chain)[1]
        t = np.zeros(n)
        for i in xrange(n):
            t[i] = acor.acor(self._chain[:,i],k)[0]
        return t
1216847
def _prepare_kappa(model):
    """"""
    import kappy
    kappa = kappy.KappaStd()
    model_str = export(model, 'kappa')
    kappa.add_model_string(model_str)
    kappa.project_parse()
    return kappa
883182
def sample_vMF(mu, kappa, num_samples):
    
    dim = len(mu)
    result = np.zeros((num_samples, dim))
    for nn in range(num_samples):
        # sample offset from center (on sphere) with spread kappa
        w = _sample_weight(kappa, dim)

        # sample a point v on the unit sphere that's orthogonal to mu
        v = _sample_orthonormal_to(mu)

        # compute new point
        result[nn, :] = v * np.sqrt(1. - w ** 2) + w * mu

    return result
360029
def _score_for_model(meta):
    
    mean_acc = list()
    pipes = meta["pipeline"]
    acc = meta["accuracy"]
    if "tagger" in pipes:
        mean_acc.append(acc["tags_acc"])
    if "parser" in pipes:
        mean_acc.append((acc["uas"] + acc["las"]) / 2)
    if "ner" in pipes:
        mean_acc.append((acc["ents_p"] + acc["ents_r"] + acc["ents_f"]) / 3)
    return sum(mean_acc) / len(mean_acc)