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


Python tensor.dot方法代碼示例

本文整理匯總了Python中theano.tensor.dot方法的典型用法代碼示例。如果您正苦於以下問題:Python tensor.dot方法的具體用法?Python tensor.dot怎麽用?Python tensor.dot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在theano.tensor的用法示例。


在下文中一共展示了tensor.dot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: step

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def step(self,x, h_tm1,c_tm1):
#{{{
        z=T.dot(x,self.W)+T.dot(h_tm1,self.U)+self.b;
        if self.with_batch:
            z_i=z[:,:self.output_dim];
            z_c=z[:,self.output_dim:2*self.output_dim];
            z_o=z[:,2*self.output_dim:];
        else:
            z_i=z[:self.output_dim];
            z_c=z[self.output_dim:2*self.output_dim];
            z_o=z[2*self.output_dim:];

        i_t = self.inner_activation(z_i +
                                 T.dot(c_tm1, self.w_ci))
        # f_t = T.nnet.sigmoid(T.dot(x_t, self.w_xf) +
        #                      T.dot(h_tm1, self.w_hf) +
        #                      T.dot(c_tm1, self.w_cf) +
        #                      self.b_f)
        c_t = (1 - i_t) * c_tm1 + i_t * self.activation(z_c)
        o_t = self.inner_activation(z_o +
                                 T.dot(c_t, self.w_co))
        h_t = o_t * self.activation(c_t)
        return  h_t,c_t
#}}} 
開發者ID:lingluodlut,項目名稱:Att-ChemdNER,代碼行數:26,代碼來源:nn.py

示例2: infer

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def infer(self, x):
        (nfilt, fc, fi, fj) = self.filter_shape
        if (fi, fj) == (1, 1):#如果卷積核的大小為1*1的情況
            W = self.W.reshape((nfilt, fc))
            (bsize, nc, ni, nj) = x.shape
            xvec = x.transpose((1,0,2,3)).reshape((nc, bsize*ni*nj))
            if self.transpose:
                y = T.dot(W.T, xvec)
                y = y.reshape((fc, bsize, ni, nj)).transpose((1,0,2,3))
            else:
                y = T.dot(W, xvec)
                y = y.reshape((nfilt, bsize, ni, nj)).transpose((1,0,2,3))
            y = thutil.gpu_contiguous(y)
        else:#正常的卷積層
            y = conv(x, self.W, border_mode=self.conv_mode,
                                transpose=self.transpose,
                                stride=self.stride)
        if self.have_bias:
            y += self.b.reshape((1, self.b.shape[0], 1, 1))
        return y

#全連接層 
開發者ID:hjimce,項目名稱:Depth-Map-Prediction,代碼行數:24,代碼來源:net.py

示例3: setUp

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def setUp(self):
        if 'gpu' not in theano.config.device:
            raise RuntimeError("Thin stack only defined for GPU usage")

        self.embedding_dim = self.model_dim = 2
        self.vocab_size = 5
        self.seq_length = 5
        self.batch_size = 2
        self.num_classes = 2

        spec = util.ModelSpec(self.model_dim, self.embedding_dim,
                              self.batch_size, self.vocab_size,
                              self.seq_length)

        self.vs = vs = VariableStore()
        def compose_network((c1, c2), *args, **kwargs):
            W = vs.add_param("W", (self.model_dim * 2, self.model_dim))
            b = vs.add_param("b", (self.model_dim,),
                             initializer=util.ZeroInitializer())
            return T.dot(T.concatenate([c1, c2], axis=1), W) + b 
開發者ID:stanfordnlp,項目名稱:spinn,代碼行數:22,代碼來源:test_stack.py

示例4: Linear

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def Linear(inp, inp_dim, outp_dim, vs, name="linear_layer", use_bias=True, initializer=None, bias_initializer=None):
    if isinstance(inp, tuple):
        assert isinstance(inp_dim, tuple)
        # Build initializers which are aware of the real shape of the overall
        # (unsplit) matrix.
        real_inp_dim = sum(inp_dim)
        initializer = partial(initializer or vs.default_initializer,
                              real_shape=(real_inp_dim, outp_dim))

        try:
            Ws = [vs.add_param("%s_W%i" % (name, i), (dim_i, outp_dim),
                               initializer=initializer)
                  for i, dim_i in enumerate(inp_dim)]
        except TypeError, e:
            raise RuntimeError(
                "TypeError in vs initialization for split Gemm. Does the "
                "initializer you provided (%s) support real_shape?"
                % initializer, e)

        outp = T.dot(inp[0], Ws[0])
        for inp_i, W_i in zip(inp[1:], Ws[1:]):
            # TODO inplace add?
            outp += T.dot(inp_i, W_i) 
