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


Python tensor.cumsum方法代码示例

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


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

示例1: nll_of_x_given_o

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def nll_of_x_given_o(self, input, ordering):
        """ Returns the theano graph that computes $-ln p(\bx|o)$.

        Parameters
        ----------
        input: 1D vector
            One image with shape (nb_channels * images_height * images_width).

        ordering: 1D vector of int
            List of pixel indices representing the input ordering.
        """

        D = int(np.prod(self.image_shape))
        mask_o_d = T.zeros((D, D), dtype=theano.config.floatX)
        mask_o_d = T.set_subtensor(mask_o_d[T.arange(D), ordering], 1.)

        mask_o_lt_d = T.cumsum(mask_o_d, axis=0)
        mask_o_lt_d = T.set_subtensor(mask_o_lt_d[1:], mask_o_lt_d[:-1])
        mask_o_lt_d = T.set_subtensor(mask_o_lt_d[0, :], 0.)

        input = T.tile(input[None, :], (D, 1))
        nll = -T.sum(self.lnp_x_o_d_given_x_o_lt_d(input, mask_o_d, mask_o_lt_d))
        return nll 
开发者ID:MarcCote,项目名称:NADE,代码行数:25,代码来源:convnade.py

示例2: set_rest_ref_matrix

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

示例3: set_nugget_surface_points

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def set_nugget_surface_points(self, ref_positions, rest_mask, number_of_points_per_surface):
        # ref_nugget = T.repeat(self.nugget_effect_scalar_T[ref_positions], number_of_points_per_surface)
        cum_rep = T.cumsum(T.concatenate((T.stack([0]), number_of_points_per_surface)))
        ref_nugget_init = T.zeros((cum_rep[-1], 1))
        ref_nugget_loop, update_ = theano.scan(self.repeat_list,
                                               outputs_info=[ref_nugget_init],
                                               sequences=[self.nugget_effect_scalar_T[ref_positions],
                                                          dict(input=cum_rep, taps=[0, 1])],
                                               non_sequences=[T.as_tensor(1)],
                                               return_list=False)

        # ref_nugget_loop = theano.printing.Print('loop')(ref_nugget_loop)
        ref_nugget = ref_nugget_loop[-1]

        rest_nugget = self.nugget_effect_scalar_T[rest_mask]
        nugget_rest_ref = ref_nugget.reshape((1, -1))[0] + rest_nugget
        return nugget_rest_ref 
开发者ID:cgre-aachen,项目名称:gempy,代码行数:19,代码来源:theano_graph_pro.py

示例4: add_exploration

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def add_exploration(recognizer, data, train_conf):

    prediction = None
    prediction_mask = None
    explore_conf = train_conf.get('exploration', 'imitative')
    if explore_conf in ['greedy', 'mixed']:
        length_expand = 10
        prediction = recognizer.get_generate_graph(
            n_steps=recognizer.labels.shape[0] + length_expand)['outputs']
        prediction_mask = tensor.lt(
            tensor.cumsum(tensor.eq(prediction, data.eos_label), axis=0),
            1).astype(floatX)
        prediction_mask = tensor.roll(prediction_mask, 1, 0)
        prediction_mask = tensor.set_subtensor(
            prediction_mask[0, :], tensor.ones_like(prediction_mask[0, :]))

        if explore_conf == 'mixed':
            batch_size = recognizer.labels.shape[1]
            targets = tensor.concatenate([
                recognizer.labels,
                tensor.zeros((length_expand, batch_size), dtype='int64')])

            targets_mask = tensor.concatenate([
                recognizer.labels_mask,
                tensor.zeros((length_expand, batch_size), dtype=floatX)])
            rng = MRG_RandomStreams()
            generate = rng.binomial((batch_size,), p=0.5, dtype='int64')
            prediction = (generate[None, :] * prediction +
                          (1 - generate[None, :]) * targets)
            prediction_mask = (tensor.cast(generate[None, :] *
                                           prediction_mask, floatX) +
                               tensor.cast((1 - generate[None, :]) *
                                           targets_mask, floatX))

        prediction_mask = theano.gradient.disconnected_grad(prediction_mask)
    elif explore_conf != 'imitative':
        raise ValueError

    return prediction, prediction_mask 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:41,代码来源:main.py

示例5: monotonicity_penalty

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def monotonicity_penalty(weights, mask_x=None):
    cumsums = tensor.cumsum(weights, axis=2)
    penalties = tensor.maximum(cumsums[1:] - cumsums[:-1], 0).sum(axis=2)
    if mask_x:
        penalties *= mask_x[1:]
    return penalties.sum() 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:8,代码来源:expressions.py

