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


Python tensor.squeeze函数代码示例

本文整理汇总了Python中theano.tensor.squeeze函数的典型用法代码示例。如果您正苦于以下问题:Python squeeze函数的具体用法?Python squeeze怎么用?Python squeeze使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: getTrainingFunc2

    def getTrainingFunc2(self):
        input = T.dmatrix()
        target = T.dvector()
        learning_rate = T.scalar()
        
        y = input
        for i in xrange(0, self.n_layers-1):
            y = T.maximum(0.0, T.dot(y, self.params[i*3]) + self.params[i*3+1] )
            y = y*self.theano_rng.binomial(y.shape, 1, 0.5)
        
        y = T.maximum(0, T.dot(y, self.params[(self.n_layers-1)*3]) + self.params[(self.n_layers-1)*3+1] )
        
        y = T.squeeze(y.T)
        #y = T.dot(y, self.params[-1])
        diff = y - target
        #regulator = theano.printing.Print('norm:')(T.sum(abs(y))*alpha)
        #L = theano.printing.Print('L:')(T.sum(diff*diff) + regulator)
        L = T.sum(diff*diff) #- target*T.log(y) - (1-target)*T.log(1-y)
        
        gparam = T.grad(L, [ self.params[i] for i in xrange(len(self.params)) if i%3 != 2 ])

        updates = {}
        for i,p,g,m in zip(xrange(len(gparam)),[ self.params[i] for i in xrange(len(self.params)) if i%3 != 2 ], gparam, [ self.moments[i] for i in xrange(len(self.moments)) if i%3 != 2 ]):
            if i%2 == 0:
                updates[m] = 0.9*m - learning_rate*0.0005*p - learning_rate*g        
            else:
                updates[m] = 0.9*m - learning_rate*g
            updates[p] = p + m

        train_func = theano.function( inputs = [input, target, learning_rate], outputs=[L,y], updates= updates)
        return train_func
开发者ID:amoliu,项目名称:autosub,代码行数:31,代码来源:parse.py

示例2: get_output

 def get_output(self, go_backwards = False, train = False):
     self.reset_states(train.shape[0])
     inputs = train.dimshuffle((1, 0, 2))
     results, _ = theano.scan(
         self.step,
         sequences=inputs,
         outputs_info=[self.states[0],self.states[1]],
         go_backwards=go_backwards)
     '''
     # deal with Theano API inconsistency
     if type(results) is list:
         outputs = results[0]
         states = results[1:]
     else:
         outputs = results
         states = []
 
     outputs = T.squeeze(outputs)
     last_output = outputs[-1]
     '''
     
     #outputs = np.asarray(results)[:,0]
     #outputs = T.squeeze(outputs)
     #outputs = outputs.dimshuffle((1, 0, 2))
     
     #states = [T.squeeze(state[-1]) for state in states]
     #return last_output, outputs, states
     
     outputs = results[0]
     outputs = T.squeeze(outputs)
     outputs = outputs.dimshuffle((1, 0, 2))
     return outputs
开发者ID:FudanNLP,项目名称:NeuralSentenceOrdering,代码行数:32,代码来源:LSTM.py

示例3: _comp_modes

 def _comp_modes(self):
     try:
         return tt.as_tensor_variable(self.comp_dists.mode)
     except AttributeError:
         return tt.squeeze(tt.stack([comp_dist.mode
                                     for comp_dist in self.comp_dists],
                                    axis=-1))
开发者ID:pymc-devs,项目名称:pymc3,代码行数:7,代码来源:mixture.py

示例4: get_relative_position

    def get_relative_position(self, t):
        """The planets' positions relative to the star

        Args:
            t: The times where the position should be evaluated.

        Returns:
            The components of the position vector at ``t`` in units of
            ``R_sun``.

        """
        dt = tt.mod(tt.shape_padright(t) - self._ref_time, self.period)
        dt -= self._half_period
        x = tt.squeeze(self.speed * dt)
        y = tt.squeeze(self._b_norm + tt.zeros_like(dt))
        z = -tt.ones_like(x)
        return x, y, z
