當前位置: 首頁>>代碼示例>>Python>>正文


Python cmath.e方法代碼示例

本文整理匯總了Python中cmath.e方法的典型用法代碼示例。如果您正苦於以下問題:Python cmath.e方法的具體用法?Python cmath.e怎麽用?Python cmath.e使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cmath的用法示例。


在下文中一共展示了cmath.e方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_constants

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import e [as 別名]
def test_constants(self):
        e_expected = 2.71828182845904523536
        pi_expected = 3.14159265358979323846
        self.assertAlmostEqual(cmath.pi, pi_expected, places=9,
            msg="cmath.pi is {}; should be {}".format(cmath.pi, pi_expected))
        self.assertAlmostEqual(cmath.e, e_expected, places=9,
            msg="cmath.e is {}; should be {}".format(cmath.e, e_expected)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_cmath.py

示例2: check_polar

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import e [as 別名]
def check_polar(self, func):
        def check(arg, expected):
            got = func(arg)
            for e, g in zip(expected, got):
                self.rAssertAlmostEqual(e, g)
        check(0, (0., 0.))
        check(1, (1., 0.))
        check(-1, (1., pi))
        check(1j, (1., pi / 2))
        check(-3j, (3., -pi / 2))
        inf = float('inf')
        check(complex(inf, 0), (inf, 0.))
        check(complex(-inf, 0), (inf, pi))
        check(complex(3, inf), (inf, pi / 2))
        check(complex(5, -inf), (inf, -pi / 2))
        check(complex(inf, inf), (inf, pi / 4))
        check(complex(inf, -inf), (inf, -pi / 4))
        check(complex(-inf, inf), (inf, 3 * pi / 4))
        check(complex(-inf, -inf), (inf, -3 * pi / 4))
        nan = float('nan')
        check(complex(nan, 0), (nan, nan))
        check(complex(0, nan), (nan, nan))
        check(complex(nan, nan), (nan, nan))
        check(complex(inf, nan), (inf, nan))
        check(complex(-inf, nan), (inf, nan))
        check(complex(nan, inf), (inf, nan))
        check(complex(nan, -inf), (inf, nan)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:29,代碼來源:test_cmath.py

示例3: computeBaseClassifierCoefficient

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import e [as 別名]
def computeBaseClassifierCoefficient(self, classifierIdx):
        '''
        輸入當前正在訓練的基分類器下標(從0開始),計算當前的基分類器係數 alpha 。
        :param classifierIdx: 當前分類器下標(從0開始)
        :return:
        '''
        self.alphaList[classifierIdx] = (1.0 / 2 * \
                                         cmath.log((1.0-self.eList[classifierIdx])/self.eList[classifierIdx], cmath.e)\
                                         ).real 
開發者ID:ysh329,項目名稱:statistical-learning-methods-note,代碼行數:11,代碼來源:AdaBoost.py

示例4: setPval

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import e [as 別名]
def setPval(self,p): self.p = p ### Typically re-set when a moderated statistic is calculated (e.g., emperical Bayesian - eBayes) 
開發者ID:nsalomonis,項目名稱:altanalyze,代碼行數:3,代碼來源:statistics.py

示例5: moderateTestStats

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import e [as 別名]
def moderateTestStats(pval_db,probability_statistic):
    """ Calculate a moderated variance for each biological comparison based, based on the average variance of all genes or molecules.
    This calculation should be identical for moderated student t-test p-values from the R package limma. Small variances might arrise
    from differences in the precision float values stored by the different languages and threshold from the Newton Iteration step. This
    implementation currently relies on first, second and third derivitive calculations (e.g., polygamma aka psi functions) from mpmath."""
    
    #tst = salstat_stats.TwoSampleTests([],[]) ### Create object with two empty lists - will analyze in object database afterwards
    #d0, s0_squared = tst.getModeratedStandardDeviation(pval_db)
    d0, s0_squared = getModeratedStandardDeviation(pval_db,probability_statistic)
    #print 'Prior degrees of freedom:',d0, 'and Prior s0 squared:',s0_squared
    #d0 = 2.054191
    #s0_squared = 0.01090202
    for uid in pval_db:
        gs = pval_db[uid]
        if 'Welch' in probability_statistic:
            ModeratedWelchTest(gs,d0, s0_squared)
        else:
            #tst.ModeratedTTestUnpaired(gs,d0, s0_squared)
            ModeratedTTestUnpaired(gs,d0,s0_squared)
        """
        if uid == '10367120':
            print gs.Avg1(), gs.Avg2(), gs.FeatureVariance(), math.sqrt(gs.FeatureVariance()), gs.AdjP()
            #gs.setFeatureVariance(math.sqrt(gs.FeatureVariance()))
            #tst.ModeratedTTestUnpaired(gs,d0, s0_squared)
            #print gs.Avg1(), gs.Avg2(), gs.FeatureVariance(), math.sqrt(gs.FeatureVariance()), gs.AdjP()
        """ 
開發者ID:nsalomonis,項目名稱:altanalyze,代碼行數:28,代碼來源:statistics.py

示例6: getModeratedStandardDeviation

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import e [as 別名]
def getModeratedStandardDeviation(comparison_db,probability_statistic):
    variance_ls=[]; e_sum=0; d0_2nd_moment_gene_sum = 0
    for uid in comparison_db:
        gs = comparison_db[uid] ### Object containing summary statistics needed for each uid (aka feature)
        if 'Welch' in probability_statistic:
            df = gs.DF()
        else:
            try: df = (gs.N1() + gs.N2()) - 2
            except Exception,e: print e, gs, [gs.N1(), gs.N2()];kill
        sg_squared = gs.FeatureVariance()
        #print uid, df, sg_squared;kill
        ###calculate s0 and d0
        if sg_squared > 1e-11:
            zg = math.log(sg_squared)
            eg = zg - psi(0,df/2.0) + math.log(df/2.0)
            variance_ls.append((eg,df))

    n = len(variance_ls) ### number of uids analyzed
    
    ### Get the mean eg for all IDs
    for (eg,df) in variance_ls:
        e_sum+=eg
        e_avg = e_sum/len(variance_ls)

    ### Calculate the d0 2nd derivitive that will later need to be solved for d0
    for (eg,df) in variance_ls:
        d0_2nd_moment_gene_sum += ((math.pow(eg-e_avg,2)*n)/(n-1)) - psi(1,df/2)
        
    d0_2nd_moment_solve = d0_2nd_moment_gene_sum/len(variance_ls)
    #print [d0_2nd_moment_solve]
    d0 = NewtonInteration(d0_2nd_moment_solve)*2
    #print [d0]
    d0 = float(d0)
    e = cm.e
    s0_squared = math.pow(e,e_avg+psi(0,d0/2) - math.log(d0/2))
    return d0, s0_squared 
開發者ID:nsalomonis,項目名稱:altanalyze,代碼行數:38,代碼來源:statistics.py

示例7: chisqprob

# 需要導入模塊: import cmath [as 別名]
# 或者: from cmath import e [as 別名]
def chisqprob(chisq,df):
    """
    Returns the (1-tailed) probability value associated with the provided
    chi-square value and df.  Adapted from chisq.c in Gary Perlman's |Stat.
    
    Usage:   chisqprob(chisq,df)
    """
    BIG = 20.0
    def ex(x):
	BIG = 20.0
	if x < -BIG:
	    return 0.0
	else:
	    return math.exp(x)

    if chisq <=0 or df < 1:
	return 1.0
    a = 0.5 * chisq
    if df%2 == 0:
	even = 1
    else:
	even = 0
    if df > 1:
	y = ex(-a)
    if even:
	s = y
    else:
	s = 2.0 * zprob(-math.sqrt(chisq))
    if (df > 2):
	chisq = 0.5 * (df - 1.0)
	if even:
	    z = 1.0
	else:
	    z = 0.5
	if a > BIG:
	    if even:
		e = 0.0
	    else:
		e = math.log(math.sqrt(math.pi))
	    c = math.log(a)
	    while (z <= chisq):
		e = math.log(z) + e
		s = s + ex(c*z-a-e)
		z = z + 1.0
	    return s
	else:
	    if even:
		e = 1.0
	    else:
		e = 1.0 / math.sqrt(math.pi) / math.sqrt(a)
		c = 0.0
		while (z <= chisq):
		    e = e * (a/float(z))
		    c = c + e
		    z = z + 1.0
		return (c*y+s)
    else:
	return s 
開發者ID:nsalomonis,項目名稱:altanalyze,代碼行數:60,代碼來源:salstat_stats.py


注:本文中的cmath.e方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。