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


Python tensor.Constant方法代码示例

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


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

示例1: isNaN_or_Inf_or_None

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def isNaN_or_Inf_or_None(x):
    isNone = x is None
    try:
        isNaN = numpy.isnan(x)
        isInf = numpy.isinf(x)
        isStr = isinstance(x, string_types)
    except Exception:
        isNaN = False
        isInf = False
        isStr = False
    if not isNaN and not isInf:
        try:
            val = get_scalar_constant_value(x)
            isInf = numpy.isinf(val)
            isNaN = numpy.isnan(val)
        except Exception:
            isNaN = False
            isInf = False
    if isinstance(x, gof.Constant) and isinstance(x.data, string_types):
        isStr = True
    else:
        isStr = False
    return isNone or isNaN or isInf or isStr 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:25,代码来源:scan_utils.py

示例2: reconstruct_graph

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def reconstruct_graph(inputs, outputs, tag=None):
    """
    Different interface to clone, that allows you to pass inputs.
    Compared to clone, this method always replaces the inputs with
    new variables of the same type, and returns those (in the same
    order as the original inputs).

    """
    if tag is None:
        tag = ''
    nw_inputs = [safe_new(x, tag) for x in inputs]
    givens = OrderedDict()
    for nw_x, x in izip(nw_inputs, inputs):
        givens[x] = nw_x
    allinputs = theano.gof.graph.inputs(outputs)
    for inp in allinputs:
        if isinstance(inp, theano.Constant):
            givens[inp] = inp.clone()

    nw_outputs = clone(outputs, replace=givens)
    return (nw_inputs, nw_outputs) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:23,代码来源:scan_utils.py

示例3: make_node

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def make_node(self, a, q):
        # cast q to theano variable
        if isinstance(q, (int, float)):
            scalar_type = T.scalar().type
            q = T.Constant(scalar_type, q)

        # set to all axes if none specified
        if self.axis is None:
            axis = range(a.ndim)
        elif isinstance(self.axis, int):
            axis = [self.axis]
        else:
            axis = self.axis

        # calculate broadcastable
        if self.keepdims:
            broadcastable = [b or (ax in axis)
                             for ax, b in enumerate(a.broadcastable)]
        else:
            broadcastable = [b
                             for ax, b in enumerate(a.broadcastable)
                             if ax not in axis]

        out = T.TensorType(a.dtype, broadcastable)()
        return theano.gof.Apply(self, [a, q], [out]) 
开发者ID:SBU-BMI,项目名称:u24_lymphocyte,代码行数:27,代码来源:tensor.py

示例4: tensor_from_layer

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def tensor_from_layer(self, arg, collect_params=True):
        """
        Grab the theano tensor representing the computation of this
        layer/operator iff `arg` is a layer.

        :type collect_params: bool
        :param collect_params: Flag. If true, also collect the parameters
            and inputs of the layer `arg` and make them parameters and inputs
            needed to compute the current layer/operator
        """
        if not collect_params:
            if isinstance(arg, Container): return arg.out
            else: return arg

        if isinstance(arg, Container):
            self.merge_params(arg)
            return arg.out
        elif isinstance(arg, theano.gof.Variable):
            inps = [x for x in theano.gof.graph.inputs([arg])
                    if not isinstance(x, (TT.Constant, theano.compile.SharedVariable))]
            self.add_inputs(inps)
            return arg
        else:
            return arg 
开发者ID:guxd,项目名称:deepAPI,代码行数:26,代码来源:basic.py

示例5: get_outer_ndim

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def get_outer_ndim(self, var, scan_args):

        # Given a variable, determine the number of dimension it would have if
        # it was pushed out of scan
        if (var in scan_args.inner_in_non_seqs or
                isinstance(var, theano.Constant)):

            outer_ndim = var.ndim
        else:
            outer_ndim = var.ndim + 1

        return outer_ndim 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:14,代码来源:scan_opt.py