開發者ID:stanfordnlp,項目名稱:spinn,代碼行數:25,代碼來源:blocks.py

示例5: _create_observation_variable

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def _create_observation_variable(individual_selections, choices, partsworth):
    """
    This function handles creating the PyMC3 observation variables.  It also gracefully handles missing observations in individual selections.

    `individual_selections` is a Series of the individuals selections made, starting from 0. It can contain NaNs which represent answer was not provided.

    `choices` is a DataFrame with a hierarchical index: level=0 enumerates the choices, and level=1 displays the profile at a specific choice.
    It's size is (n_questions, n_choices_per_question).

    `partsworth` is a slice of PyMC3 matrix. It represents the partsworth variables of a individual. Size is (n_profiles,)

    This computes the values exp(partsworth * profile_j) / sum[ exp(partsworth * profile_k ] for all j.
    """
    nan_mask = pd.notnull(individual_selections)
    return pm.Categorical("Obs_%s" % individual_selections.name,
                          tt.nnet.softmax(tt.stack([
                            tt.dot(choice.values, partsworth) for _, choice in choices[nan_mask.values].groupby(axis=1, level=0)
                          ], axis=0).T),
                          observed=individual_selections[nan_mask.values].values) 
開發者ID:CamDavidsonPilon,項目名稱:lifestyles,代碼行數:21,代碼來源:cbc_hb.py

示例6: set_output

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def set_output(self):
        padding = self._padding
        input_shape = self._input_shape
        padded_input = tensor.alloc(0.0,  # Value to fill the tensor
                                    input_shape[0],
                                    input_shape[1] + 2 * padding[1],
                                    input_shape[2],
                                    input_shape[3] + 2 * padding[3],
                                    input_shape[4] + 2 * padding[4])

        padded_input = tensor.set_subtensor(padded_input[:, padding[1]:padding[1] + input_shape[
            1], :, padding[3]:padding[3] + input_shape[3], padding[4]:padding[4] + input_shape[4]],
                                            self._prev_layer.output)

        fc_output = tensor.reshape(
            tensor.dot(self._fc_layer.output, self.Wx.val), self._output_shape)
        self._output = conv3d2d.conv3d(padded_input, self.Wh.val) + \
            fc_output + self.b.val.dimshuffle('x', 'x', 0, 'x', 'x') 
開發者ID:chrischoy,項目名稱:3D-R2N2,代碼行數:20,代碼來源:layers.py

示例7: get_output_for

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def get_output_for(self, input, init=False, deterministic=False, **kwargs):
        if input.ndim > 2:
            # if the input has more than two dimensions, flatten it into a
            # batch of feature vectors.
            input = input.flatten(2)

        activation = T.dot(input, self.W)

        if init:
            ma = T.mean(activation, axis=0)
            activation -= ma.dimshuffle('x',0)
            stdv = T.sqrt(T.mean(T.square(activation),axis=0))
            activation /= stdv.dimshuffle('x',0)
            self.init_updates = [(self.weight_scale, self.weight_scale/stdv), (self.b, -ma/stdv)]
        else:
            activation += self.b.dimshuffle('x', 0)

        return self.nonlinearity(activation) 
開發者ID:djsutherland,項目名稱:opt-mmd,代碼行數:20,代碼來源:nn.py

示例8: linear_mmd2_and_hotelling

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def linear_mmd2_and_hotelling(X, Y, biased=True, reg=0):
    if not biased:
        raise ValueError("linear_mmd2_and_hotelling only works for biased est")

    n = X.shape[0]
    p = X.shape[1]
    Z = X - Y
    Z_bar = Z.mean(axis=0)
    mmd2 = Z_bar.dot(Z_bar)

    Z_cent = Z - Z_bar
    S = Z_cent.T.dot(Z_cent) / (n - 1)
    # z' inv(S) z = z' inv(L L') z = z' inv(L)' inv(L) z = ||inv(L) z||^2
    L = slinalg.cholesky(S + reg * T.eye(p))
    Linv_Z_bar = slinalg.solve_lower_triangular(L, Z_bar)
    lambda_ = n * Linv_Z_bar.dot(Linv_Z_bar)
    # happens on the CPU!
    return mmd2, lambda_ 
