當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。