當前位置: 首頁>>代碼示例>>Python>>正文


Python linalg_ops.svd方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.linalg_ops.svd方法的典型用法代碼示例。如果您正苦於以下問題:Python linalg_ops.svd方法的具體用法?Python linalg_ops.svd怎麽用?Python linalg_ops.svd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.linalg_ops的用法示例。


在下文中一共展示了linalg_ops.svd方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _assert_non_singular

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import svd [as 別名]
def _assert_non_singular(self):
    """Private default implementation of _assert_non_singular."""
    logging.warn(
        "Using (possibly slow) default implementation of assert_non_singular."
        "  Requires conversion to a dense matrix and O(N^3) operations.")
    if self._can_use_cholesky():
      return self.assert_positive_definite()
    else:
      singular_values = linalg_ops.svd(
          self._get_cached_dense_matrix(), compute_uv=False)
      # TODO(langmore) Add .eig and .cond as methods.
      cond = (math_ops.reduce_max(singular_values, axis=-1) /
              math_ops.reduce_min(singular_values, axis=-1))
      return check_ops.assert_less(
          cond,
          self._max_condition_number_to_be_non_singular(),
          message="Singular matrix up to precision epsilon.")
    raise NotImplementedError("assert_non_singular is not implemented.") 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:linear_operator.py

示例2: _symmetric_matrix_square_root

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import svd [as 別名]
def _symmetric_matrix_square_root(mat, eps=1e-10):
  """Compute square root of a symmetric matrix.

  Note that this is different from an elementwise square root. We want to
  compute M' where M' = sqrt(mat) such that M' * M' = mat.

  Also note that this method **only** works for symmetric matrices.

  Args:
    mat: Matrix to take the square root of.
    eps: Small epsilon such that any element less than eps will not be square
      rooted to guard against numerical instability.

  Returns:
    Matrix square root of mat.
  """
  # Unlike numpy, tensorflow's return order is (s, u, v)
  s, u, v = linalg_ops.svd(mat)
  # sqrt is unstable around 0, just use 0 in such case
  si = array_ops.where(math_ops.less(s, eps), s, math_ops.sqrt(s))
  # Note that the v returned by Tensorflow is v = V
  # (when referencing the equation A = U S V^T)
  # This is unlike Numpy which returns v = V^T
  return math_ops.matmul(
      math_ops.matmul(u, array_ops.diag(si)), v, transpose_b=True) 
開發者ID:taki0112,項目名稱:GAN_Metrics-Tensorflow,代碼行數:27,代碼來源:frechet_kernel_Inception_distance.py

示例3: __call__

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import svd [as 別名]
def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    # Check the shape
    if len(shape) < 2:
      raise ValueError("The tensor to initialize must be "
                       "at least two-dimensional")
    # Flatten the input shape with the last dimension remaining
    # its original shape so it works for conv2d
    num_rows = 1
    for dim in shape[:-1]:
      num_rows *= dim
    num_cols = shape[-1]
    flat_shape = (num_rows, num_cols)

    # Generate a random matrix
    a = random_ops.random_uniform(flat_shape, dtype=dtype, seed=self.seed)
    # Compute the svd
    _, u, v = linalg_ops.svd(a, full_matrices=False)
    # Pick the appropriate singular value decomposition
    if num_rows > num_cols:
      q = u
    else:
      # Tensorflow departs from numpy conventions
      # such that we need to transpose axes here
      q = array_ops.transpose(v)
    return self.gain * array_ops.reshape(q, shape)


# Aliases.

# pylint: disable=invalid-name 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:34,代碼來源:init_ops.py

示例4: posdef_eig_svd

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import svd [as 別名]
def posdef_eig_svd(mat):
    """Computes the singular values and left singular vectors of a matrix."""
    evals, evecs, _ = linalg_ops.svd(mat)

    return evals, evecs 
開發者ID:gd-zhang,項目名稱:noisy-K-FAC,代碼行數:7,代碼來源:utils.py

示例5: posdef_eig_self_adjoint

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import svd [as 別名]
def posdef_eig_self_adjoint(mat):
    """Computes eigendecomposition using self_adjoint_eig."""
    evals, evecs = linalg_ops.self_adjoint_eig(mat)
    evals = math_ops.abs(evals)  # Should be equivalent to svd approach.

    return evals, evecs 
開發者ID:gd-zhang,項目名稱:noisy-K-FAC,代碼行數:8,代碼來源:utils.py


注:本文中的tensorflow.python.ops.linalg_ops.svd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。