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


Python sparse.as_sparse_variable方法代码示例

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


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

示例1: variable

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import as_sparse_variable [as 别名]
def variable(value, dtype=None, name=None):
    '''Instantiates a variable and returns it.

    # Arguments
        value: Numpy array, initial value of the tensor.
        dtype: Tensor type.
        name: Optional name string for the tensor.

    # Returns
        A variable instance (with Keras metadata included).
    '''
    if dtype is None:
        dtype = floatx()
    if hasattr(value, 'tocoo'):
        _assert_sparse_module()
        variable = th_sparse_module.as_sparse_variable(value)
    else:
        value = np.asarray(value, dtype=dtype)
        variable = theano.shared(value=value, name=name, strict=False)
    variable._keras_shape = value.shape
    variable._uses_learning_phase = False
    return variable 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:24,代码来源:theano_backend.py

示例2: variable

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import as_sparse_variable [as 别名]
def variable(value, dtype=None, name=None, constraint=None):
    """Instantiates a variable and returns it.

    # Arguments
        value: Numpy array, initial value of the tensor.
        dtype: Tensor type.
        name: Optional name string for the tensor.
        constraint: Optional projection function to be
            applied to the variable after an optimizer update.

    # Returns
        A variable instance (with Keras metadata included).
    """
    if dtype is None:
        dtype = floatx()
    if hasattr(value, 'tocoo'):
        _assert_sparse_module()
        variable = th_sparse_module.as_sparse_variable(
            value, name=_prepare_name(name, 'variable'))
    else:
        if isinstance(value, (theano.tensor.TensorVariable,
                              theano.tensor.sharedvar.TensorSharedVariable,
                              theano.tensor.TensorConstant)):
            # Support for RandomStreams().normal(), .uniform().
            value = value.eval()
        value = np.asarray(value, dtype=dtype)
        variable = theano.shared(value=value,
                                 name=_prepare_name(name, 'variable'),
                                 strict=False)
    variable._keras_shape = value.shape
    variable._uses_learning_phase = False
    variable.constraint = constraint
    return variable 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:35,代码来源:theano_backend.py

示例3: __init__

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import as_sparse_variable [as 别名]
def __init__(self, *args, **kwargs):
        super(OpsReflected, self).__init__(*args, reflected=True, **kwargs)
        self._rT = rTReflectedOp(self._c_ops.rTReflected, self._c_ops.N)
        self._sT = sTReflectedOp(self._c_ops.sTReflected, self._c_ops.N)
        self._A1Big = ts.as_sparse_variable(self._c_ops.A1Big)

        # Compute grid on unit disk with ~source_npts points
        source_npts = kwargs.get("source_npts", 1)
        if source_npts <= 1:
            self.source_dx = np.array([0.0])
            self.source_dy = np.array([0.0])
            self.source_dz = np.array([0.0])
            self.source_npts = 1
        else:
            N = int(2 + np.sqrt(source_npts * 4 / np.pi))
            dx = np.linspace(-1, 1, N)
            dx, dy = np.meshgrid(dx, dx)
            dz = 1 - dx ** 2 - dy ** 2
            self.source_dx = dx[dz > 0].flatten()
            self.source_dy = dy[dz > 0].flatten()
            self.source_dz = dz[dz > 0].flatten()
            self.source_npts = len(self.source_dx)

        # NOTE: dz is *negative*, since the source is actually
        # *closer* to the body than in the point approximation
        self.source_dx = tt.as_tensor_variable(self.source_dx)
        self.source_dy = tt.as_tensor_variable(self.source_dy)
        self.source_dz = tt.as_tensor_variable(-self.source_dz)

        # Oren-Nayar (1994) intensity profile (for rendering)
        self._OrenNayar = OrenNayarOp(self._c_ops.OrenNayarPolynomial)
        self._pTON94 = pTOp(self._c_ops.pT, _c_ops.STARRY_OREN_NAYAR_DEG) 
开发者ID:rodluger,项目名称:starry,代码行数:34,代码来源:core.py

示例4: variable

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import as_sparse_variable [as 别名]
def variable(value, dtype=None, name=None):
    """Instantiates a variable and returns it.

    # Arguments
        value: Numpy array, initial value of the tensor.
        dtype: Tensor type.
        name: Optional name string for the tensor.

    # Returns
        A variable instance (with Keras metadata included).
    """
    if dtype is None:
        dtype = floatx()
    if hasattr(value, 'tocoo'):
        _assert_sparse_module()
        variable = th_sparse_module.as_sparse_variable(
            value, name=_prepare_name(name, 'variable'))
    else:
        if isinstance(value, (theano.tensor.TensorVariable,
                              theano.tensor.sharedvar.TensorSharedVariable,
                              theano.tensor.TensorConstant)):
            # Support for RandomStreams().normal(), .uniform().
            value = value.eval()
        value = np.asarray(value, dtype=dtype)
        variable = theano.shared(value=value,
                                 name=_prepare_name(name, 'variable'),
                                 strict=False)
    variable._keras_shape = value.shape
    variable._uses_learning_phase = False
    return variable 
开发者ID:sunilmallya,项目名称:keras-lambda,代码行数:32,代码来源:theano_backend.py


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