本文整理汇总了Python中theano.tensor.log1p函数的典型用法代码示例。如果您正苦于以下问题:Python log1p函数的具体用法?Python log1p怎么用?Python log1p使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log1p函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: jacobian_det
def jacobian_det(self, y):
Km1 = y.shape[0]
k = tt.arange(Km1)[(slice(None),) + (None,) * (y.ndim - 1)]
eq_share = -tt.log(Km1 - k) # logit(1./(Km1 + 1 - k))
yl = y + eq_share
yu = tt.concatenate([tt.ones(y[:1].shape), 1 - inverse_logit(yl)])
S = tt.extra_ops.cumprod(yu, 0)
return tt.sum(tt.log(S[:-1]) - tt.log1p(tt.exp(yl)) - tt.log1p(tt.exp(-yl)), 0)
开发者ID:Riashat,项目名称:pymc3,代码行数:8,代码来源:transforms.py
示例2: jacobian_det
def jacobian_det(self, y_):
y = y_.T
Km1 = y.shape[0]
k = tt.arange(Km1)[(slice(None), ) + (None, ) * (y.ndim - 1)]
eq_share = logit(1. / (Km1 + 1 - k).astype(str(y_.dtype)))
yl = y + eq_share
yu = tt.concatenate([tt.ones(y[:1].shape), 1 - invlogit(yl, self.eps)])
S = tt.extra_ops.cumprod(yu, 0)
return tt.sum(tt.log(S[:-1]) - tt.log1p(tt.exp(yl)) - tt.log1p(tt.exp(-yl)), 0).T
开发者ID:hstm,项目名称:pymc3,代码行数:9,代码来源:transforms.py
示例3: rates
def rates(self, x):
dtype = theano.config.floatX
sigma = tt.cast(0.05, dtype=dtype)
tau_ref = tt.cast(self.tau_ref, dtype=dtype)
tau_rc = tt.cast(self.tau_rc, dtype=dtype)
j = self.gain * x + self.bias - 1
j = sigma * tt.log1p(tt.exp(j / sigma))
v = 1. / (tau_ref + tau_rc * tt.log1p(1. / j))
return tt.switch(j > 0, v, 0.0) / self.max_rates
开发者ID:Narts,项目名称:nef-rbm,代码行数:10,代码来源:deep-auto.py
示例4: log_i0
def log_i0(x):
"""
Calculates the logarithm of the 0 order modified Bessel function of the first kind""
"""
return tt.switch(tt.lt(x, 5), tt.log1p(x**2. / 4. + x**4. / 64. + x**6. / 2304.
+ x**8. / 147456. + x**10. / 14745600.
+ x**12. / 2123366400.),
x - 0.5 * tt.log(2. * np.pi * x) + tt.log1p(1. / (8. * x)
+ 9. / (128. * x**2.) + 225. / (3072. * x**3.)
+ 11025. / (98304. * x**4.)))
开发者ID:alexander-belikov,项目名称:pymc3,代码行数:10,代码来源:special.py
示例5: safe_logaddexp
def safe_logaddexp(a, b):
"""Symbolic log(exp(a) + exp(b)). The edge case where `a` - `b` is undefined is handled by
setting the difference to 0. This occurs if both `a` and `b` are +inf or -inf.
Returns:
symbolic log(exp(a) + exp(b))
"""
diff = b - a
safe_diff = tt.switch(tt.isnan(diff), 0, diff)
return tt.switch(safe_diff >= 0,
b + tt.log1p(tt.exp(-safe_diff)),
a + tt.log1p(tt.exp(safe_diff)))
开发者ID:broadinstitute,项目名称:gatk,代码行数:12,代码来源:commons.py
示例6: logp
def logp(self, value):
psi = self.psi
p = self.p
n = self.n
logp_val = tt.switch(tt.gt(value, 0),
tt.log(psi) + self.bin.logp(value),
logaddexp(tt.log1p(-psi), tt.log(psi) + n * tt.log1p(-p)))
return bound(logp_val,
0 <= value, value <= n,
0 <= psi, psi <= 1,
0 <= p, p <= 1)
开发者ID:aasensio,项目名称:pymc3,代码行数:13,代码来源:discrete.py
示例7: nlif
def nlif(x):
dtype = theano.config.floatX
sigma = tt.cast(0.05, dtype=dtype)
tau_ref = tt.cast(0.002, dtype=dtype)
tau_rc = tt.cast(0.02, dtype=dtype)
alpha = tt.cast(1, dtype=dtype)
beta = tt.cast(1, dtype=dtype)
amp = tt.cast(1. / 65, dtype=dtype)
j = alpha * x + beta - 1
j = sigma * tt.log1p(tt.exp(j / sigma))
v = amp / (tau_ref + tau_rc * tt.log1p(1. / j))
return tt.switch(j > 0, v, 0.0)
开发者ID:Narts,项目名称:nef-rbm,代码行数:13,代码来源:nlif-deep.py
示例8: nlif
def nlif(x):
dtype = theano.config.floatX
sigma = tt.cast(0.05, dtype=dtype)
tau_ref = tt.cast(0.002, dtype=dtype)
tau_rc = tt.cast(0.02, dtype=dtype)
alpha = tt.cast(1, dtype=dtype)
beta = tt.cast(1, dtype=dtype) # so that f(0) = firing threshold
amp = tt.cast(1. / 63.04, dtype=dtype) # so that f(1) = 1
j = alpha * x + beta - 1
j = sigma * tt.log1p(tt.exp(j / sigma))
v = amp / (tau_ref + tau_rc * tt.log1p(1. / j))
return tt.switch(j > 0, v, 0.0)
开发者ID:Narts,项目名称:nef-rbm,代码行数:13,代码来源:train_lif.py
示例9: kl_div
def kl_div(self, x, y):
"""
Compute sum of D(x_i || y_i) for each corresponding element
along the 3rd dimension (the embedding dimension)
of x and y
This function takes care to not compute logarithms that are close
to 0, since NaN's could result for log(sigmoid(x)) if x is negative.
It simply uses that log(sigmoid(x)) = - log(1 + e^-x)
"""
sig_x = T.nnet.sigmoid(x)
exp_x = T.exp(x)
exp_y = T.exp(y)
exp_neg_x = T.exp(-x)
exp_neg_y = T.exp(-y)
return (sig_x * (T.log1p(exp_neg_y) - T.log1p(exp_neg_x)) + (1 - sig_x) * (T.log1p(exp_y) - T.log1p(exp_x))).mean()
开发者ID:rguthrie3,项目名称:MorphologicalPriorsForWordEmbeddings,代码行数:15,代码来源:morpho_model.py
示例10: __call__
def __call__(self, layer, spec, shape, name=None, **tags):
# case when user uses default init specs
assert tags.get('variational',False) == True, "Please declare param as variational to avoid confusion"
if not isinstance(spec, dict):
initial_rho = np.log(np.expm1(self.prior_std)) #std to rho
assert np.isfinite(initial_rho),"too small std to initialize correctly. Please pass explicit"\
" initializer (dict with {'mu':mu_init, 'rho':rho_init})."
spec = {'mu': spec,'rho':init.Constant(initial_rho)}
mu_spec,rho_spec = spec['mu'],spec['rho']
rho = layer.add_param(rho_spec, shape,name=(name or 'unk')+'.rho', **tags)
mean = layer.add_param(mu_spec, shape,name=(name or 'unk')+'.mu', **tags)
#Reparameterization trick
e = self.srng.normal(shape, std=1)
W = mean + T.log1p(T.exp(rho)) * e
#KL divergence KL(q,p) = E_(w~q(w|x)) [log q(w|x) - log P(w)] aka variational cost
q_p = T.sum(self.log_posterior_approx(W, mean, rho) - self.log_prior(W))
#accumulate variational cost
layer._bbwrap_var_cost += q_p
return W
开发者ID:dantodor,项目名称:Practical_RL,代码行数:26,代码来源:bayes.py
示例11: log_posterior_approx
def log_posterior_approx(self,weights, mean, rho):
"""
Logarithm of ELBO on posterior probabilities:
log q(weights|learned mu and rho) aka log q(theta|x)
"""
std = T.log1p(T.exp(rho)) #rho to std
return self.log_normal(weights, mean, std)
开发者ID:dantodor,项目名称:Practical_RL,代码行数:7,代码来源:bayes.py
示例12: setup
def setup(self, bottom, top):
from caffe_helper.theano_util import init_theano
init_theano()
import theano as tn
import theano.tensor as T
assert len(bottom) == 2
assert len(top) == 1
s_y = T.matrix('y') # y in [-inf, inf]
s_t = T.matrix('t') # t in {-1, 0, 1} where 0 is ignored
s_dloss = T.scalar('dloss')
# Forward
# s_loss = T.mean(abs(s_t) * T.log1p(T.exp(-s_y * s_t))) # unstable
s_loss = -T.sum(
abs(s_t) * (
s_y * ((s_t >= 0) - (s_y >= 0)) - T.log1p(T.exp(-abs(s_y)))))\
/ T.maximum(T.sum(abs(s_t)), 1)
# Backward
s_p = 1 / (1 + T.exp(-s_y))
s_dy = s_dloss * abs(s_t) * (s_p - (s_t >= 0)) / \
T.maximum(T.sum(abs(s_t)), 1)
def _o(s):
return tn.Out(s, borrow=True)
self.tn_forward = tn.function([s_y, s_t], s_loss)
self.tn_backward = tn.function([s_y, s_t, s_dloss], _o(s_dy))
开发者ID:NHZlX,项目名称:tnarihi-caffe-helper,代码行数:26,代码来源:loss_layers.py
示例13: normal_lccdf
def normal_lccdf(mu, sigma, x):
z = (x - mu) / sigma
return tt.switch(
tt.gt(z, 1.0),
tt.log(tt.erfcx(z / tt.sqrt(2.)) / 2.) - tt.sqr(z) / 2.,
tt.log1p(-tt.erfc(-z / tt.sqrt(2.)) / 2.)
)
开发者ID:aasensio,项目名称:pymc3,代码行数:7,代码来源:censored_data.py
示例14: normal_lcdf
def normal_lcdf(mu, sigma, x):
"""Compute the log of the cumulative density function of the normal."""
z = (x - mu) / sigma
return tt.switch(
tt.lt(z, -1.0),
tt.log(tt.erfcx(-z / tt.sqrt(2.)) / 2.) - tt.sqr(z) / 2.,
tt.log1p(-tt.erfc(z / tt.sqrt(2.)) / 2.)
)
开发者ID:alexander-belikov,项目名称:pymc3,代码行数:8,代码来源:dist_math.py
示例15: logp
def logp(self, value):
quaddist, logdet, ok = self._quaddist(value)
k = value.shape[-1].astype(theano.config.floatX)
norm = (gammaln((self.nu + k) / 2.)
- gammaln(self.nu / 2.)
- 0.5 * k * floatX(np.log(self.nu * np.pi)))
inner = - (self.nu + k) / 2. * tt.log1p(quaddist / self.nu)
return bound(norm + inner - logdet, ok)
开发者ID:aasensio,项目名称:pymc3,代码行数:9,代码来源:multivariate.py
示例16: log_add
def log_add(lna, lnb):
"""
Compute the ln(a+b) given {lna,lnb}
:param
:return: ln(a+b)
"""
max_ = tensor.maximum(lna, lnb)
result = (max_ + tensor.log1p(tensor.exp(lna + lnb - 2 * max_))) #log1p(x) = log(1+x)
return tensor.switch(tensor.isnan(result), max_, result)
开发者ID:Michlong,项目名称:Precise-CTC,代码行数:9,代码来源:mytheano_utils.py
示例17: logp
def logp(self, value):
nu = self.nu
mu = self.mu
lam = self.lam
sd = self.sd
return bound(gammaln((nu + 1.0) / 2.0)
+ .5 * T.log(lam / (nu * np.pi))
- gammaln(nu / 2.0)
- (nu + 1.0) / 2.0 * T.log1p(lam * (value - mu)**2 / nu),
lam > 0, nu > 0, sd > 0)
开发者ID:gurganious,项目名称:pymc3,代码行数:11,代码来源:continuous.py
示例18: lif
def lif(x):
dtype = theano.config.floatX
tau_ref = tt.cast(0.002, dtype=dtype)
tau_rc = tt.cast(0.02, dtype=dtype)
alpha = tt.cast(1, dtype=dtype)
beta = tt.cast(1, dtype=dtype)
amp = tt.cast(1. / 65, dtype=dtype)
j = alpha * x + beta - 1
v = amp / (tau_ref + tau_rc * tt.log1p(1. / j))
return tt.switch(j > 0, v, 0.0)
开发者ID:Narts,项目名称:nef-rbm,代码行数:11,代码来源:nlif-rbm.py
示例19: _log_add_3
def _log_add_3(log_a, log_b, log_c):
"""Theano expression for log(a+b+c) given log(a), log(b), log(c)."""
smaller = T.minimum(log_a, log_b)
larger = T.maximum(log_a, log_b)
largest = T.maximum(larger, log_c)
larger = T.minimum(larger, log_c)
return largest + T.log1p(
T.exp(smaller - largest) +
T.exp(larger - largest)
)
开发者ID:igul222,项目名称:Marmot,代码行数:11,代码来源:ctc.py
示例20: log1mexp
def log1mexp(x):
"""Return log(1 - exp(-x)).
This function is numerically more stable than the naive approch.
For details, see
https://cran.r-project.org/web/packages/Rmpfr/vignettes/log1mexp-note.pdf
"""
return tt.switch(
tt.lt(x, 0.683),
tt.log(-tt.expm1(-x)),
tt.log1p(-tt.exp(-x)))
开发者ID:alexander-belikov,项目名称:pymc3,代码行数:12,代码来源:math.py
注:本文中的theano.tensor.log1p函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论