本文整理汇总了Python中numpy.expm1方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.expm1方法的具体用法?Python numpy.expm1怎么用?Python numpy.expm1使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.expm1方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_burkardt_3
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def test_burkardt_3(self):
# This example is due to Laub.
# This matrix is ill-suited for the Taylor series approach.
# As powers of A are computed, the entries blow up too quickly.
exp1 = np.exp(1)
exp39 = np.exp(39)
A = np.array([
[0, 1],
[-39, -40],
], dtype=float)
desired = np.array([
[
39/(38*exp1) - 1/(38*exp39),
-np.expm1(-38) / (38*exp1)],
[
39*np.expm1(-38) / (38*exp1),
-1/(38*exp1) + 39/(38*exp39)],
], dtype=float)
actual = expm(A)
assert_allclose(actual, desired)
示例2: ipsi
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def ipsi(self, u, log=False):
r = np.asarray(u) * self.params
res = np.copy(r)
res[np.isnan(r)] = np.nan
em = np.expm1(-self.params)
# for small inputs, u <= 0.01
small_mask = np.abs(r) <= 0.01 * abs(self.params)
res[small_mask] = -np.log(np.expm1(-r[small_mask]) / em)
big_mask = np.abs(r) > 0.01 * abs(self.params)
e = np.exp(-self.params)
mid_mask = (e > 0) & (np.abs(self.params - r) < 0.5) # theta * (1 - u) < 0.5
m1 = big_mask & mid_mask
m2 = big_mask & ~mid_mask
r[m1] = -np.log1p(e * np.expm1((self.params - r[m1])) / em)
r[m2] = -np.log1p((np.exp(-r[m2]) - e) / em)
return np.log(r) if log else r
示例3: random
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def random(self, n: int, seed: int = None):
u = random_uniform(n, self.dim, seed)
if abs(self.params) < 1e-7:
return u
if self.dim == 2:
v = u[:, 1]
a = -abs(self.params)
v = -1 / a * np.log1p(-v * np.expm1(-a) / (np.exp(-a * u[:, 0]) * (v - 1) - v))
u[:, 1] = 1 - v if self.params > 0 else v
return u
# alpha too large
if log1mexp(self.params) == 0:
return np.ones((n, self.dim))
fr = random_log_series_ln1p(-self.params, n)[:, None]
return self.psi(-np.log(u) / fr)
示例4: _gpinv
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def _gpinv(probs, kappa, sigma):
"""Inverse Generalized Pareto distribution function."""
# pylint: disable=unsupported-assignment-operation, invalid-unary-operand-type
x = np.full_like(probs, np.nan)
if sigma <= 0:
return x
ok = (probs > 0) & (probs < 1)
if np.all(ok):
if np.abs(kappa) < np.finfo(float).eps:
x = -np.log1p(-probs)
else:
x = np.expm1(-kappa * np.log1p(-probs)) / kappa
x *= sigma
else:
if np.abs(kappa) < np.finfo(float).eps:
x[ok] = -np.log1p(-probs[ok])
else:
x[ok] = np.expm1(-kappa * np.log1p(-probs[ok])) / kappa
x *= sigma
x[probs == 0] = 0
if kappa >= 0:
x[probs == 1] = np.inf
else:
x[probs == 1] = -sigma / kappa
return x
示例5: _test
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def _test(vectorizer, model, n_rows):
tr = load_train('tests/train_10k.tsv')
tr, va = train_test_split(tr)
te = pd.read_csv('tests/test_10k_corrupted.tsv', sep="\t")
if n_rows is not None:
if n_rows == 'random':
n_rows = np.random.randint(1, te.shape[0])
te = te.sample(n=n_rows)
mat_tr = vectorizer.fit_transform(tr, tr.price)
mat_te = vectorizer.transform(te.copy())
mat_va = vectorizer.transform(va)
model.fit(mat_tr, np.log1p(tr.price))
assert rmsle(np.expm1(model.predict(mat_va)), va.price) < 0.85
te_preds = np.expm1(model.predict(mat_te))
assert te_preds.shape[0] == te.shape[0]
assert np.all(np.isfinite(te_preds))
assert te_preds.min() >= -1, "min price is {}".format(te_preds.min())
assert te_preds.max() <= 3000, "max price is {}".format(te_preds.max())
示例6: bdtrc
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def bdtrc(k, n, p):
if (k < 0):
return (1.0)
if (k == n):
return (0.0)
dn = n - k
if (k == 0):
if (p < .01):
dk = -np.expm1(dn * np.log1p(-p))
else:
dk = 1.0 - np.exp(dn * np.log(1.0 - p))
else:
dk = k + 1
dk = betainc(dk, dn, p)
return dk
示例7: finv
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def finv(self, f):
return np.where(f>_lim_val, f, np.log(np.expm1(f)))
示例8: gradfactor
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def gradfactor(self, f, df):
return df*np.where(f>_lim_val, 1., - np.expm1(-f))
示例9: log_jacobian
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def log_jacobian(self, model_param):
return np.where(model_param>_lim_val, model_param, np.log(np.expm1(model_param))) - model_param
示例10: log_jacobian_grad
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def log_jacobian_grad(self, model_param):
return 1./(np.expm1(model_param))
示例11: _cdf
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def _cdf(self, x, p):
k = floor(x)
return -expm1(log1p(-p)*k)
示例12: _stats
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def _stats(self, lambda_):
mu = 1/(exp(lambda_)-1)
var = exp(-lambda_)/(expm1(-lambda_))**2
g1 = 2*cosh(lambda_/2.0)
g2 = 4+2*cosh(lambda_)
return mu, var, g1, g2
示例13: test_numpy_method
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def test_numpy_method():
# This type of code is used frequently by PyMC3 users
x = tt.dmatrix('x')
data = np.random.rand(5, 5)
x.tag.test_value = data
for fct in [np.arccos, np.arccosh, np.arcsin, np.arcsinh,
np.arctan, np.arctanh, np.ceil, np.cos, np.cosh, np.deg2rad,
np.exp, np.exp2, np.expm1, np.floor, np.log,
np.log10, np.log1p, np.log2, np.rad2deg,
np.sin, np.sinh, np.sqrt, np.tan, np.tanh, np.trunc]:
y = fct(x)
f = theano.function([x], y)
utt.assert_allclose(np.nan_to_num(f(data)),
np.nan_to_num(fct(data)))
示例14: impl
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def impl(self, x):
# If x is an int8 or uint8, numpy.expm1 will compute the result in
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.expm1(x, sig='f')
return numpy.expm1(x)
示例15: c_code
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import expm1 [as 别名]
def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs
(z,) = outputs
if node.inputs[0].type in complex_types:
raise NotImplementedError('type not supported', type)
return "%(z)s = expm1(%(x)s);" % locals()