当前位置: 首页>>代码示例>>Python>>正文


Python tensor.eq方法代码示例

本文整理汇总了Python中theano.tensor.eq方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.eq方法的具体用法?Python tensor.eq怎么用?Python tensor.eq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.tensor的用法示例。


在下文中一共展示了tensor.eq方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: accuracy_instance

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def accuracy_instance(predictions, targets, n=[1, 2, 3, 4, 5, 10], \
        nb_classes=5, nb_samples_per_class=10, batch_size=1):
    accuracy_0 = theano.shared(np.zeros((batch_size, nb_samples_per_class), \
        dtype=theano.config.floatX))
    indices_0 = theano.shared(np.zeros((batch_size, nb_classes), \
        dtype=np.int32))
    batch_range = T.arange(batch_size)
    def step_(p, t, acc, idx):
        acc = T.inc_subtensor(acc[batch_range, idx[batch_range, t]], T.eq(p, t))
        idx = T.inc_subtensor(idx[batch_range, t], 1)
        return (acc, idx)
    (raw_accuracy, _), _ = theano.foldl(step_, sequences=[predictions.dimshuffle(1, 0), \
        targets.dimshuffle(1, 0)], outputs_info=[accuracy_0, indices_0])
    accuracy = T.mean(raw_accuracy / nb_classes, axis=0)

    return accuracy 
开发者ID:tristandeleu,项目名称:ntm-one-shot,代码行数:18,代码来源:metrics.py

示例2: _get_jac_vars

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def _get_jac_vars(self):
        if not self.predictor.feature_jacobian_name:
            raise NotImplementedError

        X_var, U_var, X_target_var, U_lin_var, alpha_var = self.input_vars

        names = [self.predictor.feature_name, self.predictor.feature_jacobian_name, self.predictor.next_feature_name]
        vars_ = L.get_output([self.predictor.pred_layers[name] for name in iter_util.flatten_tree(names)], deterministic=True)
        feature_vars, jac_vars, next_feature_vars = iter_util.unflatten_tree(names, vars_)

        y_vars = [T.flatten(feature_var, outdim=2) for feature_var in feature_vars]
        y_target_vars = [theano.clone(y_var, replace={X_var: X_target_var}) for y_var in y_vars]
        y_target_vars = [theano.ifelse.ifelse(T.eq(alpha_var, 1.0),
                                              y_target_var,
                                              alpha_var * y_target_var + (1 - alpha_var) * y_var)
                         for (y_var, y_target_var) in zip(y_vars, y_target_vars)]

        jac_vars = [theano.clone(jac_var, replace={U_var: U_lin_var}) for jac_var in jac_vars]
        return jac_vars 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:21,代码来源:servoing_policy.py

示例3: _get_jac_z_vars

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def _get_jac_z_vars(self):
        if not self.predictor.feature_jacobian_name:
            raise NotImplementedError

        X_var, U_var, X_target_var, U_lin_var, alpha_var = self.input_vars

        names = [self.predictor.feature_name, self.predictor.feature_jacobian_name, self.predictor.next_feature_name]
        vars_ = L.get_output([self.predictor.pred_layers[name] for name in iter_util.flatten_tree(names)], deterministic=True)
        feature_vars, jac_vars, next_feature_vars = iter_util.unflatten_tree(names, vars_)

        y_vars = [T.flatten(feature_var, outdim=2) for feature_var in feature_vars]
        y_target_vars = [theano.clone(y_var, replace={X_var: X_target_var}) for y_var in y_vars]
        y_target_vars = [theano.ifelse.ifelse(T.eq(alpha_var, 1.0),
                                              y_target_var,
                                              alpha_var * y_target_var + (1 - alpha_var) * y_var)
                         for (y_var, y_target_var) in zip(y_vars, y_target_vars)]

        jac_vars = [theano.clone(jac_var, replace={U_var: U_lin_var}) for jac_var in jac_vars]
        y_next_pred_vars = [T.flatten(next_feature_var, outdim=2) for next_feature_var in next_feature_vars]
        y_next_pred_vars = [theano.clone(y_next_pred_var, replace={U_var: U_lin_var}) for y_next_pred_var in y_next_pred_vars]

        z_vars = [y_target_var - y_next_pred_var + T.batched_tensordot(jac_var, U_lin_var, axes=(2, 1))
                  for (y_target_var, y_next_pred_var, jac_var) in zip(y_target_vars, y_next_pred_vars, jac_vars)]
        return jac_vars, z_vars 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:26,代码来源:servoing_policy.py

示例4: salt_and_pepper

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def salt_and_pepper(input, noise_level=0.2, mrg=None):
    """
    This applies salt and pepper noise to the input tensor - randomly setting bits to 1 or 0.

    Parameters
    ----------
    input : tensor
        The tensor to apply salt and pepper noise to.
    noise_level : float
        The amount of salt and pepper noise to add.
    mrg : random
        Random number generator with .binomial method.

    Returns
    -------
    tensor
        Tensor with salt and pepper noise applied.
    """
    if mrg is None:
        mrg = theano_random
    # salt and pepper noise
    a = mrg.binomial(size=input.shape, n=1, p=(1 - noise_level), dtype=theano.config.floatX)
    b = mrg.binomial(size=input.shape, n=1, p=0.5, dtype=theano.config.floatX)
    c = T.eq(a, 0) * b
    return input * a + c 