開發者ID:djsutherland,項目名稱:opt-mmd,代碼行數:20,代碼來源:mmd.py

示例9: gen

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def gen(_z, _params, n_layers=3, n_f=128, init_sz=4, nc=3):
    [gw0, gg0, gb0] = _params[0:3]
    hs = []
    h0 = relu(batchnorm(T.dot(_z, gw0), g=gg0, b=gb0))
    h1 = h0.reshape((h0.shape[0], n_f * 2 ** n_layers, init_sz, init_sz))
    hs.extend([h0, h1])
    for n in range(n_layers):
        [w, g, b] = _params[3 * (n + 1):3 * (n + 2)]
        hin = hs[-1]
        hout = relu(batchnorm(deconv(hin, w, subsample=(2, 2), border_mode=(2, 2)), g=g, b=b))
        hs.append(hout)
    x = deconv(hs[-1], _params[-1], subsample=(2, 2), border_mode=(2, 2))

    if nc == 3:
        x_f = tanh(x)
    if nc == 1:
        x_f = sigmoid(x)
    return x_f 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:20,代碼來源:train_dcgan_utils.py

示例10: gen_batchnorm

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def gen_batchnorm(_z, _params, n_layers=3, n_f=128, init_sz=4, nc=3):
    [gw0, gg0, gb0] = _params[0:3]
    hs = []
    h0_o = T.dot(_z, gw0)
    output = [h0_o]
    h0 = relu(batchnorm(h0_o, g=gg0, b=gb0))
    h1 = h0.reshape((h0.shape[0], n_f * 2 ** n_layers, init_sz, init_sz))
    hs.extend([h0, h1])
    for n in range(n_layers):
        [w, g, b] = _params[3 * (n + 1):3 * (n + 2)]
        hin = hs[-1]
        h_o = deconv(hin, w, subsample=(2, 2), border_mode=(2, 2))
        hout = relu(batchnorm(h_o, g=g, b=b))
        hs.append(hout)
        output.append(h_o)

    if nc == 3:
        x = tanh(deconv(hs[-1], _params[-1], subsample=(2, 2), border_mode=(2, 2)))
    if nc == 1:
        x = sigmoid(deconv(hs[-1], _params[-1], subsample=(2, 2), border_mode=(2, 2)))

    return x, output 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:24,代碼來源:train_dcgan_utils.py

示例11: gen_test

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def gen_test(_z, _params, _bn, n_layers=3, n_f=128, init_sz=4):
    [gw0, gg0, gb0] = _params[0:3]
    hs = []
    u = _bn[0]
    s = _bn[n_layers + 1]
    h0 = relu(batchnorm(T.dot(T.clip(_z, -1.0, 1.0), gw0), u=u, s=s, g=gg0, b=gb0))
    h1 = h0.reshape((h0.shape[0], n_f * 2 ** n_layers, init_sz, init_sz))
    hs.extend([h0, h1])
    for n in range(n_layers):
        [w, g, b] = _params[3 * (n + 1):3 * (n + 2)]
        hin = hs[-1]
        u = _bn[n + 1]
        s = _bn[n + n_layers + 2]
        hout = relu(batchnorm(deconv(hin, w, subsample=(2, 2), border_mode=(2, 2)), u=u, s=s, g=g, b=b))
        hs.append(hout)
    x = tanh(deconv(hs[-1], _params[-1], subsample=(2, 2), border_mode=(2, 2)))
    return x 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:19,代碼來源:train_dcgan_utils.py

