当前位置: 首页>>代码示例>>Python>>正文


Python math.log1p函数代码示例

本文整理汇总了Python中math.log1p函数的典型用法代码示例。如果您正苦于以下问题:Python log1p函数的具体用法?Python log1p怎么用?Python log1p使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了log1p函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_log1p

    def test_log1p(self):
        import math

        self.ftest(math.log1p(1 / math.e - 1), -1)
        self.ftest(math.log1p(0), 0)
        self.ftest(math.log1p(math.e - 1), 1)
        self.ftest(math.log1p(1), math.log(2))
开发者ID:GaussDing,项目名称:pypy,代码行数:7,代码来源:test_math.py

示例2: logadd

	def logadd(self, alpha):
		x = alpha[0]
		y = alpha[1]
		if y <= x:
			return x + math.log1p(math.exp(y-x))
		else:
			return y + math.log1p(math.exp(x-y))
开发者ID:cedrichu,项目名称:trigramHMM,代码行数:7,代码来源:hmm_trigram.py

示例3: testing

def testing(test_list, vocabulary, P1, P2, pp, np):
	result_value = []
	for test in test_list:
		test = test.split()
		
#		print test
		
		sum_of_pprob = 0
		sum_of_nprob = 0
		for word in test:
			if vocabulary.count(word):
				index = vocabulary.index(word)
				sum_of_pprob += math.log1p(pp[index])
				sum_of_nprob += math.log1p(np[index])

		positiveProbability = sum_of_pprob + math.log1p(P1)
		negativeProbability = sum_of_nprob + math.log1p(P2)
		
#		print positiveProbability
#		print negativeProbability
#		input('probability')

		if positiveProbability >= negativeProbability:
			result_value.append('+')
		else:
			result_value.append('-')
	return result_value
开发者ID:Mahe94,项目名称:NLP_Project,代码行数:27,代码来源:stage5.py

示例4: transition

def transition(dist, a, f, logspace=0):
    """
    Compute transition probabilities for a HMM. 
    
    to compute transition probabilities between hidden-states,
    when moving from time t to t+1,
    the genetic distance (cM) between the two markers are required.
    
    Assuming known parameters a and f.
    lf logspace = 1, calculations are log-transformed.
    
    Key in dictionary: 0 = not-IBD, 1 = IBD.
    """
    if logspace == 0:
        qk = exp(-a*dist)

        T = { # 0 = not-IBD, 1 = IBD
            1: {1: (1-qk)*f + qk, 0: (1-qk)*(1-f)},
            0: {1: (1-qk)*f, 0: (1-qk)*(1-f) + qk}
            }
        
    else:
        if dist == 0:
            dist = 1e-06

        ff = 1-f
        ad = a*dist
        A = expm1(ad)
        AA = -expm1(-ad)
        T = { # 0 = not-IBD, 1 = IBD
            1: {1: log1p(A*f)-ad, 0: log(AA*ff)},
            0: {1: log(AA*f), 0: log1p(A*ff)-ad}}
    return T
开发者ID:magnusdv,项目名称:filtus,代码行数:33,代码来源:AutEx.py

示例5: __log_add

 def __log_add(self, left, right):
     if (right < left):
         return left + math.log1p(math.exp(right - left))
     elif (right > left):
         return right + math.log1p(math.exp(left - right))
     else:
         return left + self.M_LN2
开发者ID:yrjie,项目名称:genomeBackup,代码行数:7,代码来源:hmm_gamma.py

示例6: log_sum

def log_sum(left,right):
	if right < left:
		return left + log1p(exp(right - left))
	elif left < right:
		return right + log1p(exp(left - right));
	else:
		return left + log1p(1)
开发者ID:adityamarella,项目名称:hiddenmarkovmodel,代码行数:7,代码来源:hmm.py

示例7: log_add

def log_add(left, right):
    if (right < left):
        return left + math.log1p(math.exp(right - left))
    elif (right > left):
        return right + math.log1p(math.exp(left - right))
    else:
        return left + M_LN2
