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


Python tensor.add方法代码示例

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


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

示例1: build_bilinear_net

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def build_bilinear_net(input_shapes, X_var=None, U_var=None, X_diff_var=None, axis=1):
    x_shape, u_shape = input_shapes
    X_var = X_var or T.tensor4('X')
    U_var = U_var or T.matrix('U')
    X_diff_var = X_diff_var or T.tensor4('X_diff')
    X_next_var = X_var + X_diff_var

    l_x = L.InputLayer(shape=(None,) + x_shape, input_var=X_var)
    l_u = L.InputLayer(shape=(None,) + u_shape, input_var=U_var)

    l_x_diff_pred = LT.BilinearLayer([l_x, l_u], axis=axis)
    l_x_next_pred = L.ElemwiseMergeLayer([l_x, l_x_diff_pred], T.add)
    l_y = L.flatten(l_x)
    l_y_diff_pred = L.flatten(l_x_diff_pred)

    X_next_pred_var = lasagne.layers.get_output(l_x_next_pred)
    loss = ((X_next_var - X_next_pred_var) ** 2).mean(axis=0).sum() / 2.

    net_name = 'BilinearNet'
    input_vars = OrderedDict([(var.name, var) for var in [X_var, U_var, X_diff_var]])
    pred_layers = OrderedDict([('y_diff_pred', l_y_diff_pred), ('y', l_y), ('x0_next_pred', l_x_next_pred)])
    return net_name, input_vars, pred_layers, loss 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:24,代码来源:net_theano.py

示例2: create_structure

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def create_structure(self):
        """Creates the symbolic graph of this layer.

        Sets self.output to a symbolic matrix that describes the output of this
        layer. If the inputs are the same size as the output, the output will be
        the elementwise sum of the inputs. If needed, the inputs will be
        projected to the same size.
        """

        for input_index, input_layer in enumerate(self._input_layers):
            input_size = input_layer.output_size
            if input_size == self.output_size:
                input_matrix = input_layer.output
            else:
                input_matrix = self._tensor_preact(input_layer.output,
                                                   'input{}'.format(input_index),
                                                   use_bias=False)

            if self.output is None:
                self.output = input_matrix
            else:
                self.output = tensor.add(self.output, input_matrix) 
开发者ID:senarvi,项目名称:theanolm,代码行数:24,代码来源:additionlayer.py