开发者ID:vitruvianscience,项目名称:OpenDeep,代码行数:27,代码来源:noise.py

示例5: recurrence_relation

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def recurrence_relation(y, y_mask, blank_symbol):
        n_y = y.shape[0]
        blanks = tensor.zeros((2, y.shape[1])) + blank_symbol
        ybb = tensor.concatenate((y, blanks), axis=0).T
        sec_diag = (tensor.neq(ybb[:, :-2], ybb[:, 2:]) *
                    tensor.eq(ybb[:, 1:-1], blank_symbol) *
                    y_mask.T)

        # r1: LxL
        # r2: LxL
        # r3: LxLxB
        r2 = tensor.eye(n_y, k=1)
        r3 = (tensor.eye(n_y, k=2).dimshuffle(0, 1, 'x') *
              sec_diag.dimshuffle(1, 'x', 0))

        return r2, r3 
开发者ID:mohammadpz,项目名称:CTC-Connectionist-Temporal-Classification,代码行数:18,代码来源:ctc_cost.py

示例6: gate_layer

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def gate_layer(tparams, X_word, X_char, options, prefix, pretrain_mode, activ='lambda x: x', **kwargs):
    """ 
    compute the forward pass for a gate layer

    Parameters
    ----------
    tparams        : OrderedDict of theano shared variables, {parameter name: value}
    X_word         : theano 3d tensor, word input, dimensions: (num of time steps, batch size, dim of vector)
    X_char         : theano 3d tensor, char input, dimensions: (num of time steps, batch size, dim of vector)
    options        : dictionary, {hyperparameter: value}
    prefix         : string, layer name
    pretrain_mode  : theano shared scalar, 0. = word only, 1. = char only, 2. = word & char
    activ          : string, activation function: 'liner', 'tanh', or 'rectifier'

    Returns
    -------
    X              : theano 3d tensor, final vector, dimensions: (num of time steps, batch size, dim of vector)

    """      
    # compute gating values, Eq.(3)
    G = tensor.nnet.sigmoid(tensor.dot(X_word, tparams[p_name(prefix, 'v')]) + tparams[p_name(prefix, 'b')][0])
    X = ifelse(tensor.le(pretrain_mode, numpy.float32(1.)),  
               ifelse(tensor.eq(pretrain_mode, numpy.float32(0.)), X_word, X_char),
               G[:, :, None] * X_char + (1. - G)[:, :, None] * X_word)   
    return eval(activ)(X) 
开发者ID:nyu-dl,项目名称:gated_word_char_rlm,代码行数:27,代码来源:layers.py

示例7: concat_layer

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def concat_layer(tparams, X_word, X_char, options, prefix, pretrain_mode, activ='lambda x: x', **kwargs):
    """ 
    compute the forward pass for a concat layer

    Parameters
    ----------
    tparams        : OrderedDict of theano shared variables, {parameter name: value}
    X_word         : theano 3d tensor, word input, dimensions: (num of time steps, batch size, dim of vector)
    X_char         : theano 3d tensor, char input, dimensions: (num of time steps, batch size, dim of vector)
    options        : dictionary, {hyperparameter: value}
    prefix         : string,  layer name
    pretrain_mode  : theano shared scalar, 0. = word only, 1. = char only, 2. = word & char
    activ          : string, activation function: 'liner', 'tanh', or 'rectifier'

    Returns
    -------
    X              : theano 3d tensor, final vector, dimensions: (num of time steps, batch size, dim of vector)

    """
    X = ifelse(tensor.le(pretrain_mode, numpy.float32(1.)),
               ifelse(tensor.eq(pretrain_mode, numpy.float32(0.)), X_word, X_char),
               tensor.dot(tensor.concatenate([X_word, X_char], axis=2), tparams[p_name(prefix, 'W')]) + tparams[p_name(prefix, 'b')]) 
    return eval(activ)(X) 
开发者ID:nyu-dl,项目名称:gated_word_char_rlm,代码行数:25,代码来源:layers.py

示例8: __init__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def __init__(self, rng, input, n_in, n_out, is_train,
                 activation, dropout_rate, mask=None, W=None, b=None):
        super(DropoutHiddenLayer, self).__init__(
                rng=rng, input=input, n_in=n_in, n_out=n_out, W=W, b=b,
                activation=activation)

        self.dropout_rate = dropout_rate
        self.srng = T.shared_randomstreams.RandomStreams(rng.randint(999999))
        self.mask = mask
        self.layer = self.output

        # Computes outputs for train and test phase applying dropout when needed.
        train_output = self.layer * T.cast(self.mask, theano.config.floatX)
        test_output = self.output * (1 - dropout_rate)
        self.output = ifelse(T.eq(is_train, 1), train_output, test_output)
        return 
