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