示例12: gen_test

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def gen_test(_z, _params, _batchnorm, n_layers=3, n_f=128, init_sz=4, nc=3, use_tanh=False):
    if use_tanh:
        _z = tanh(_z)
    [gw0, gg0, gb0] = _params[0:3]
    hs = []
    u = _batchnorm[0]
    s = _batchnorm[n_layers + 1]
    h0 = relu(batchnorm(T.dot(T.clip(_z, -1.0, 1.0), gw0), u=u, s=s, g=gg0, b=gb0))
    h1 = h0.reshape((h0.shape[0], n_f * 2 ** n_layers, init_sz, init_sz))
    hs.extend([h0, h1])
    for n in range(n_layers):
        [w, g, b] = _params[3 * (n + 1):3 * (n + 2)]
        hin = hs[-1]
        u = _batchnorm[n + 1]
        s = _batchnorm[n + n_layers + 2]
        hout = relu(batchnorm(deconv(hin, w, subsample=(2, 2), border_mode=(2, 2)), u=u, s=s, g=g, b=b))
        hs.append(hout)
    x = deconv(hs[-1], _params[-1], subsample=(2, 2), border_mode=(2, 2))
    if nc == 3:
        x_f = tanh(x)
    if nc == 1:
        x_f = sigmoid(x)
    return x_f 
開發者ID:junyanz,項目名稱:iGAN,代碼行數:25,代碼來源:dcgan_theano.py

示例13: nn

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def nn(model, text, vectors, query, k=5):
	"""
	Return the nearest neighbour sentences to query
	text: list of sentences
	vectors: the corresponding representations for text
	query: a string to search
	"""
	qf = encode(model, [query])
	qf /= norm(qf)
	scores = numpy.dot(qf, vectors.T).flatten()
	sorted_args = numpy.argsort(scores)[::-1]
	sentences = [text[a] for a in sorted_args[:k]]
	print 'QUERY: ' + query
	print 'NEAREST: '
	for i, s in enumerate(sentences):
		print s, sorted_args[i] 
開發者ID:hanzhanggit,項目名稱:StackGAN,代碼行數:18,代碼來源:skipthoughts.py

示例14: model

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def model(X, w, w2, w3, w4, p_drop_conv, p_drop_hidden):
    l1a = rectify(conv2d(X, w, border_mode='full'))
    l1 = max_pool_2d(l1a, (2, 2))
    l1 = dropout(l1, p_drop_conv)

    l2a = rectify(conv2d(l1, w2))
    l2 = max_pool_2d(l2a, (2, 2))
    l2 = dropout(l2, p_drop_conv)

    l3a = rectify(conv2d(l2, w3))
    l3b = max_pool_2d(l3a, (2, 2))
    l3 = T.flatten(l3b, outdim=2)
    l3 = dropout(l3, p_drop_conv)

    l4 = rectify(T.dot(l3, w4))
    l4 = dropout(l4, p_drop_hidden)

    pyx = softmax(T.dot(l4, w_o))
    return l1, l2, l3, l4, pyx 
開發者ID:Newmu,項目名稱:Theano-Tutorials,代碼行數:21,代碼來源:5_convolutional_net.py

示例15: get_output

# 需要導入模塊: from theano import tensor [as 別名]
# 或者: from theano.tensor import dot [as 別名]
def get_output(self, train=False):
        X = self.get_input(train)  # shape: (nb_samples, time (padded with zeros), input_dim)
        # new shape: (time, nb_samples, input_dim) -> because theano.scan iterates over main dimension
        padded_mask = self.get_padded_shuffled_mask(train, X, pad=1)
        X = X.dimshuffle((1, 0, 2))
        x = T.dot(X, self.W) + self.b

        # scan = theano symbolic loop.
        # See: http://deeplearning.net/software/theano/library/scan.html
        # Iterate over the first dimension of the x array (=time).
        outputs, updates = theano.scan(
            self._step,  # this will be called with arguments (sequences[i], outputs[i-1], non_sequences[i])
            sequences=[x, dict(input=padded_mask, taps=[-1])],  # tensors to iterate over, inputs to _step
            # initialization of the output. Input to _step with default tap=-1.
            outputs_info=T.unbroadcast(alloc_zeros_matrix(X.shape[1], self.output_dim), 1),
            non_sequences=self.U,  # static inputs to _step
            truncate_gradient=self.truncate_gradient)

        if self.return_sequences:
            return outputs.dimshuffle((1, 0, 2))
        return outputs[-1] 
開發者ID:lllcho,項目名稱:CAPTCHA-breaking,代碼行數:23,代碼來源:recurrent.py


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