本文整理汇总了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))
示例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))
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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)
示例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))
示例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
示例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