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


Python tensor.Variable方法代码示例

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


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

示例1: cost

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def cost(self, readouts, outputs):
        """Compute generation cost of outputs given readouts.

        Parameters
        ----------
        readouts : :class:`~theano.Variable`
            Readouts produced by the :meth:`readout` method
            of a `(..., readout dim)` shape.
        outputs : :class:`~theano.Variable`
            Outputs whose cost should be computed. Should have as many
            or one less dimensions compared to `readout`. If readout has
            `n` dimensions, first `n - 1` dimensions of `outputs` should
            match with those of `readouts`.

        """
        pass 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:18,代码来源:sequence_generators.py

示例2: encode

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def encode(self, inputs):
        """
        Map inputs through the encoder function.

        Parameters
        ----------
        inputs : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the input
            minibatch(es) to be encoded. Assumed to be 2-tensors, with the
            first dimension indexing training examples and the second
            indexing data dimensions.

        Returns
        -------
        encoded : tensor_like or list of tensor_like
            Theano symbolic (or list thereof) representing the corresponding
            minibatch(es) after encoding.
        """
        if isinstance(inputs, tensor.Variable):
            return self._hidden_activation(inputs)
        else:
            return [self.encode(v) for v in inputs] 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:24,代码来源:autoencoder.py

示例3: input_to_h_from_v

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def input_to_h_from_v(self, v):
        """
        Compute the affine function (linear map plus bias) that serves as
        input to the hidden layer in an RBM.

        Parameters
        ----------
        v : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the one or several
            minibatches on the visible units, with the first dimension
            indexing training examples and the second indexing data dimensions.

        Returns
        -------
        a : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the input to each
            hidden unit for each training example.
        """

        if isinstance(v, tensor.Variable):
            return self.bias_hid + self.transformer.lmul(v)
        else:
            return [self.input_to_h_from_v(vis) for vis in v] 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:25,代码来源:rbm.py

示例4: input_to_v_from_h

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def input_to_v_from_h(self, h):
        """
        Compute the affine function (linear map plus bias) that serves as
        input to the visible layer in an RBM.

        Parameters
        ----------
        h : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the one or several
            minibatches on the hidden units, with the first dimension
            indexing training examples and the second indexing data dimensions.

        Returns
        -------
        a : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the input to each
            visible unit for each row of h.
        """
        if isinstance(h, tensor.Variable):
            return self.bias_vis + self.transformer.lmul_T(h)
        else:
            return [self.input_to_v_from_h(hid) for hid in h] 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:24,代码来源:rbm.py

示例5: mean_h_given_v

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def mean_h_given_v(self, v):
        """
        Compute the mean activation of the hidden units given visible unit
        configurations for a set of training examples.

        Parameters
        ----------
        v : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the hidden unit
            states for a batch (or several) of training examples, with the
            first dimension indexing training examples and the second
            indexing data dimensions.

        Returns
        -------
        h : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the mean
            (deterministic) hidden unit activations given the visible units.
        """
        if isinstance(v, tensor.Variable):
            return nnet.sigmoid(self.input_to_h_from_v(v))
        else:
            return [self.mean_h_given_v(vis) for vis in v] 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:25,代码来源:rbm.py

示例6: sgd_updates

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def sgd_updates(self, params, grads, stepsizes):
        """
        Return a list of (pairs) that can be used
        as updates in theano.function to
        implement stochastic gradient descent.

        Parameters
        ----------
        params : list of Variable
            variables to adjust in order to minimize some cost
        grads : list of Variable
            the gradient on each param (with respect to some cost)
        stepsizes : symbolic scalar or list of one symbolic scalar per param
            step by this amount times the negative gradient on each iteration
        """
        try:
            iter(stepsizes)
        except Exception:
            stepsizes = [stepsizes for p in params]
        if len(params) != len(grads):
            raise ValueError('params and grads have different lens')
        updates = [(p, p - step * gp) for (step, p, gp)
                in zip(stepsizes, params, grads)]
        return updates 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:26,代码来源:rbm.py