开发者ID:prasadseemakurthi,项目名称:Deep-Neural-Networks-HealthCare,代码行数:18,代码来源:DropoutHiddenLayer.py

示例9: _create_class_size_function

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def _create_class_size_function(self):
        """Creates a function that calculates the number of words in a class.

        :type class_id: int
        :param class_id: ID of a class

        :rtype: int
        :returns: number of words in the class
        """

        class_id = tensor.scalar('class_id', dtype=self._count_type)
        class_id.tag.test_value = 0

        result = tensor.eq(self._word_to_class, class_id).sum()

        self._class_size = theano.function(
            [class_id],
            result,
            name='class_size') 
开发者ID:senarvi,项目名称:theanolm,代码行数:21,代码来源:theanobigramoptimizer.py

示例10: Noise

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def Noise(hyp, X1, X2=None, all_pairs=True):
    ''' Noise kernel. Takes as an input a distance matrix D
    and creates a new matrix as Kij = sn2 if Dij == 0 else 0'''
    if X2 is None:
        X2 = X1

    sn2 = hyp**2
    if all_pairs and X1 is X2:
        # D = (X1[:,None,:] - X2[None,:,:]).sum(2)
        K = tt.eye(X1.shape[0])*sn2
        return K
    else:
        # D = (X1 - X2).sum(1)
        if X1 is X2:
            K = tt.ones((X1.shape[0],))*sn2
        else:
            K = 0
        return K

    # K = tt.eq(D,0)*sn2
    # return K 
开发者ID:mcgillmrl,项目名称:kusanagi,代码行数:23,代码来源:cov.py

示例11: equal

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def equal(x, y):
    return T.eq(x, y) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:4,代码来源:theano_backend.py

示例12: get_output_mask

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def get_output_mask(self, train=False):
        X = self.get_input(train)
        return T.any(T.ones_like(X) * (1. - T.eq(X, self.mask_value)), axis=-1) 
开发者ID:lllcho,项目名称:CAPTCHA-breaking,代码行数:5,代码来源:core.py

示例13: get_output_mask

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def get_output_mask(self, train=None):
        X = self.get_input(train)
        if not self.mask_zero:
            return None
        else:
            return T.ones_like(X) * (1 - T.eq(X, 0)) 
开发者ID:lllcho,项目名称:CAPTCHA-breaking,代码行数:8,代码来源:embeddings.py

示例14: more_complex_test

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def more_complex_test():
    notimpl = NotImplementedOp()
    ifelseifelseif = IfElseIfElseIf()

    x1 = T.scalar('x1')
    x2 = T.scalar('x2')
    c1 = T.scalar('c1')
    c2 = T.scalar('c2')
    t1 = ifelse(c1, x1, notimpl(x2))
    t1.name = 't1'
    t2 = t1 * 10
    t2.name = 't2'
    t3 = ifelse(c2, t2, x1 + t1)
    t3.name = 't3'
    t4 = ifelseifelseif(T.eq(x1, x2), x1, T.eq(x1, 5), x2, c2, t3, t3 + 0.5)
    t4.name = 't4'

    f = function([c1, c2, x1, x2], t4, mode=Mode(linker='vm',
                                                 optimizer='fast_run'))
    if theano.config.vm.lazy is False:
        try:
            f(1, 0, numpy.array(10, dtype=x1.dtype), 0)
            assert False
        except NotImplementedOp.E:
            pass
    else:
        print(f(1, 0, numpy.array(10, dtype=x1.dtype), 0))
        assert f(1, 0, numpy.array(10, dtype=x1.dtype), 0) == 20.5
    print('... passed') 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:31,代码来源:test_lazy.py

示例15: fft

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import eq [as 别名]
def fft(z):
	B      = z.shape[0]//2
	L      = z.shape[1]
	C      = TT.as_tensor_variable(np.asarray([[[1,-1]]], dtype=T.config.floatX))
	Zr, Zi = TTF.rfft(z[:B], norm="ortho"), TTF.rfft(z[B:], norm="ortho")
	isOdd  = TT.eq(L%2, 1)
	Zr     = TI.ifelse(isOdd, TT.concatenate([Zr, C*Zr[:,1:  ][:,::-1]], axis=1),
	                          TT.concatenate([Zr, C*Zr[:,1:-1][:,::-1]], axis=1))
	Zi     = TI.ifelse(isOdd, TT.concatenate([Zi, C*Zi[:,1:  ][:,::-1]], axis=1),
	                          TT.concatenate([Zi, C*Zi[:,1:-1][:,::-1]], axis=1))
	Zi     = (C*Zi)[:,:,::-1]  # Zi * i
	Z      = Zr+Zi
	return TT.concatenate([Z[:,:,0], Z[:,:,1]], axis=0) 
开发者ID:ChihebTrabelsi,项目名称:deep_complex_networks,代码行数:15,代码来源:fft.py


注:本文中的theano.tensor.eq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。