开发者ID:dfm,项目名称:exoplanet,代码行数:17,代码来源:simple.py

示例5: squeeze

def squeeze(x, axis):
    '''Remove a 1-dimension from the tensor at index "axis".
    '''
    broadcastable = x.broadcastable[:axis] + x.broadcastable[axis+1:]
    x = T.patternbroadcast(x, [i == axis for i in range(x.type.ndim)])
    x = T.squeeze(x)
    x = T.patternbroadcast(x, broadcastable)
    return x
开发者ID:fvisin,项目名称:keras,代码行数:8,代码来源:theano_backend.py

示例6: _comp_logp

    def _comp_logp(self, value):
        comp_dists = self.comp_dists

        try:
            value_ = value if value.ndim > 1 else tt.shape_padright(value)

            return comp_dists.logp(value_)
        except AttributeError:
            return tt.squeeze(tt.stack([comp_dist.logp(value)
                                        for comp_dist in comp_dists],
                                       axis=1))
开发者ID:brandonwillard,项目名称:pymc3,代码行数:11,代码来源:mixture.py

示例7: logsumexp

def logsumexp(x, axis=None, keepdims=False):
    max_value = T.max(x, axis=axis, keepdims=True)
    res = max_value + T.log(T.sum(T.exp(x-max_value), axis=axis, keepdims=True))
    if not keepdims:
        if axis is None:
            return T.squeeze(res)

        slices = [slice(None, None, None)]*res.ndim
        slices[axis] = 0  # Axis being merged
        return res[tuple(slices)]

    return res
开发者ID:ppoulin91,项目名称:learn2track,代码行数:12,代码来源:utils.py

示例8: get_radial_velocity

    def get_radial_velocity(self, t, K=None, output_units=None):
        """Get the radial velocity of the star

        .. note:: The convention in exoplanet is that positive `z` points
            *towards* the observer. However, for consistency with radial
            velocity literature this method returns values where positive
            radial velocity corresponds to a redshift as expected.

        Args:
            t: The times where the radial velocity should be evaluated.
            K (Optional): The semi-amplitudes of the orbits. If provided, the
                ``m_planet`` and ``incl`` parameters will be ignored and this
                amplitude will be used instead.
            output_units (Optional): An AstroPy velocity unit. If not given,
                the output will be evaluated in ``m/s``. This is ignored if a
                value is given for ``K``.

        Returns:
            The reflex radial velocity evaluated at ``t`` in units of
            ``output_units``. For multiple planets, this will have one row for
            each planet.

        """

        # Special case for K given: m_planet, incl, etc. is ignored
        if K is not None:
            f = self._get_true_anomaly(t)
            if self.ecc is None:
                return tt.squeeze(K * tt.cos(f))
            # cos(w + f) + e * cos(w) from Lovis & Fischer
            return tt.squeeze(
                K * (self.cos_omega*tt.cos(f) - self.sin_omega*tt.sin(f) +
                     self.ecc * self.cos_omega))

        # Compute the velocity using the full orbit solution
        if output_units is None:
            output_units = u.m / u.s
        conv = (1 * u.R_sun / u.day).to(output_units).value
        v = self.get_star_velocity(t)
        return -conv * v[2]
开发者ID:dfm,项目名称:exoplanet,代码行数:40,代码来源:keplerian.py

示例9: get_planet_position

    def get_planet_position(self, t):
        """The planets' positions in the barycentric frame

        Args:
            t: The times where the position should be evaluated.

        Returns:
            The components of the position vector at ``t`` in units of
            ``R_sun``.

        """
        return tuple(tt.squeeze(x)
                     for x in self._get_position(self.a_planet, t))
开发者ID:dfm,项目名称:exoplanet,代码行数:13,代码来源:keplerian.py