示例6: compute_output

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def compute_output(self, network, in_vw):
        axis = network.find_hyperparameter(["axis"])
        network.create_vw(
            "default",
            variable=T.cumsum(in_vw.variable, axis=axis),
            shape=in_vw.shape,
            tags={"output"}
        ) 
开发者ID:SBU-BMI,项目名称:u24_lymphocyte,代码行数:10,代码来源:theanode.py

示例7: drawpoints

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def drawpoints(points, xmin=None, ymin=None, xmax=None, ymax=None):
    skips = np.hstack((np.array([0]),points[:,2]))
    xys = np.vstack((np.zeros((1,2)),np.cumsum(points[:,:2],axis=0)))
    xys[:,:2] -= xys[:,:2].mean(axis=0)
#     xys = points[:,:2]

    xs=[]
    ys=[]
    x=[]
    y=[]
    for xy,s in zip(xys, skips):
        if s:
            if len(x) > 1:
                xs.append(x)
                ys.append(y)
            x=[]
            y=[]
        else:
            x.append(xy[0])
            y.append(xy[1])

    for x,y in zip(xs, ys):
        pl.plot(x, y, 'k-')

    if xmin is None:
        xmin,ymin = xys.min(axis=0)
        xmax,ymax = xys.max(axis=0)
    ax = pl.gca()
    ax.set_xlim(xmin, xmax)
    ax.set_ylim(ymin, ymax)
    ax.invert_yaxis()
    ax.set_xticks([])
    ax.set_yticks([]) 
开发者ID:udibr,项目名称:sketch,代码行数:35,代码来源:sketch.py

示例8: emit

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def emit(self, readouts):
        """
        Single step

        :param readouts: output of hidden layer [batch_size,get_dim('inputs')]
        """
        mean, sigma, corr, weight, penup = self.components(readouts)
        mix_dim = self.mix_dim  # get_dim('mix')
        batch_size = readouts.shape[0]

        nr = self.theano_rng.normal(
            size=(batch_size, mix_dim, 2),
            avg=0., std=1.) #, dtype=floatX)

        c = (1 - T.sqrt(1-corr**2))/(corr + self.epsilon)
        c = c.dimshuffle((0, 1, 'x'))  # same for x and y
        nr = nr + nr[:,:,::-1]*c  # x+c*y and y + c*x

        nr = nr / T.sqrt(1+c**2)
        nr = nr * sigma
        nr = nr + mean
        # If I dont do dtype=floatX in the next line I get an error
        weight = self.theano_rng.multinomial(pvals=weight, dtype=floatX)
        # an alternative is the following code:
        # right_boundry = T.cumsum(weight,axis=1)  # [...,1]
        # left_boundry = right_boundry - weight  # [0,...]
        # un0 = self.theano_rng.uniform(size=(batch_size,)).dimshuffle((0, 'x'))
        # weight = T.cast(left_boundry <= un0, floatX) * \
        #          T.cast(un0 < right_boundry, floatX)  # 1 only in one bin

        xy = nr * weight[:,:,None]  # [batch_size,mix_dim,2]

        xy = xy.sum(axis=1) # [batch_size,2]

        un = self.theano_rng.uniform(size=(batch_size, 1)) #, dtype=floatX)
        penup = T.cast(un < penup, floatX) # .astype(floatX)  # [batch_size,1]

        res = T.concatenate([xy, penup], axis=1)
        return res 
开发者ID:udibr,项目名称:sketch,代码行数:41,代码来源:sketch.py

示例9: set_rest_ref_matrix

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

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

示例10: geomav

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def geomav(x, *args, **kwargs):
    x = x[0]
    if len(x) == 0:
        return np.zeros(600)
    res = np.cumsum(utils.norm_geometric_average(utils.cdf_to_pdf(x)))
    return res 
开发者ID:317070,项目名称:kaggle-heart,代码行数:8,代码来源:merge_predictions.py

示例11: prodav

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def prodav(x, *args, **kwargs):
    x = x[0]
    if len(x) == 0:
        return np.zeros(600)
    return np.cumsum(utils.norm_prod(utils.cdf_to_pdf(x))) 
开发者ID:317070,项目名称:kaggle-heart,代码行数:7,代码来源:merge_predictions.py

