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


Python tensor.repeat方法代码示例

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


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

示例1: step

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def step(self, word,h_tm1,c_tm1,x):
#{{{
        H=x;
        input_length=x.shape[0];
        C=T.repeat(c_tm1.reshape((1,-1)),input_length,axis=0);
        _HC=K.concatenate([H,C]);
        energy=T.dot(_HC,self.W_A.reshape((-1,1)))+self.b_A;
        energy=K.softmax(energy.reshape((1,-1)));
        x=(H*energy.reshape((-1,1))).sum(axis=0)

        #combine glimpsed with word;
        combine=K.concatenate([x,word]);
        combined=K.dot(combine,self.W_combine)+self.b_combine;
        #original LSTM step
        h_t,c_t=super(AttentionLSTM,self).step_noBatch(combined,h_tm1,c_tm1);
        return  h_t,c_t
#}}} 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:19,代码来源:nn.py

示例2: TestMyTile

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def TestMyTile():
    x = T.matrix('x')
    y = T.iscalar('y')
    z = MyTile(x, (y, y))

    f=theano.function([x, y], z)
    a = np.array([ [11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34] ] ).astype(theano.config.floatX)
    b = 3
    c = f(a, b)

    print a
    print c
    print c.shape

    x3d = T.tensor3('x3d')
    g = theano.function([x3d, y], MyTile(x3d, (y, y)) )
    a = np.random.uniform(0, 1, (3, 3, 2)).astype(theano.config.floatX)
    c = g(a, b)
    print c.shape
    print c[:,:,0]
    print c[:,:,1]


##repeat each element in x by reps at the axis given by axes 
开发者ID:j3xugit,项目名称:RaptorX-Contact,代码行数:26,代码来源:utils.py

示例3: mean_step

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def mean_step(self, x_t, m_t, *args):
        args = iter(args)
        
        # already computed avg 
        avg_past = next(args)
        n_past = next(args)

        if m_t.ndim >= 1:
            m_t = m_t.dimshuffle(0, 'x') 
        
        # reset avg
        avg_past_r = m_t * avg_past 
        n_past_r = m_t.T * n_past


        n = n_past_r + 1.0

        resized_n = T.repeat(n.T, avg_past_r.shape[1], axis=1)
        avg = (avg_past_r * (resized_n - 1) + x_t) / resized_n

        # Old implementation:
        #avg = (avg_past_r * (n[:, None] - 1) + x_t) / n[:, None]

        # return state and pooled state
        return avg, n 
开发者ID:julianser,项目名称:hred-latent-piecewise,代码行数:27,代码来源:dialog_encdec.py

