本文整理匯總了Python中theano.tensor.abs_方法的典型用法代碼示例。如果您正苦於以下問題:Python tensor.abs_方法的具體用法?Python tensor.abs_怎麽用?Python tensor.abs_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類theano.tensor
的用法示例。
在下文中一共展示了tensor.abs_方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sym_logdensity
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def sym_logdensity(self, x):
""" x is a matrix of column datapoints (VxB) V = n_visible, B = batch size """
def density_given_previous_a_and_x(x, w, V_alpha, b_alpha, V_mu, b_mu, V_sigma, b_sigma, activations_factor, p_prev, a_prev, x_prev):
a = a_prev + T.dot(T.shape_padright(x_prev, 1), T.shape_padleft(w, 1))
h = self.nonlinearity(a * activations_factor) # BxH
Alpha = T.nnet.softmax(T.dot(h, V_alpha) + T.shape_padleft(b_alpha)) # BxC
Mu = T.dot(h, V_mu) + T.shape_padleft(b_mu) # BxC
Sigma = T.exp((T.dot(h, V_sigma) + T.shape_padleft(b_sigma))) # BxC
p = p_prev + log_sum_exp(T.log(Alpha) - T.log(2 * Sigma) - T.abs_(Mu - T.shape_padright(x, 1)) / Sigma)
return (p, a, x)
# First element is different (it is predicted from the bias only)
a0 = T.zeros_like(T.dot(x.T, self.W)) # BxH
p0 = T.zeros_like(x[0])
x0 = T.ones_like(x[0])
([ps, _as, _xs], updates) = theano.scan(density_given_previous_a_and_x,
sequences=[x, self.W, self.V_alpha, self.b_alpha, self.V_mu, self.b_mu, self.V_sigma, self.b_sigma, self.activation_rescaling],
outputs_info=[p0, a0, x0])
return (ps[-1], updates)
示例2: discrim
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def discrim(X):
current_input = dropout(X, 0.3)
### encoder ###
cv1 = relu(dnn_conv(current_input, aew1, subsample=(1,1), border_mode=(1,1)))
cv2 = relu(batchnorm(dnn_conv(cv1, aew2, subsample=(4,4), border_mode=(2,2)), g=aeg2, b=aeb2))
cv3 = relu(batchnorm(dnn_conv(cv2, aew3, subsample=(1,1), border_mode=(1,1)), g=aeg3, b=aeb3))
cv4 = relu(batchnorm(dnn_conv(cv3, aew4, subsample=(4,4), border_mode=(2,2)), g=aeg4, b=aeb4))
cv5 = relu(batchnorm(dnn_conv(cv4, aew5, subsample=(1,1), border_mode=(1,1)), g=aeg5, b=aeb5))
cv6 = relu(batchnorm(dnn_conv(cv5, aew6, subsample=(4,4), border_mode=(0,0)), g=aeg6, b=aeb6))
### decoder ###
dv6 = relu(batchnorm(deconv(cv6, aew6, subsample=(4,4), border_mode=(0,0)), g=aeg6t, b=aeb6t))
dv5 = relu(batchnorm(deconv(dv6, aew5, subsample=(1,1), border_mode=(1,1)), g=aeg5t, b=aeb5t))
dv4 = relu(batchnorm(deconv(dv5, aew4, subsample=(4,4), border_mode=(2,2)), g=aeg4t, b=aeb4t))
dv3 = relu(batchnorm(deconv(dv4, aew3, subsample=(1,1), border_mode=(1,1)), g=aeg3t, b=aeb3t))
dv2 = relu(batchnorm(deconv(dv3, aew2, subsample=(4,4), border_mode=(2,2)), g=aeg2t, b=aeb2t))
dv1 = tanh(deconv(dv2, aew1, subsample=(1,1), border_mode=(1,1)))
rX = dv1
mse = T.sqrt(T.sum(T.abs_(T.flatten(X-rX, 2)),axis=1)) + T.sqrt(T.sum(T.flatten((X-rX)**2, 2), axis=1)) # L1 and L2 loss
return T.flatten(cv6, 2), rX, mse
示例3: discrim
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def discrim(X):
current_input = dropout(X, 0.3)
### encoder ###
cv1 = relu(dnn_conv(current_input, aew1, subsample=(1,1), border_mode=(1,1)))
cv2 = relu(batchnorm(dnn_conv(cv1, aew2, subsample=(4,4), border_mode=(2,2)), g=aeg2, b=aeb2))
cv3 = relu(batchnorm(dnn_conv(cv2, aew3, subsample=(1,1), border_mode=(1,1)), g=aeg3, b=aeb3))
cv4 = relu(batchnorm(dnn_conv(cv3, aew4, subsample=(4,4), border_mode=(2,2)), g=aeg4, b=aeb4))
cv5 = relu(batchnorm(dnn_conv(cv4, aew5, subsample=(1,1), border_mode=(1,1)), g=aeg5, b=aeb5))
cv6 = relu(batchnorm(dnn_conv(cv5, aew6, subsample=(4,4), border_mode=(0,0)), g=aeg6, b=aeb6))
### decoder ###
dv6 = relu(batchnorm(deconv(cv6, aew6, subsample=(4,4), border_mode=(0,0)), g=aeg6t, b=aeb6t))
dv5 = relu(batchnorm(deconv(dv6, aew5, subsample=(1,1), border_mode=(1,1)), g=aeg5t, b=aeb5t))
dv4 = relu(batchnorm(deconv(dv5, aew4, subsample=(4,4), border_mode=(2,2)), g=aeg4t, b=aeb4t))
dv3 = relu(batchnorm(deconv(dv4, aew3, subsample=(1,1), border_mode=(1,1)), g=aeg3t, b=aeb3t))
dv2 = relu(batchnorm(deconv(dv3, aew2, subsample=(4,4), border_mode=(2,2)), g=aeg2t, b=aeb2t))
dv1 = tanh(deconv(dv2, aew1, subsample=(1,1), border_mode=(1,1)))
rX = dv1
mse = T.sqrt(T.sum(T.abs_(T.flatten(X-rX, 2)),axis=1)) + T.sqrt(T.sum(T.flatten((X-rX)**2, 2), axis=1))
return T.flatten(cv6, 2), rX, mse
示例4: abs_error
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def abs_error(predicted_values, true_values):
"""
Gaussian negative log likelihood compared to true_values. Estimates the
conditional median.
Parameters
----------
predicted_values : tensor, shape 2D or 3D
The predicted values out of some layer.
true_values : tensor, shape 2D or 3D
Ground truth values. Must be the same shape as
predicted_values.
Returns
-------
abs_error : tensor, shape predicted_values.shape[1:]
The cost per sample, or per sample per step if 3D
"""
return tensor.abs_(predicted_values - true_values).sum(axis=-1)
示例5: binarize_conv_input
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def binarize_conv_input(conv_input, k):
# This is from BinaryNet.
# This acts like sign function during forward pass. and like hard_tanh during back propagation
bin_conv_out = binary_tanh_unit(conv_input)
# scaling factor for the activation.
A =T.abs_(conv_input)
# K will have scaling matrixces for each input in the batch.
# K's shape = (batch_size, 1, map_height, map_width)
k_shape = k.eval().shape
pad = (k_shape[-2]/2, k_shape[-1]/2)
# support the kernel stride. This is necessary for AlexNet
K = theano.tensor.nnet.conv2d(A, k, border_mode=pad)
return bin_conv_out, K
示例6: manhattenScore
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def manhattenScore(self,attended,state,W):
#{{{
#Manhattan Distance
#eps for avoid gradient to be NaN;
M=T.abs_(T.maximum(attended-state,self.eps));
M=T.dot(M,W);
_energy=M.max()-M;
return _energy;
#}}}
示例7: abs
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def abs(x):
return T.abs_(x)
示例8: __call__
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def __call__(self, x):
return (x + T.abs_(x)) / 2.0
示例9: L1Loss
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def L1Loss(y_pred, y_true):
return T.abs_(y_pred - y_true).mean()
示例10: TruncatedL1
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def TruncatedL1(y_pred, y_true, tr):
return T.maximum(T.abs_(y_pred - y_true), tr).mean()
示例11: mean_absolute_error
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def mean_absolute_error(y_true, y_pred):
return T.abs_(y_pred - y_true).mean(axis=-1)
示例12: mean_absolute_percentage_error
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def mean_absolute_percentage_error(y_true, y_pred):
return T.abs_((y_true - y_pred) / T.clip(T.abs_(y_true), epsilon, np.inf)).mean(axis=-1) * 100.
示例13: MeanAbsoluteError
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def MeanAbsoluteError(y_true, y_pred):
return T.abs_(y_pred - y_true).mean()
示例14: parse_transfer_function
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def parse_transfer_function(string_identifier, slope_parameter = None):
""" This function returns the appropriate activation function, as selected by the string argument.
string_identifier:
possible values are tanh, ReLU/relu, sigmoid/sig, abs, maxout <number>, linear/lin
RETURNS:
transfer_function(python/theano function), string_identifier (normalized), dict (for special cases)
"""
cross_channel_pooling_groups=None
if string_identifier=='tanh':
Activation_f = T.tanh
elif string_identifier in ['ReLU', 'relu']: #rectified linear unit
string_identifier = "relu"
Activation_f = lambda x: x*(x>0)
elif string_identifier in ['sigmoid', 'sig']:
string_identifier = "sigmoid"
Activation_f = T.nnet.sigmoid
elif string_identifier in ['abs', 'Abs', 'absolute']:
string_identifier='abs'
Activation_f = T.abs_
elif string_identifier in ['plu','PLu','PLU','piecewise']: #piece-wise linear function
string_identifier = "PLU"
print "parse_transfer_function::Remember to optimize the 'slope_parameter'"
assert slope_parameter is not None,"...and better pass it to this function, as well! (type: Theano.Tensor, shape: same as activation, unif. random values [-1,1] should be fine)"
Activation_f = lambda x: T.maximum(0,x) + T.minimum(0,x) * slope_parameter
elif "maxout" in string_identifier:
r=int(string_identifier.split(" ")[1])
assert r>=2
cross_channel_pooling_groups = r
elif string_identifier in ['linear',"lin"]:
string_identifier = "linear"
Activation_f = lambda x:x
else:
raise NotImplementedError()
return Activation_f, string_identifier, {"cross_channel_pooling_groups":cross_channel_pooling_groups}
示例15: test_mixin_composition
# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def test_mixin_composition():
# Check composed expressions as parameters
a = theano.shared(0.0)
b = theano.shared(-1.0)
mu = a + b - 1.0
sigma = T.abs_(a * b)
p = Normal(mu=mu, sigma=sigma)
assert a in p.parameters_
assert b in p.parameters_
# Compose parameters with observed variables
a = theano.shared(1.0)
b = theano.shared(0.0)
y = T.dmatrix(name="y")
p = Normal(mu=a * y + b)
assert len(p.parameters_) == 3
assert a in p.parameters_
assert b in p.parameters_
assert p.sigma in p.parameters_
assert p.mu not in p.parameters_
assert len(p.observeds_) == 1
assert y in p.observeds_
# Check signatures
data_X = np.random.rand(10, 1)
data_y = np.random.rand(10, 1)
p.pdf(X=data_X, y=data_y)
p.cdf(X=data_X, y=data_y)
p.rvs(10, y=data_y)
# Check error
a = theano.shared(1.0)
b = theano.shared(0.0)
y = T.dmatrix() # y must be named
assert_raises(ValueError, Normal, mu=a * y + b)