示例12: weighted_geom_no_entr

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def weighted_geom_no_entr(prediction_matrix, average, eps=1e-14, expert_weights=None, *args, **kwargs):
    if len(prediction_matrix.flatten()) == 0:
        return np.zeros(600)
    weights = generate_information_weight_matrix(prediction_matrix, average, expert_weights=expert_weights, use_entropy=False, *args, **kwargs)
    assert np.isfinite(weights).all()
    pdf = utils.cdf_to_pdf(prediction_matrix)
    x_log = np.log(pdf)
    x_log[pdf<=0] = np.log(eps)
    # Compute the mean
    geom_av_log = np.sum(x_log * weights, axis=(0,1)) / (np.sum(weights, axis=(0,1)) + eps)
    geom_av_log = geom_av_log - np.max(geom_av_log)  # stabilizes rounding errors?

    geom_av = np.exp(geom_av_log)
    res = np.cumsum(geom_av/np.sum(geom_av))
    return res 
开发者ID:317070,项目名称:kaggle-heart,代码行数:17,代码来源:merge_predictions.py

示例13: weighted_geom_method

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def weighted_geom_method(prediction_matrix, average, eps=1e-14, expert_weights=None, *args, **kwargs):
    if len(prediction_matrix.flatten()) == 0:
        return np.zeros(600)
    weights = generate_information_weight_matrix(prediction_matrix, average, expert_weights=expert_weights, *args, **kwargs)
    assert np.isfinite(weights).all()
    pdf = utils.cdf_to_pdf(prediction_matrix)
    x_log = np.log(pdf)
    x_log[pdf<=0] = np.log(eps)
    # Compute the mean
    geom_av_log = np.sum(x_log * weights, axis=(0,1)) / (np.sum(weights, axis=(0,1)) + eps)
    geom_av_log = geom_av_log - np.max(geom_av_log)  # stabilizes rounding errors?

    geom_av = np.exp(geom_av_log)
    res = np.cumsum(geom_av/np.sum(geom_av))
    return res 
开发者ID:317070,项目名称:kaggle-heart,代码行数:17,代码来源:merge_predictions.py

示例14: build_sampling_function

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import cumsum [as 别名]
def build_sampling_function(self, seed=1234):
        from .utils import Timer
        from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
        rng = np.random.RandomState(seed)
        theano_rng = RandomStreams(rng.randint(2**30))

        # Build theano function
        # $X$: batch of inputs (flatten images)
        input = T.matrix('input')
        # $o_d$: index of d-th dimension in the ordering.
        mask_o_d = T.matrix('mask_o_d')
        # $o_{<d}$: indices of the d-1 first dimensions in the ordering.
        mask_o_lt_d = T.matrix('mask_o_lt_d')

        # Prepare input
        X = input*mask_o_lt_d
        if self.nb_channels == 2:
            X = T.concatenate([X, mask_o_lt_d], axis=1)

        output = T.nnet.sigmoid(self.get_output(X))
        # output = self.fprop(input, mask_o_lt_d)

        probs = T.sum(output*mask_o_d, axis=1)
        bits = theano_rng.binomial(p=probs, size=probs.shape, n=1, dtype=theano.config.floatX)
        sample_bit_plus = theano.function([input, mask_o_d, mask_o_lt_d], [bits, probs])

        def _sample(nb_samples, return_probs=False, ordering_seed=1234):
            rng = np.random.RandomState(ordering_seed)
            D = int(np.prod(self.image_shape))
            ordering = np.arange(D)
            rng.shuffle(ordering)

            with Timer("Generating {} samples from ConvDeepNADE".format(nb_samples)):
                o_d = np.zeros((D, D), dtype=theano.config.floatX)
                o_d[np.arange(D), ordering] = 1

                o_lt_d = np.cumsum(o_d, axis=0)
                o_lt_d[1:] = o_lt_d[:-1]
                o_lt_d[0, :] = 0

                samples = np.zeros((nb_samples, D), dtype="float32")
                samples_probs = np.zeros((nb_samples, D), dtype="float32")
                for d, bit in enumerate(ordering):
                    if d % 100 == 0:
                        print(d)
                    bits, probs = sample_bit_plus(samples, np.tile(o_d[d], (nb_samples, 1)), np.tile(o_lt_d[d], (nb_samples, 1)))
                    samples[:, bit] = bits
                    samples_probs[:, bit] = probs

                if return_probs:
                    return samples, samples_probs

                return samples

        return _sample 
开发者ID:MarcCote,项目名称:NADE,代码行数:57,代码来源:convnade.py


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