示例4: rbf_kernel

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def rbf_kernel(X0):
    XY = T.dot(X0, X0.transpose())
    x2 = T.reshape(T.sum(T.square(X0), axis=1), (X0.shape[0], 1))
    X2e = T.repeat(x2, X0.shape[0], axis=1)
    H = T.sub(T.add(X2e, X2e.transpose()), 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(0.5 * h / T.log(X0.shape[0].astype('float32') + 1.0)) / 2.

    Kxy = T.exp(-H / h ** 2 / 2.0)
    neighbors = T.argsort(H, axis=1)[:, 1]

    return Kxy, neighbors, h 
开发者ID:DartML,项目名称:SteinGAN,代码行数:23,代码来源:steingan_celeba.py

示例5: rbf_kernel

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [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

示例6: set_rest_ref_matrix

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def set_rest_ref_matrix(self, number_of_points_per_surface):
        ref_positions = T.cumsum(T.concatenate((T.stack([0]), number_of_points_per_surface[:-1] + 1)))
        cum_rep = T.cumsum(T.concatenate((T.stack([0]), number_of_points_per_surface)))

        ref_points_init = T.zeros((cum_rep[-1], 3))
        ref_points_loop, update_ = theano.scan(self.repeat_list,
                                               outputs_info=[ref_points_init],
                                               sequences=[self.surface_points_all[ref_positions],
                                                          dict(input=cum_rep, taps=[0, 1])],
                                               non_sequences=[T.as_tensor(3)],

                                               return_list=False)

        #   ref_points_loop = theano.printing.Print('loop')(ref_points_loop)
        ref_points = ref_points_loop[-1]
        #  ref_points = T.repeat(self.surface_points_all[ref_positions], number_of_points_per_surface, axis=0)

        rest_mask = T.ones(T.stack([self.surface_points_all.shape[0]]), dtype='int16')
        rest_mask = T.set_subtensor(rest_mask[ref_positions], 0)
        rest_mask = T.nonzero(rest_mask)[0]
        rest_points = self.surface_points_all[rest_mask]
        return [ref_points, rest_points, ref_positions, rest_mask] 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:24,代码来源:theano_graph_pro.py

示例7: mean_step

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def mean_step(self, x_t, m_t, *args):
        args = iter(args)
        
        # already computed avg 
        avg_past = next(args)
        n_past = next(args)

        if m_t.ndim >= 1:
            m_t = m_t.dimshuffle(0, 'x') 
        
        # reset avg
        avg_past_r = m_t * avg_past 
        n_past_r = m_t.T * n_past


        n = n_past_r + 1.

        resized_n = T.repeat(n.T, avg_past_r.shape[1], axis=1)
        avg = (avg_past_r * (resized_n - 1) + x_t) / resized_n

        # Old implementation:
        #avg = (avg_past_r * (n[:, None] - 1) + x_t) / n[:, None]

        # return state and pooled state
        return avg, n 
开发者ID:julianser,项目名称:hed-dlg-truncated,代码行数:27,代码来源:dialog_encdec.py

示例8: forwardNNScore

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def forwardNNScore(self,attended,state,W):
#{{{
        #get weights
        W_1=W[:(self.attended_dim+self.state_dim)*self.state_dim]; 
        W_1=W_1.reshape((self.attended_dim+self.state_dim,self.state_dim));
        W_2=W[(self.attended_dim+self.state_dim)*self.state_dim:];
        
        #forward neural network 
        state_=T.repeat(state.reshape((1,-1)),attended.shape[0],axis=0);
        input=T.concatenate([attended,state_],axis=-1);
        M1=self.atten_activation(T.dot(input,W_1));
        M2=self.atten_activation(T.dot(M1,W_2));
        _energy=M2;
        return _energy;
    #}}} 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:17,代码来源:nn.py

示例9: CNNScore

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def CNNScore(self,attended,state,W):
#{{{
        state_=T.repeat(state.reshape((1,-1)),attended.shape[0],axis=0);
        input=T.concatenate([attended,state_],axis=-1);
        M1=self.CNN1.call(input);
        M2=self.CNN2.call(M1);
        _energy=M2.flatten();
        return _energy;
#}}} 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:11,代码来源:nn.py

示例10: repeat_elements

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def repeat_elements(x, rep, axis):
    '''Repeat the elements of a tensor along an axis, like np.repeat.

    If x has shape (s1, s2, s3) and axis=1, the output
    will have shape (s1, s2 * rep, s3).
    '''
    # TODO: `keras_shape` inference.
    return T.repeat(x, rep, axis=axis) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:10,代码来源:theano_backend.py

示例11: repeat_elements

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def repeat_elements(x, rep, axis):
    '''Repeat the elements of a tensor along an axis, like np.repeat.

    If x has shape (s1, s2, s3) and axis=1, the output
    will have shape (s1, s2 * rep, s3).
    '''
    return T.repeat(x, rep, axis=axis) 
开发者ID:mathDR,项目名称:reading-text-in-the-wild,代码行数:9,代码来源:theano_backend.py

示例12: repeat

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def repeat(x, n):
    '''Repeat a 2D tensor.

    If x has shape (samples, dim) and n=2,
    the output will have shape (samples, 2, dim).
    '''
    assert x.ndim == 2
    x = x.dimshuffle((0, 'x', 1))
    return T.extra_ops.repeat(x, n, axis=1) 
开发者ID:mathDR,项目名称:reading-text-in-the-wild,代码行数:11,代码来源:theano_backend.py

示例13: MyRepeat

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def MyRepeat(x, reps, axes):
    assert len(reps) == len(axes)
    y = x
    for r, a in zip(reps, axes):
	y = T.repeat(y, [r], axis=a)
    return y


## Replace each vector (the last dim) of x by the linear combination of this vector and patterns 
## x is tensor4 with shape (bSize, nRows, nCols, n_in) where n_in = pshape[0]
## x can be interpreted as a set of reduced contact maps, where each contact map has size (nRows, nCols)

## the resultant matrix shall have shape (batchSize, nRows * pshape[1], nCols* pshape[2], 2), indicating the predicted prob of contacts and non-contacts 
开发者ID:j3xugit,项目名称:RaptorX-Contact,代码行数:15,代码来源:utils.py

示例14: convolve

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def convolve(self, input, **kwargs):
        W_shape = self.get_W_shape()
        W_shape = (W_shape[0], W_shape[1] * self.groups, W_shape[2], W_shape[3])

        # the following is the symbolic equivalent of
        # W = np.zeros(W_shape)
        # for g in range(self.groups):
        #     input_slice = slice(g * self.input_shape[1] // self.groups,
        #                         (g + 1) * self.input_shape[1] // self.groups)
        #     output_slice = slice(g * self.num_filters // self.groups, (g + 1) * self.num_filters // self.groups)
        #     W[output_slice, input_slice, :, :] = self.W.get_value()[output_slice, :, :, :]

        # repeat W across the second dimension and then mask the terms outside the block diagonals
        mask = np.zeros(W_shape[:2]).astype(theano.config.floatX)
        for g in range(self.groups):
            input_slice = slice(g * self.input_shape[1] // self.groups,
                                (g + 1) * self.input_shape[1] // self.groups)
            output_slice = slice(g * self.num_filters // self.groups, (g + 1) * self.num_filters // self.groups)
            mask[output_slice, input_slice] = 1

        # elementwise multiplication along broadcasted dimensions is faster than T.tile
        # the following is equivalent to
        # W = T.tile(self.W, (1, self.groups, 1, 1)) * mask[:, :, None, None]
        W = (T.ones((1, self.groups, 1, 1, 1)) * self.W[:, None, :, :, :]).reshape(W_shape) * mask[:, :, None, None]

        # similarly for T.repeat but we don't use that in here
        # W = T.repeat(self.W, self.groups, axis=1) * mask[:, :, None, None]
        # W = (T.ones((1, 1, self.groups, 1, 1)) * self.W[:, :, None, :, :]).reshape(W_shape) * mask[:, :, None, None]

        border_mode = 'half' if self.pad == 'same' else self.pad
        conved = self.convolution(input, W,
                                  self.input_shape, W_shape,
                                  subsample=self.stride,
                                  filter_dilation=self.filter_dilation,
                                  border_mode=border_mode,
                                  filter_flip=self.flip_filters)
        return conved 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:39,代码来源:layers_theano.py

示例15: repeat_elements

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import repeat [as 别名]
def repeat_elements(x, rep, axis):
    """Repeat the elements of a tensor along an axis, like np.repeat.

    If x has shape (s1, s2, s3) and axis=1, the output
    will have shape (s1, s2 * rep, s3).
    """
    y = T.repeat(x, rep, axis=axis)
    if hasattr(x, '_keras_shape'):
        y._keras_shape = list(x._keras_shape)
        repeat_dim = x._keras_shape[axis]
        if repeat_dim is not None:
                y._keras_shape[axis] = repeat_dim * rep
        y._keras_shape = tuple(y._keras_shape)
    return y 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:16,代码来源:theano_backend.py


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