开发者ID:Tell1,项目名称:ml-impl,代码行数:7,代码来源:test.py

示例8: my_features

def my_features(u, t):
    vector = []
    #vector += [float(edits_num(u, t, p)) for p in periods]
    vector += [math.log1p(user_lastedit[(u,t)]-user_frstedit[(u,t)])]
    vector += [math.log1p(numpy.reciprocal(numpy.mean(user_edit_freq[u])))] 
    #vector += [float(artis_num(u, t, p)) for p in periods]
    return vector
开发者ID:aniketalshi,项目名称:wikipediaprediciton,代码行数:7,代码来源:predictor.py

示例9: B

def B(x):
    y=None
    if math.sin(x/(x**2+2))+math.exp(math.log1p(x)+1)==0 or x==0:
        y='Neopredelen'
    else:
         y=(1/(math.sin(x/(x**2+2))+math.exp(math.log1p(x)+1)))-1
    return y
开发者ID:Brattelnik,项目名称:Borodulin,代码行数:7,代码来源:Math1.py

示例10: mandelbrot

def mandelbrot(n):
	z = complex(0,0)
	for i in range(max_iter):
		z = complex.add(complex.multiply(z,z),n)
		if cabs(z) >= escape_radius:
			smooth = i + 1 - int(math.log1p(math.log1p(cabs(z)))/math.log1p(escape_radius))
			return int(smooth)
	return True
开发者ID:Kerorogunso,项目名称:Mandelbrot,代码行数:8,代码来源:Mandelbrot.py

示例11: drift

def drift(active_editors_test, grouped_edits, time_train, time_test):
    """Calculate drift
    """
    average_train = sum([math.log1p(count_edits(grouped_edits[editor], time_train, 5))
                         for editor in active_editors_test])/len(active_editors_test)
    average_test = sum([math.log1p(count_edits(grouped_edits[editor], time_test, 5))
                        for editor in active_editors_test])/len(active_editors_test)
    return average_test - average_train
开发者ID:879229395,项目名称:wikichallenge,代码行数:8,代码来源:driver.py

示例12: test_log1p

 def test_log1p(self):
     import math
     self.ftest(math.log1p(1/math.e-1), -1)
     self.ftest(math.log1p(0), 0)
     self.ftest(math.log1p(math.e-1), 1)
     self.ftest(math.log1p(1), math.log(2))
     raises(ValueError, math.log1p, -1)
     raises(ValueError, math.log1p, -100)
开发者ID:Qointum,项目名称:pypy,代码行数:8,代码来源:test_math.py

示例13: logadd

def logadd(x, y):
    if y == 0:
        return x
    if x == 0:
        return y
    if y <= x:
        return x + math.log1p(math.exp(y - x))
    else:
        return y + math.log1p(math.exp(x - y))
开发者ID:asrivat1,项目名称:PartOfSpeechTagger,代码行数:9,代码来源:vtagem.py

示例14: geometric

def geometric(data, p):
    denom = math.log1p(-p)
    data.start_example(GEOMETRIC_LABEL)
    while True:
        probe = fractional_float(data)
        if probe < 1.0:
            result = int(math.log1p(-probe) / denom)
            assert result >= 0, (probe, p, result)
            data.stop_example()
            return result
开发者ID:Wilfred,项目名称:hypothesis-python,代码行数:10,代码来源:utils.py

示例15: __call__

 def __call__(self, response, a, result):
     text = get_text_from_html(a)
     this_features = defaultdict(float)
     norm = 0.0
     for token in parse_string(text, self.default_language):
         this_features[self.prefix + "__" + token] += 1.0
         norm += 1
     norm = log1p(norm)
     result.features.update((t, log1p(c) / norm) for t, c in this_features.viewitems())
     return result
开发者ID:windj007,项目名称:lcrawl,代码行数:10,代码来源:html.py


注:本文中的math.log1p函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。