當前位置: 首頁>>代碼示例>>Python>>正文


Python tensor.abs_方法代碼示例

本文整理匯總了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) 
開發者ID:MarcCote,項目名稱:NADE,代碼行數:21,代碼來源:MoLaplaceNADE.py

示例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 
開發者ID:DartML,項目名稱:SteinGAN,代碼行數:24,代碼來源:steingan_celeba.py

示例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 
開發者ID:DartML,項目名稱:SteinGAN,代碼行數:24,代碼來源:steingan_lsun.py

示例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) 
開發者ID:dagbldr,項目名稱:dagbldr,代碼行數:23,代碼來源:penalties.py

示例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 
開發者ID:gplhegde,項目名稱:theano-xnor-net,代碼行數:19,代碼來源:xnor_net.py

示例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; 
#}}} 
開發者ID:lingluodlut,項目名稱:Att-ChemdNER,代碼行數:11,代碼來源:nn.py

示例7: abs

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def abs(x):
    return T.abs_(x) 
開發者ID:lingluodlut,項目名稱:Att-ChemdNER,代碼行數:4,代碼來源:theano_backend.py

示例8: __call__

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import abs_ [as 別名]
def __call__(self, x):
        return (x + T.abs_(x)) / 2.0 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:4,代碼來源:activations.py

示例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() 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:4,代碼來源:costs.py

示例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() 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:4,代碼來源:costs.py

示例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) 
開發者ID:lllcho,項目名稱:CAPTCHA-breaking,代碼行數:4,代碼來源:objectives.py

示例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. 
開發者ID:lllcho,項目名稱:CAPTCHA-breaking,代碼行數:4,代碼來源:objectives.py

示例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() 
開發者ID:Newmu,項目名稱:dcgan_code,代碼行數:4,代碼來源:costs.py

示例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} 
開發者ID:GUR9000,項目名稱:Deep_MRI_brain_extraction,代碼行數:41,代碼來源:TransferFunctions.py

示例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) 
開發者ID:diana-hep,項目名稱:carl,代碼行數:37,代碼來源:test_base.py


注:本文中的theano.tensor.abs_方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。