本文整理汇总了Python中numpy.logaddexp2函数的典型用法代码示例。如果您正苦于以下问题:Python logaddexp2函数的具体用法?Python logaddexp2怎么用?Python logaddexp2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了logaddexp2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_nan
def test_nan(self):
err = np.seterr(invalid="ignore")
try:
assert np.isnan(np.logaddexp2(np.nan, np.inf))
assert np.isnan(np.logaddexp2(np.inf, np.nan))
assert np.isnan(np.logaddexp2(np.nan, 0))
assert np.isnan(np.logaddexp2(0, np.nan))
assert np.isnan(np.logaddexp2(np.nan, np.nan))
finally:
np.seterr(**err)
开发者ID:8cH9azbsFifZ,项目名称:wspr,代码行数:10,代码来源:test_umath.py
示例2: _nllx
def _nllx(xi, i):
ll = 0.0
zi[0] = sum(xi ** 2.0)
zi[1 : k + 1] = xi
for j in range(l):
gij = snp_matrix[i, j]
if gij == geosnp.MISSING:
continue
qnf = zi.T.dot(Y[j])
r = numpy.logaddexp2(-qnf, 0)
r2 = numpy.logaddexp2(qnf, 0)
ll -= (gij * r) + ((2.0 - gij) * (r2))
# return NLL in order to minimize
return -ll
开发者ID:quattro,项目名称:geosnp,代码行数:15,代码来源:estimation.py
示例3: _nlly
def _nlly(yj, j):
ll = 0.0
q, a, b = yj[0], yj[1 : k + 1], yj[-1]
for i in range(n):
gij = snp_matrix[i, j]
if gij == geosnp.MISSING:
continue
xi = X[i]
qnf = (q * sum(xi ** 2.0)) + a.dot(xi) + b
r = numpy.logaddexp2(-qnf, 0)
r2 = numpy.logaddexp2(qnf, 0)
ll -= (gij * r) + ((2.0 - gij) * (r2))
# return NLL in order to minimize
return -ll
开发者ID:quattro,项目名称:geosnp,代码行数:15,代码来源:estimation.py
示例4: _increment_by_frecency
def _increment_by_frecency(self, frecency_added, multiplier=1.):
"""Increment this frecency by another frecency, with optional multiplier.
NOTE: No attempt is made here to handle differing timescales or other parameters.
"""
log2_multiplier = log2(multiplier)
log2_weight_added = frecency_added.log2_value + log2_multiplier
self.log2_value = logaddexp2(self.log2_value, log2_weight_added)
开发者ID:mokelly,项目名称:frecency,代码行数:7,代码来源:frecency.py
示例5: add
def add(self, x, y):
# Convert log_b probabilities to log_2 probabilities.
x2 = x * np.log2(base)
y2 = y * np.log2(base)
z = np.logaddexp2(x2, y2)
# Convert log_2 probabilities to log_b probabilities.
z *= self.log(2)
return z
开发者ID:chebee7i,项目名称:dit,代码行数:8,代码来源:ops.py
示例6: _baum_welch_step
def _baum_welch_step(self, sequence, model, symbol_to_number):
N = len(model._states)
M = len(model._symbols)
T = len(sequence)
# compute forward and backward probabilities
alpha = model._forward_probability(sequence)
beta = model._backward_probability(sequence)
# find the log probability of the sequence
lpk = logsumexp2(alpha[T - 1])
A_numer = _ninf_array((N, N))
B_numer = _ninf_array((N, M))
A_denom = _ninf_array(N)
B_denom = _ninf_array(N)
transitions_logprob = model._transitions_matrix().T
for t in range(T):
symbol = sequence[t][_TEXT] # not found? FIXME
next_symbol = None
if t < T - 1:
next_symbol = sequence[t + 1][_TEXT] # not found? FIXME
xi = symbol_to_number[symbol]
next_outputs_logprob = model._outputs_vector(next_symbol)
alpha_plus_beta = alpha[t] + beta[t]
if t < T - 1:
numer_add = (
transitions_logprob
+ next_outputs_logprob
+ beta[t + 1]
+ alpha[t].reshape(N, 1)
)
A_numer = np.logaddexp2(A_numer, numer_add)
A_denom = np.logaddexp2(A_denom, alpha_plus_beta)
else:
B_denom = np.logaddexp2(A_denom, alpha_plus_beta)
B_numer[:, xi] = np.logaddexp2(B_numer[:, xi], alpha_plus_beta)
return lpk, A_numer, A_denom, B_numer, B_denom
开发者ID:prz3m,项目名称:kind2anki,代码行数:45,代码来源:hmm.py
示例7: test_logaddexp2_range
def test_logaddexp2_range(self):
x = [1000000, -1000000, 1000200, -1000200]
y = [1000200, -1000200, 1000000, -1000000]
z = [1000200, -1000000, 1000200, -1000000]
for dt in ["f", "d", "g"]:
logxf = np.array(x, dtype=dt)
logyf = np.array(y, dtype=dt)
logzf = np.array(z, dtype=dt)
assert_almost_equal(np.logaddexp2(logxf, logyf), logzf)
开发者ID:jarrodmillman,项目名称:numpy,代码行数:9,代码来源:test_umath.py
示例8: test_logaddexp2_values
def test_logaddexp2_values(self):
x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]
z = [6, 6, 6, 6, 6]
for dt, dec in zip(["f", "d", "g"], [6, 15, 15]):
xf = np.log2(np.array(x, dtype=dt))
yf = np.log2(np.array(y, dtype=dt))
zf = np.log2(np.array(z, dtype=dt))
assert_almost_equal(np.logaddexp2(xf, yf), zf, decimal=dec)
开发者ID:jarrodmillman,项目名称:numpy,代码行数:9,代码来源:test_umath.py
示例9: misc_floating
def misc_floating(mod, x):
"miscellaneous"
# y0 = math.erfc(x)
y1 = math.atan2(x, x)
y2 = np.arctan2(x, x)
y3 = np.logaddexp(x, x)
y4 = np.logaddexp2(x, x)
return (y1, y2, y3, y4) #(y0, y1)
开发者ID:ejmvar,项目名称:numba,代码行数:9,代码来源:test_allmath.py
示例10: test_inf
def test_inf(self):
inf = np.inf
x = [inf, -inf, inf, -inf, inf, 1, -inf, 1]
y = [inf, inf, -inf, -inf, 1, inf, 1, -inf]
z = [inf, inf, inf, -inf, inf, inf, 1, 1]
for dt in ["f", "d", "g"]:
logxf = np.array(x, dtype=dt)
logyf = np.array(y, dtype=dt)
logzf = np.array(z, dtype=dt)
assert_equal(np.logaddexp2(logxf, logyf), logzf)
开发者ID:kidaa,项目名称:Neuroimaging,代码行数:10,代码来源:test_umath.py
示例11: increment
def increment(self, value_added=1., event_time=None):
"""
Increment frecency, with value_added weighted according to time of observation.
* *value_added* is the number or weight of current events to add to the Frecency counter. (e.g., 1 for one view)
* *event_time* can be used to set the time at which the new value was added; otherwise, the present time is used.
"""
if not event_time:
event_time = time.time()
log2_weight_added = (event_time - self.time0) / self.timescale + log2(value_added)
self.log2_value = logaddexp2(self.log2_value, log2_weight_added) # All calculations in log2 space to avoid overflow
开发者ID:mokelly,项目名称:frecency,代码行数:11,代码来源:frecency.py
示例12: test_inf
def test_inf(self) :
inf = np.inf
x = [inf, -inf, inf, -inf, inf, 1, -inf, 1]
y = [inf, inf, -inf, -inf, 1, inf, 1, -inf]
z = [inf, inf, inf, -inf, inf, inf, 1, 1]
with np.errstate(invalid='ignore'):
for dt in ['f', 'd', 'g'] :
logxf = np.array(x, dtype=dt)
logyf = np.array(y, dtype=dt)
logzf = np.array(z, dtype=dt)
assert_equal(np.logaddexp2(logxf, logyf), logzf)
开发者ID:Fematich,项目名称:article_browser,代码行数:11,代码来源:test_umath.py
示例13: test_inf
def test_inf(self):
err = np.seterr(invalid="ignore")
inf = np.inf
x = [inf, -inf, inf, -inf, inf, 1, -inf, 1]
y = [inf, inf, -inf, -inf, 1, inf, 1, -inf]
z = [inf, inf, inf, -inf, inf, inf, 1, 1]
try:
for dt in ["f", "d", "g"]:
logxf = np.array(x, dtype=dt)
logyf = np.array(y, dtype=dt)
logzf = np.array(z, dtype=dt)
assert_equal(np.logaddexp2(logxf, logyf), logzf)
finally:
np.seterr(**err)
开发者ID:jarrodmillman,项目名称:numpy,代码行数:14,代码来源:test_umath.py
示例14: add_inplace
def add_inplace(self, x, y):
x *= np.log2(base)
y2 = y * np.log2(base)
np.logaddexp2(x, y2, x)
x *= self.log(2)
return x
开发者ID:chebee7i,项目名称:dit,代码行数:6,代码来源:ops.py
示例15: test_logaddexp2
def test_logaddexp2(self):
import math
import sys
float_max, float_min = sys.float_info.max, sys.float_info.min
from numpy import logaddexp2
log2 = math.log(2)
# From the numpy documentation
prob1 = math.log(1e-50) / log2
prob2 = math.log(2.5e-50) / log2
prob12 = logaddexp2(prob1, prob2)
assert math.fabs(-164.28904982231052 - prob12) < 0.000000000001
assert logaddexp2(0, 0) == 1
assert logaddexp2(float("-inf"), 0) == 0
assert logaddexp2(float_max, float_max) == float_max
assert logaddexp2(float_min, float_min) == 1.0
assert math.isnan(logaddexp2(float("nan"), 1))
assert math.isnan(logaddexp2(1, float("nan")))
assert math.isnan(logaddexp2(float("nan"), float("inf")))
assert math.isnan(logaddexp2(float("inf"), float("nan")))
assert logaddexp2(float("-inf"), float("-inf")) == float("-inf")
assert logaddexp2(float("-inf"), float("inf")) == float("inf")
assert logaddexp2(float("inf"), float("-inf")) == float("inf")
assert logaddexp2(float("inf"), float("inf")) == float("inf")
开发者ID:Qointum,项目名称:pypy,代码行数:28,代码来源:test_ufuncs.py
示例16: test_logaddexp2_float32_float64_mat
def test_logaddexp2_float32_float64_mat():
expect(np.logaddexp2, [float32_mat, float64_mat], np.logaddexp2(float32_mat,float64_mat))
开发者ID:Abramovuch,项目名称:parakeet,代码行数:2,代码来源:test_logaddexp2.py
示例17: test_logaddexp2_float32_float64_vec
def test_logaddexp2_float32_float64_vec():
expect(np.logaddexp2, [float32_vec, float64_vec], np.logaddexp2(float32_vec,float64_vec))
开发者ID:Abramovuch,项目名称:parakeet,代码行数:2,代码来源:test_logaddexp2.py
示例18: logaddexp2_usecase
def logaddexp2_usecase(x, y, result):
np.logaddexp2(x, y, result)
开发者ID:aburan28,项目名称:numba,代码行数:2,代码来源:test_ufuncs.py
示例19: test_logaddexp2_bool_bool_mat
def test_logaddexp2_bool_bool_mat():
expect(np.logaddexp2, [bool_mat, bool_mat], np.logaddexp2(bool_mat,bool_mat))
开发者ID:Abramovuch,项目名称:parakeet,代码行数:2,代码来源:test_logaddexp2.py
示例20: test_logaddexp2_bool_bool_vec
def test_logaddexp2_bool_bool_vec():
expect(np.logaddexp2, [bool_vec, bool_vec], np.logaddexp2(bool_vec,bool_vec))
开发者ID:Abramovuch,项目名称:parakeet,代码行数:2,代码来源:test_logaddexp2.py
注:本文中的numpy.logaddexp2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论