Calculate DP (Discriminant power).

    :param TNR: specificity or true negative rate
    :type TNR : float
    :param TPR: sensitivity, recall, hit rate, or true positive rate
    :type TPR : float
    :return: DP as float
961111
def DP_calc(TPR, TNR):
    
    try:
        X = TPR / (1 - TPR)
        Y = TNR / (1 - TNR)
        return (math.sqrt(3) / math.pi) * (math.log(X, 10) + math.log(Y, 10))
    except Exception:
        return "None"
995101
def tdist_ci(x, df, stderr, level):
    
    q = (1 + level)/2
    delta = stats.t.ppf(q, df) * stderr
    return x - delta, x + delta
1285452
def _get_tpm_capability(self):
        
        tpm_values = {"NotPresent": False,
                      "PresentDisabled": True,
                      "PresentEnabled": True}
        try:
            tpm_state = self._get_bios_setting('TpmState')
        except exception.IloCommandNotSupportedError:
            tpm_state = "NotPresent"
        tpm_result = tpm_values[tpm_state]
        return tpm_result
372151
def _tl15(self, data, wavenumber):
        """"""

        return ((C2 * wavenumber) /
                xu.log((1.0 / data) * C1 * wavenumber ** 3 + 1.0))
291460
def _dD_dR(self, R):
        """"""
        HNn_R_sina = self._HNn / R / self._sin_alpha

        return HNn_R_sina * (0.3 * (HNn_R_sina + 0.3 * HNn_R_sina**2. + 1) / R / (0.3 * HNn_R_sina + 1)**2
                             - (1/R * (1 + 0.6 * HNn_R_sina) / (0.3 * HNn_R_sina + 1)))
512744
def _calculate_fnr_fdr(group):
    
    data = {k: d["value"] for k, d in group.set_index("metric").T.to_dict().items()}
    return pd.DataFrame([{"fnr": data["fn"] / float(data["tp"] + data["fn"]) * 100.0 if data["tp"] > 0 else 0.0,
                          "fdr": data["fp"] / float(data["tp"] + data["fp"]) * 100.0 if data["tp"] > 0 else 0.0,
                          "tpr": "TP: %s FN: %s" % (data["tp"], data["fn"]),
                          "spc": "FP: %s" % (data["fp"])}])
1345506
protected void bprop(int target) {
      assert (target != missing_int_value); // no correction of weights/biases for missing label
      float m = momentum();
      float r = _minfo.adaDelta() ? 0 : rate(_minfo.get_processed_total()) * (1f - m);
      float g; //partial derivative dE/dy * dy/dnet
      final float rows = _a.size();
      for( int row = 0; row < rows; row++ ) {
        final float t = (row == target ? 1f : 0f);
        final float y = _a.get(row);
        //dy/dnet = derivative of softmax = (1-y)*y
        if (params.loss == Loss.CrossEntropy) {
          //nothing else needed, -dCE/dy * dy/dnet = target - y
          //cf. http://www.stanford.edu/group/pdplab/pdphandbook/handbookch6.html
          g = t - y;
        } else {
          assert(params.loss == Loss.MeanSquare);
          //-dMSE/dy = target-y
          g = (t - y) * (1f - y) * y;
        }
        // this call expects dE/dnet
        bprop(row, g, r, m);
      }
    }
152245
def get_res(ds, t_srs=None, square=False):
    
    gt = ds.GetGeoTransform()
    ds_srs = get_ds_srs(ds)
    #This is Xres, Yres
    res = [gt[1], np.abs(gt[5])]
    if square:
        res = [np.mean(res), np.mean(res)]
    if t_srs is not None and not ds_srs.IsSame(t_srs):
        if True:
            #This diagonal approach is similar to the approach in gdaltransformer.cpp
            #Bad news for large extents near the poles
            #ullr = get_ullr(ds, t_srs)
            #diag = np.sqrt((ullr[0]-ullr[2])**2 + (ullr[1]-ullr[3])**2)
            extent = ds_extent(ds, t_srs)
            diag = np.sqrt((extent[2]-extent[0])**2 + (extent[3]-extent[1])**2)
            res = diag / np.sqrt(ds.RasterXSize**2 + ds.RasterYSize**2)
            res = [res, res]
        else:        
            #Compute from center pixel
            ct = osr.CoordinateTransformation(ds_srs, t_srs)
            pt = get_center(ds)
            #Transform center coordinates
            pt_ct = ct.TransformPoint(*pt)
            #Transform center + single pixel offset coordinates
            pt_ct_plus = ct.TransformPoint(pt[0] + gt[1], pt[1] + gt[5])
            #Compute resolution in new units 
            res = [pt_ct_plus[0] - pt_ct[0], np.abs(pt_ct_plus[1] - pt_ct[1])]
    return res