示例10: get_planet_velocity

    def get_planet_velocity(self, t):
        """Get the planets' velocity vector

        Args:
            t: The times where the velocity should be evaluated.

        Returns:
            The components of the velocity vector at ``t`` in units of
            ``M_sun/day``.

        """
        return tuple(tt.squeeze(x)
                     for x in self._get_velocity(-self.m_star, t))
开发者ID:dfm,项目名称:exoplanet,代码行数:13,代码来源:keplerian.py

示例11: __init__

    def __init__(self, p, *args, **kwargs):
        super().__init__(*args, **kwargs)
        try:
            self.k = tt.shape(p)[-1].tag.test_value
        except AttributeError:
            self.k = tt.shape(p)[-1]
        p = tt.as_tensor_variable(floatX(p))

        # From #2082, it may be dangerous to automatically rescale p at this
        # point without checking for positiveness
        self.p = p
        self.mode = tt.argmax(p, axis=-1)
        if self.mode.ndim == 1:
            self.mode = tt.squeeze(self.mode)
开发者ID:aloctavodia,项目名称:pymc3,代码行数:14,代码来源:discrete.py

示例12: get_star_velocity

    def get_star_velocity(self, t):
        """Get the star's velocity vector

        .. note:: For a system with multiple planets, this will return one
            column per planet with the contributions from each planet. The
            total velocity can be found by summing along the last axis.

        Args:
            t: The times where the velocity should be evaluated.

        Returns:
            The components of the velocity vector at ``t`` in units of
            ``M_sun/day``.

        """
        return tuple(tt.squeeze(x)
                     for x in self._get_velocity(self.m_planet, t))
开发者ID:dfm,项目名称:exoplanet,代码行数:17,代码来源:keplerian.py

示例13: get_relative_velocity

    def get_relative_velocity(self, t):
        """The planets' velocity relative to the star

        .. note:: This treats each planet independently and does not take the
            other planets into account when computing the position of the
            star. This is fine as long as the planet masses are small.

        Args:
            t: The times where the velocity should be evaluated.

        Returns:
            The components of the velocity vector at ``t`` in units of
            ``R_sun/day``.

        """
        return tuple(tt.squeeze(x)
                     for x in self._get_velocity(-self.m_total, t))
开发者ID:dfm,项目名称:exoplanet,代码行数:17,代码来源:keplerian.py

示例14: get_star_position

    def get_star_position(self, t):
        """The star's position in the barycentric frame

        .. note:: If there are multiple planets in the system, this will
            return one column per planet with each planet's contribution to
            the motion. The star's full position can be computed by summing
            over the last axis.

        Args:
            t: The times where the position should be evaluated.

        Returns:
            The components of the position vector at ``t`` in units of
            ``R_sun``.

        """
        return tuple(tt.squeeze(x)
                     for x in self._get_position(self.a_star, t))
开发者ID:dfm,项目名称:exoplanet,代码行数:18,代码来源:keplerian.py

示例15: _compute_losses

    def _compute_losses(self, model_output):
        # model_output.shape : (batch_size, seq_len, K, M, target_size)
        # self.dataset.symb_targets.shape = (batch_size, seq_len+K-1, target_dims)

        # targets.shape = (batch_size, seq_len, 3)
        targets = self.dataset.symb_targets[:, : -self.model.k + 1 or None, :]

        # mask.shape : (batch_size, seq_len)
        mask = self.dataset.symb_mask

        # samples.shape : (batch_size, seq_len, 3)
        # T.squeeze(.) should remove the K=1 and M=1 dimensions
        self.samples = self.model.get_max_component_samples(T.squeeze(model_output))

        # loss_per_time_step.shape = (batch_size, seq_len)
        self.loss_per_time_step = l2distance(self.samples, targets)
        # loss_per_seq.shape = (batch_size,)
        self.loss_per_seq = T.sum(self.loss_per_time_step * mask, axis=1) / T.sum(mask, axis=1)

        return self.loss_per_seq
开发者ID:ppoulin91,项目名称:learn2track,代码行数:20,代码来源:gru_msp.py


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