示例7: __call__

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def __call__(self, inputs):
        """
        (Symbolically) corrupt the inputs with a noise process.

        Parameters
        ----------
        inputs : tensor_like, or list of tensor_likes
            Theano symbolic(s) representing a (list of) (mini)batch of
            inputs to be corrupted, with the first dimension indexing
            training examples and the second indexing data dimensions.

        Returns
        -------
        corrupted : tensor_like, or list of tensor_likes
            Theano symbolic(s) representing the corresponding corrupted
            inputs.
        """
        if isinstance(inputs, tensor.Variable):
            return self._corrupt(inputs)
        else:
            return [self._corrupt(inp) for inp in inputs] 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:23,代码来源:corruption.py

示例8: theano_function

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def theano_function(*vars_by_pos, **kwargs):
    '''theano function decorator'''
    mode = kwargs.pop('mode', 'FAST_RUN')
    check_valid = kwargs.pop('check_valid', False)
    checks = kwargs.pop('checks', ())
    vars_by_name = kwargs
    def compile_func(f):
        argnames = f.func_code.co_varnames[:f.func_code.co_argcount]
        if any([a in vars_by_name for a in argnames[:len(vars_by_pos)]]):
            raise ValueError('Argument supplied twice to %s' % f.func_name)
        varspec = dict(vars_by_name)
        varspec.update(zip(argnames[:len(vars_by_pos)], vars_by_pos))
        argvars = []
        for name in argnames:
            spec = varspec[name]
            if isinstance(spec, (tuple, list)):
                (var, test_val) = spec
            else:
                var = spec
                test_val = None
            assert isinstance(var, T.Variable)
            var.name = name
            if test_val is not None:
                var.tag.test_value = test_val
            argvars.append(var)
        return function(argvars, f(*argvars),
                        check_valid=check_valid,
                        checks=checks,
                        mode=mode)
    return compile_func 
开发者ID:hjimce,项目名称:Depth-Map-Prediction,代码行数:32,代码来源:thutil.py

示例9: check_theano_variable

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def check_theano_variable(variable, n_dim, dtype_prefix):
    """Check number of dimensions and dtype of a Theano variable.

    If the input is not a Theano variable, it is converted to one. `None`
    input is handled as a special case: no checks are done.

    Parameters
    ----------
    variable : :class:`~tensor.TensorVariable` or convertible to one
        A variable to check.
    n_dim : int
        Expected number of dimensions or None. If None, no check is
        performed.
    dtype : str
        Expected dtype prefix or None. If None, no check is performed.

    """
    if variable is None:
        return

    if not isinstance(variable, tensor.Variable):
        variable = tensor.as_tensor_variable(variable)

    if n_dim and variable.ndim != n_dim:
        raise ValueError("Wrong number of dimensions:"
                         "\n\texpected {}, got {}".format(
                             n_dim, variable.ndim))

    if dtype_prefix and not variable.dtype.startswith(dtype_prefix):
        raise ValueError("Wrong dtype prefix:"
                         "\n\texpected starting with {}, got {}".format(
                             dtype_prefix, variable.dtype)) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:34,代码来源:__init__.py

示例10: emit

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

        Parameters
        ----------
        readouts : :class:`~theano.Variable`
            Readouts produced by the :meth:`readout` method of
            a `(batch_size, readout_dim)` shape.

        """
        pass 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:13,代码来源:sequence_generators.py

示例11: _setitem

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def _setitem(self, key, value):
        if isinstance(value, Variable):
            add_role(value, PARAMETER)
            add_annotation(value, self.brick) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:6,代码来源:base.py

示例12: decode

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Variable [as 别名]
def decode(self, hiddens):
        """
        Map inputs through the encoder function.

        Parameters
        ----------
        hiddens : tensor_like or list of tensor_likes
            Theano symbolic (or list thereof) representing the input
            minibatch(es) to be encoded. Assumed to be 2-tensors, with the
            first dimension indexing training examples and the second
            indexing data dimensions.

        Returns
        -------
        decoded : tensor_like or list of tensor_like
            Theano symbolic (or list thereof) representing the corresponding
            minibatch(es) after decoding.
        """
        if self.act_dec is None:
            act_dec = lambda x: x
        else:
            act_dec = self.act_dec
        if isinstance(hiddens, tensor.Variable):
            return act_dec(self.visbias + tensor.dot(hiddens, self.w_prime))
        else:
            return [self.decode(v) for v in hiddens] 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:28,代码来源:autoencoder.py


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