395812
def tpr(y, z):
    
    tp, tn, fp, fn = contingency_table(y, z)
    return tp / (tp + fn)
951337
def lnprior(x):
    """"""
    per, t0, b = x
    if b < -1 or b > 1:
        return -np.inf
    elif per < 7 or per > 10:
        return -np.inf
    elif t0 < 1978 or t0 > 1979:
        return -np.inf
    else:
        return 0.
1252324
def _nuclear_factor(self, Tp):
        
        sigmaRpp = 10 * np.pi * 1e-27
        sigmainel = self._sigma_inel(Tp)
        sigmainel0 = self._sigma_inel(1e3)  # at 1e3 GeV
        f = sigmainel / sigmainel0
        f2 = np.where(f > 1, f, 1.0)
        G = 1.0 + np.log(f2)
        # epsilon factors computed from Eqs 21 to 23 with local ISM abundances
        epsC = 1.37
        eps1 = 0.29
        eps2 = 0.1

        epstotal = np.where(
            Tp > self._Tth,
            epsC + (eps1 + eps2) * sigmaRpp * G / sigmainel,
            0.0,
        )

        if np.any(Tp < 1.0):
            # nuclear enhancement factor diverges towards Tp = Tth, fix Tp<1 to
            # eps(1.0) = 1.91
            loE = np.where((Tp > self._Tth) * (Tp < 1.0))
            epstotal[loE] = 1.9141

        return epstotal
1022972
def calc_signal_power(params, fname, transient=200, Df=None, mlab=True, NFFT=1000,
                      noverlap=0, window=plt.mlab.window_hanning):
    '''
    

    '''


    if type(fname) is str and os.path.isfile(fname):
        #open file
        f = h5py.File(fname)
        data = f['data'].value
        srate = f['srate'].value 
        tvec = np.arange(data.shape[1]) * 1000. / srate
        f.close()
    elif type(fname) is np.ndarray:
        data = fname
        srate = 1000.
        tvec = np.arange(data.shape[1]) * 1000. / srate
    else:
        raise Exception, '{} not a file or array'.format(fname)
    
    # slice
    slica = (tvec >= transient)
    data = data[:,slica]

    # subtract mean
    dataT = data.T - data.mean(axis=1)
    data = dataT.T
    
    #extract PSD
    PSD=[]
    for i in np.arange(len(params.electrodeParams['z'])):
        if mlab:
            Pxx, freqs=plt.mlab.psd(data[i], NFFT=NFFT,
                                    Fs=srate, noverlap=noverlap, window=window)
        else:
            [freqs, Pxx] = helpers.powerspec([data[i,]], tbin= 1.,
                                        Df=Df, pointProcess=False)
            mask = np.where(freqs >= 0.)
            freqs = freqs[mask]
            Pxx = Pxx.flatten()
            Pxx = Pxx[mask]
            Pxx = Pxx/tvec[tvec >= transient].size**2
        PSD +=[Pxx.flatten()]
        
    PSD=np.array(PSD)

    return freqs, PSD
1269876
def calc_nfalse(d):
    

    dtfactor = n.sum([1./i for i in d['dtarr']])    # assumes dedisperse-all algorithm
    ntrials = d['readints'] * dtfactor * len(d['dmarr']) * d['npixx'] * d['npixy']
    qfrac = 1 - (erf(d['sigma_image1']/n.sqrt(2)) + 1)/2.
    nfalse = int(qfrac*ntrials)
    return nfalse
1177807
def tlp_classifiers(self, name_tlp, val_tlp):
        '''
        
        '''

        classifier = {
            "WHITE": 0,
            "GREEN": 1,
            "AMBER": 2,
            "RED": 3
        }

        valid = True

        if classifier[name_tlp] > val_tlp:
            valid = False

        return valid
337088
def from_scale(cls, gold_number, precision, recall, title):
        
        tp_count = get_numerator(recall, gold_number)
        positive_count = get_denominator(precision, tp_count)
        fp_count = positive_count - tp_count
        fn_count = gold_number - tp_count
        scale_report = cls(['tp'] * tp_count,
                           ['fp'] * fp_count,
                           ['fn'] * fn_count,
                           title)
        return scale_report
451150
def mpr(truth, recommend):
    
    if len(recommend) == 0 and len(truth) == 0:
        return 0.  # best
    elif len(truth) == 0 or len(truth) == 0:
        return 100.  # worst

    accum = 0.
    n_recommend = recommend.size
    for t in truth:
        r = np.where(recommend == t)[0][0] / float(n_recommend)
        accum += r
    return accum * 100. / truth.size
104237
def true_neg_rate(self):
        
        false_pos = self.matrix[1][0]
        true_neg = self.matrix[1][1]
        return divide(1.0 * true_neg, true_neg + false_pos)