本文整理汇总了Python中theano.tensor.erf方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.erf方法的具体用法?Python tensor.erf怎么用?Python tensor.erf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.erf方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def __init__(self, x, mu, sigma, *args, **kwargs):
super(Normal, self).__init__(*args, **kwargs)
self._logp = bound(
-(x - mu)**2 / (2 * sigma**2) + T.log(1 / T.sqrt(sigma**2 * 2*np.pi)),
sigma > 0
)
self._cdf = 0.5 * (1 + T.erf((x - mu)/(sigma*T.sqrt(2))))
self._add_expr('x', x)
self._add_expr('mu', mu)
self._add_expr('sigma', sigma)
示例2: n_cdf
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def n_cdf(x):
return 0.5 * (1.0 + T.erf(x / T.sqrt(2.0)))
示例3: discretized_gaussian
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def discretized_gaussian(mean, logvar, binsize, sample=None):
scale = T.exp(.5*logvar)
if sample is None:
_y = G.rng_curand.normal(size=mean.shape)
sample = mean + scale * _y #sample from the actual logistic
sample = T.floor(sample/binsize)*binsize #discretize the sample
_sample = (T.floor(sample/binsize)*binsize - mean)/scale
def _erf(x):
return T.erf(x/T.sqrt(2.))
logp = T.log( _erf(_sample + binsize/scale) - _erf(_sample) + 1e-7) + T.log(.5)
logp = logp.flatten(2).sum(axis=1)
#raise Exception()
entr = (.5 * (T.log(2 * math.pi) + 1 + logvar)).flatten(2).sum(axis=1)
return RandomVariable(sample, logp, entr, mean=mean, logvar=logvar)
示例4: __init__
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def __init__(self, mu=0.0, sigma=1.0):
"""Constructor.
Parameters
----------
* `mu` [float]:
The distribution mean.
* `sigma` [float]:
The distribution standard deviation.
"""
super(Normal, self).__init__(mu=mu, sigma=sigma)
# pdf
self.pdf_ = (
(1. / np.sqrt(2. * np.pi)) / self.sigma *
T.exp(-(self.X - self.mu) ** 2 / (2. * self.sigma ** 2))).ravel()
self._make(self.pdf_, "pdf")
# -log pdf
self.nll_ = bound(
T.log(self.sigma) + T.log(np.sqrt(2. * np.pi)) +
(self.X - self.mu) ** 2 / (2. * self.sigma ** 2),
np.inf,
self.sigma > 0.).ravel()
self._make(self.nll_, "nll")
# cdf
self.cdf_ = 0.5 * (1. + T.erf((self.X - self.mu) /
(self.sigma * np.sqrt(2.)))).ravel()
self._make(self.cdf_, "cdf")
# ppf
self.ppf_ = (self.mu +
np.sqrt(2.) * self.sigma * T.erfinv(2. * self.p - 1.))
self._make(self.ppf_, "ppf", args=[self.p])
示例5: gelu2
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def gelu2(x):
'''
similar to silu
'''
return x*(tt.erf(x) + 1)
示例6: cdf
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def cdf(sample, mu=0, sigma=1, eps=1e-6):
div = T.sqrt(2) * sigma
erf_arg = (sample - mu) / div
return .5 * (1 + T.erf(erf_arg))
示例7: get_output_for
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def get_output_for(self, input, **kwargs):
mu = input[0]
sigma = input[1]
w = input[2]
if self.log:
sigma = T.exp(sigma)
x_range = T.arange(0, 600).dimshuffle('x', 0, 'x')
mu = mu.dimshuffle(0, 'x', 1)
sigma = sigma.dimshuffle(0, 'x', 1)
x = (x_range - mu) / (sigma * T.sqrt(2.) + 1e-16)
cdf = (T.erf(x) + 1.) / 2. # (bs, 600, n_mix)
cdf = T.sum(cdf * w.dimshuffle(0, 'x', 1), axis=-1)
return cdf
示例8: get_output_for
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def get_output_for(self, input, **kwargs):
if input.ndim > 3:
# input: (batch, time, axis, verti, horiz)
# needs: (batch, time, pixels)
input = input.flatten(ndim=3)
eps=1e-7
clipped_input = T.clip(input, eps, 1-eps)
mu = T.sum(clipped_input, axis=2).dimshuffle(0,1,'x')
sigma = T.sqrt(T.sum(clipped_input * (1-clipped_input), axis=2).dimshuffle(0,1,'x') + eps)
x_axis = theano.shared(np.arange(0, 600, dtype='float32')).dimshuffle('x','x',0)
x = (x_axis - mu) / sigma
return (T.erf(x) + 1)/2
示例9: get_output_for
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def get_output_for(self, input, **kwargs):
eps = 1e-7
x_axis = theano.shared(np.arange(0, 600, dtype='float32')).dimshuffle('x',0)
# This needs to be clipped to avoid NaN's!
sigma = T.exp(T.clip(input[:,1].dimshuffle(0,'x'), -10, 10))
#theano_printer.print_me_this("sigma", sigma)
x = (x_axis - input[:,0].dimshuffle(0,'x')) / (sigma * np.sqrt(2).astype('float32'))
return (T.erf(x) + 1)/2
示例10: theano_mu_sigma_erf
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def theano_mu_sigma_erf(mu_erf, sigma_erf, eps=1e-7):
x_axis = theano.shared(np.arange(0, 600, dtype='float32')).dimshuffle('x',0)
if sigma_erf.ndim==0:
sigma_erf = T.clip(sigma_erf.dimshuffle('x','x'), eps, 1)
elif sigma_erf.ndim==1:
sigma_erf = T.clip(sigma_erf.dimshuffle(0,'x'), eps, 1)
x = (x_axis - mu_erf.dimshuffle(0,'x')) / (sigma_erf * np.sqrt(2).astype('float32'))
return (T.erf(x) + 1)/2
示例11: numpy_mu_sigma_erf
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import erf [as 别名]
def numpy_mu_sigma_erf(mu_erf, sigma_erf, eps=1e-7):
batch_size = mu_erf.shape[0]
x_axis = np.tile(np.arange(0, 600, dtype='float32'), (batch_size, 1))
mu_erf = np.tile(mu_erf[:,None], (1, 600))
sigma_erf = np.tile(sigma_erf[:,None], (1, 600))
sigma_erf += eps
x = (x_axis - mu_erf) / (sigma_erf * np.sqrt(2))
return (erf(x) + 1)/2