示例3: rbf_kernel

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def rbf_kernel(X):

    XY = T.dot(X, X.T)
    x2 = T.sum(X**2, axis=1).dimshuffle(0, 'x')
    X2e = T.repeat(x2, X.shape[0], axis=1)
    H = X2e +  X2e.T - 2. * XY

    V = H.flatten()
    # median distance
    h = T.switch(T.eq((V.shape[0] % 2), 0),
        # if even vector
        T.mean(T.sort(V)[ ((V.shape[0] // 2) - 1) : ((V.shape[0] // 2) + 1) ]),
        # if odd vector
        T.sort(V)[V.shape[0] // 2])

    h = T.sqrt(.5 * h / T.log(H.shape[0].astype('float32') + 1.)) 
    
    # compute the rbf kernel
    kxy = T.exp(-H / (h ** 2) / 2.0)

    dxkxy = -T.dot(kxy, X)
    sumkxy = T.sum(kxy, axis=1).dimshuffle(0, 'x')
    dxkxy = T.add(dxkxy, T.mul(X, sumkxy)) / (h ** 2)

    return kxy, dxkxy 
开发者ID:DartML,项目名称:SteinGAN,代码行数:27,代码来源:rbm_adv.py

示例4: input_to_h_from_v

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def input_to_h_from_v(self, v):
        """
        .. todo::

            WRITEME
        """
        D = self.Lambda
        alpha = self.alpha

        def sum_s(x):
            return x.reshape((
                -1,
                self.nhid,
                self.n_s_per_h)).sum(axis=2)

        return tensor.add(
                self.b,
                -0.5 * tensor.dot(v * v, D),
                sum_s(self.mu * tensor.dot(v, self.W)),
                sum_s(0.5 * tensor.sqr(tensor.dot(v, self.W)) / alpha))

    #def mean_h_given_v(self, v):
    #    inherited version is OK:
    #    return nnet.sigmoid(self.input_to_h_from_v(v)) 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:26,代码来源:rbm.py

示例5: free_energy_given_v

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def free_energy_given_v(self, v):
        """
        .. todo::

            WRITEME
        """
        sigmoid_arg = self.input_to_h_from_v(v)
        return tensor.add(
                0.5 * (self.B * (v ** 2)).sum(axis=1),
                -tensor.nnet.softplus(sigmoid_arg).sum(axis=1))

    #def __call__(self, v):
    #    inherited version is OK

    #def reconstruction_error:
    #    inherited version should be OK

    #def params(self):
    #    inherited version is OK. 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:21,代码来源:rbm.py

示例6: sequence_iteration

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def sequence_iteration(self, output, mask,use_dropout=0,dropout_value=0.5):

        dot_product = T.dot(output , self.t_w_out)

        net_o = T.add( dot_product , self.t_b_out )

        ex_net = T.exp(net_o)
        sum_net = T.sum(ex_net, axis=2, keepdims=True)
        softmax_o = ex_net / sum_net


        mask = T.addbroadcast(mask, 2) # to do nesseccary?
        output = T.mul(mask, softmax_o)   + T.mul( (1. - mask) , 1e-6 )

        return output #result


######                     Linear Layer
######################################## 
开发者ID:JoergFranke,项目名称:recnet,代码行数:21,代码来源:output_layer.py

示例7: sequence_iteration

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def sequence_iteration(self, in_seq, mask, use_dropout,dropout_value=1):

        in_seq_d = T.switch(use_dropout,
                             (in_seq *
                              self.trng.binomial(in_seq.shape,
                                            p=dropout_value, n=1,
                                            dtype=in_seq.dtype)),
                             in_seq)

        rz_in_seq =  T.add( T.dot(in_seq_d, self.weights[0]) , self.weights[1] )

        out_seq, updates = theano.scan(
                                        fn=self.t_forward_step,
                                        sequences=[mask, rz_in_seq],  # in_seq_d],
                                        outputs_info=[self.t_ol_t00],
                                        non_sequences=[i for i in self.weights][2:] + [self.t_n_out],
                                        go_backwards = self.go_backwards,
                                        truncate_gradient=-1,
                                        #n_steps=50,
                                        strict=True,
                                        allow_gc=False,
                                        )
        return out_seq 
开发者ID:JoergFranke,项目名称:recnet,代码行数:25,代码来源:recurrent_layer.py

示例8: fit

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def fit(self, weights, o_error, tpo ):

        gradients = T.grad(o_error ,weights)
        updates = []
        for c, v, w, g in zip(self.t_cache, self.t_velocity, weights,gradients):
            new_velocity = T.sub( T.mul(tpo["momentum_rate"], v) , T.mul(tpo["learn_rate"], g) )
            new_cache = T.add( T.mul(tpo["decay_rate"] , c) , T.mul(T.sub( 1, tpo["decay_rate"]) , T.sqr(g)))
            new_weights = T.sub(T.add(w , new_velocity) , T.true_div( T.mul(g,tpo["learn_rate"]) , T.sqrt(T.add(new_cache,0.1**8))))
            updates.append((w, new_weights))
            updates.append((v, new_velocity))
            updates.append((c, new_cache))

        return updates


######                 Nesterov momentum
######################################## 
开发者ID:JoergFranke,项目名称:recnet,代码行数:19,代码来源:update_function.py

示例9: __init__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def __init__(self, net, mixfrac=1.0, maxiter=25):
        EzPickle.__init__(self, net, mixfrac, maxiter)
        self.net = net
        self.mixfrac = mixfrac

        x_nx = net.input
        self.predict = theano.function([x_nx], net.output, **FNOPTS)

        ypred_ny = net.output
        ytarg_ny = T.matrix("ytarg")
        var_list = net.trainable_weights
        l2 = 1e-3 * T.add(*[T.square(v).sum() for v in var_list])
        N = x_nx.shape[0]
        mse = T.sum(T.square(ytarg_ny - ypred_ny))/N
        symb_args = [x_nx, ytarg_ny]
        loss = mse + l2
        self.opt = LbfgsOptimizer(loss, var_list, symb_args, maxiter=maxiter, extra_losses={"mse":mse, "l2":l2}) 
开发者ID:joschu,项目名称:modular_rl,代码行数:19,代码来源:core.py

示例10: __add__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def __add__(left, right):
        return add(left, right) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:4,代码来源:basic.py

示例11: __radd__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def __radd__(right, left):
        return add(left, right) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:4,代码来源:basic.py

示例12: test_softmax_optimizations_w_bias2

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def test_softmax_optimizations_w_bias2(self):
        x = tensor.matrix('x')
        b = tensor.vector('b')
        c = tensor.vector('c')
        one_of_n = tensor.lvector('one_of_n')
        op = crossentropy_categorical_1hot

        fgraph = gof.FunctionGraph(
                [x, b, c, one_of_n],
                [op(softmax_op(T.add(x, b, c)), one_of_n)])
        assert fgraph.outputs[0].owner.op == op

        # print 'BEFORE'
        # for node in fgraph.toposort():
        #    print node.op
        # print '----'

        theano.compile.mode.optdb.query(
                theano.compile.mode.OPT_FAST_RUN).optimize(fgraph)

        # print 'AFTER'
        # for node in fgraph.toposort():
        #    print node.op
        # print '===='
        assert len(fgraph.toposort()) == 3

        assert str(fgraph.outputs[0].owner.op) == 'OutputGuard'
        assert (fgraph.outputs[0].owner.inputs[0].owner.op ==
                crossentropy_softmax_argmax_1hot_with_bias) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:31,代码来源:test_nnet.py

示例13: set_layer_param_tags

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def set_layer_param_tags(layer, params=None, **tags):
    """
    If params is None, update tags of all parameters, else only update tags of parameters in params.
    """
    for param, param_tags in layer.params.items():
        if params is None or param in params:
            for tag, value in tags.items():
                if value:
                    param_tags.add(tag)
                else:
                    param_tags.discard(tag) 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:13,代码来源:layers_theano.py

示例14: __init__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def __init__(self, incomings, **kwargs):
        super(BatchwiseSumLayer, self).__init__(incomings, T.add, **kwargs) 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:4,代码来源:layers_theano.py

示例15: __init__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import add [as 别名]
def __init__(self, x, y, args):
        self.params_theta = []
        self.params_lambda = []
        self.params_weight = []
        if args.dataset == 'mnist':
            input_size = (None, 1, 28, 28)
        elif args.dataset == 'cifar10':
            input_size = (None, 3, 32, 32)
        else:
            raise AssertionError
        layers = [ll.InputLayer(input_size)]
        self.penalty = theano.shared(np.array(0.))

        #conv1
        layers.append(Conv2DLayerWithReg(args, layers[-1], 20, 5))
        self.add_params_to_self(args, layers[-1])
        layers.append(ll.MaxPool2DLayer(layers[-1], pool_size=2, stride=2))
        #conv1
        layers.append(Conv2DLayerWithReg(args, layers[-1], 50, 5))
        self.add_params_to_self(args, layers[-1])
        layers.append(ll.MaxPool2DLayer(layers[-1], pool_size=2, stride=2))
        #fc1
        layers.append(DenseLayerWithReg(args, layers[-1], num_units=500))
        self.add_params_to_self(args, layers[-1])
        #softmax
        layers.append(DenseLayerWithReg(args, layers[-1], num_units=10, nonlinearity=nonlinearities.softmax))
        self.add_params_to_self(args, layers[-1])

        self.layers = layers
        self.y = ll.get_output(layers[-1], x, deterministic=False)
        self.prediction = T.argmax(self.y, axis=1)
        # self.penalty = penalty if penalty != 0. else T.constant(0.)
        print(self.params_lambda)
        # time.sleep(20)
        # cost function
        self.loss = T.mean(categorical_crossentropy(self.y, y))
        self.lossWithPenalty = T.add(self.loss, self.penalty)
        print "loss and losswithpenalty", type(self.loss), type(self.lossWithPenalty) 
开发者ID:bigaidream-projects,项目名称:drmad,代码行数:40,代码来源:models.py


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