示例6: tensor_from_layer

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def tensor_from_layer(self, arg, collect_params=True):
        """
        Grab the theano tensor representing the computation of this
        layer/operator iff `arg` is a layer.

        :type collect_params: bool
        :param collect_params: Flag. If true, also collect the parameters
            and inputs of the layer `arg` and make them parameters and inputs
            needed to compute the current layer/operator
        """
        if not collect_params:
            if isinstance(arg, Container):
                return arg.out
            else:
                return arg


        if isinstance(arg, Container):
            self.merge_params(arg)
            return arg.out
        elif isinstance(arg, theano.gof.Variable):
            inps = [x for x in theano.gof.graph.inputs([arg])
                    if not isinstance(x, (TT.Constant, theano.compile.SharedVariable))]
            self.add_inputs(inps)
            return arg
        else:
            return arg 
开发者ID:pascanur,项目名称:GroundHog,代码行数:29,代码来源:basic.py

示例7: find_inputs_and_params

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def find_inputs_and_params(node):
    '''Walk a computation graph and extract root variables.

    Parameters
    ----------
    node : Theano expression
        A symbolic Theano expression to walk.

    Returns
    -------
    inputs : list Theano variables
        A list of candidate inputs for this graph. Inputs are nodes in the graph
        with no parents that are not shared and are not constants.
    params : list of Theano shared variables
        A list of candidate parameters for this graph. Parameters are nodes in
        the graph that are shared variables.
    '''
    queue, seen, inputs, params = [node], set(), set(), set()
    while queue:
        node = queue.pop()
        seen.add(node)
        queue.extend(p for p in node.get_parents() if p not in seen)
        if not node.get_parents():
            if isinstance(node, theano.compile.SharedVariable):
                params.add(node)
            elif not isinstance(node, TT.Constant):
                inputs.add(node)
    return list(inputs), list(params) 
开发者ID:lmjohns3,项目名称:downhill,代码行数:30,代码来源:util.py

示例8: push_out_inner_vars

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import Constant [as 别名]
def push_out_inner_vars(self, fgraph, inner_vars, old_scan_node,
                            old_scan_args):

        outer_vars = [None] * len(inner_vars)
        new_scan_node = old_scan_node
        new_scan_args = old_scan_args

        # For the inner_vars that already exist in the outer graph,
        # simply obtain a reference to them
        for idx in range(len(inner_vars)):

            var = inner_vars[idx]

            if var in old_scan_args.inner_in_seqs:
                idx_seq = old_scan_args.inner_in_seqs.index(var)
                outer_vars[idx] = old_scan_args.outer_in_seqs[idx_seq]

            elif var in old_scan_args.inner_in_non_seqs:
                idx_non_seq = old_scan_args.inner_in_non_seqs.index(var)
                outer_vars[idx] = old_scan_args.outer_in_non_seqs[idx_non_seq]

            elif isinstance(var, theano.Constant):
                outer_vars[idx] = var.clone()

            elif var in old_scan_args.inner_out_nit_sot:
                idx_nitsot = old_scan_args.inner_out_nit_sot.index(var)
                outer_vars[idx] = old_scan_args.outer_out_nit_sot[idx_nitsot]

        # For the inner_vars that don't already exist in the outer graph, add
        # them as new nitsot outputs to the scan node.
        idx_add_as_nitsots = [i for i in range(len(outer_vars))
                              if outer_vars[i] is None]
        add_as_nitsots = [inner_vars[idx] for idx in idx_add_as_nitsots]

        if len(add_as_nitsots) > 0:

            new_scan_node = self.add_nitsot_outputs(fgraph, old_scan_node,
                                                    old_scan_args,
                                                    add_as_nitsots)

            new_scan_args = scan_args(new_scan_node.inputs,
                                      new_scan_node.outputs,
                                      new_scan_node.op.inputs,
                                      new_scan_node.op.outputs,
                                      new_scan_node.op.info)

            new_outs = new_scan_args.outer_out_nit_sot[-len(add_as_nitsots):]
            for i in range(len(new_outs)):
                outer_vars[idx_add_as_nitsots[i]] = new_outs[i]

        return outer_vars, new_scan_node, new_scan_args 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:53,代码来源:scan_opt.py


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