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


Python linalg_ops.matrix_inverse方法代碼示例

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


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

示例1: _MatrixDeterminantGrad

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import matrix_inverse [as 別名]
def _MatrixDeterminantGrad(op, grad):
  """Gradient for MatrixDeterminant."""
  a = op.inputs[0]
  c = op.outputs[0]
  a_adj_inv = linalg_ops.matrix_inverse(a, adjoint=True)
  multipliers = array_ops.reshape(
      grad * c, array_ops.concat([array_ops.shape(c), [1, 1]], 0))
  return multipliers * a_adj_inv 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:linalg_grad.py

示例2: _define_distance_to_clusters

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import matrix_inverse [as 別名]
def _define_distance_to_clusters(self, data):
    """Defines the Mahalanobis distance to the assigned Gaussian."""
    # TODO(xavigonzalvo): reuse (input - mean) * cov^-1 * (input -
    # mean) from log probability function.
    self._all_scores = []
    for shard in data:
      all_scores = []
      shard = array_ops.expand_dims(shard, 0)
      for c in xrange(self._num_classes):
        if self._covariance_type == FULL_COVARIANCE:
          cov = self._covs[c, :, :]
        elif self._covariance_type == DIAG_COVARIANCE:
          cov = array_ops.diag(self._covs[c, :])
        inverse = linalg_ops.matrix_inverse(cov + self._min_var)
        inv_cov = array_ops.tile(
            array_ops.expand_dims(inverse, 0),
            array_ops.stack([self._num_examples, 1, 1]))
        diff = array_ops.transpose(shard - self._means[c, :, :], perm=[1, 0, 2])
        m_left = math_ops.matmul(diff, inv_cov)
        all_scores.append(
            math_ops.sqrt(
                math_ops.matmul(
                    m_left, array_ops.transpose(
                        diff, perm=[0, 2, 1]))))
      self._all_scores.append(
          array_ops.reshape(
              array_ops.concat(all_scores, 1),
              array_ops.stack([self._num_examples, self._num_classes])))

    # Distance to the associated class.
    self._all_scores = array_ops.concat(self._all_scores, 0)
    assignments = array_ops.concat(self.assignments(), 0)
    rows = math_ops.to_int64(math_ops.range(0, self._num_examples))
    indices = array_ops.concat(
        [array_ops.expand_dims(rows, 1), array_ops.expand_dims(assignments, 1)],
        1)
    self._scores = array_ops.gather_nd(self._all_scores, indices) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:39,代碼來源:gmm_ops.py

示例3: _image_projective_transform_grad

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import matrix_inverse [as 別名]
def _image_projective_transform_grad(op, grad):
  """Computes the gradient for ImageProjectiveTransform."""
  images = op.inputs[0]
  transforms = op.inputs[1]
  interpolation = op.get_attr("interpolation")

  image_or_images = ops.convert_to_tensor(images, name="images")
  transform_or_transforms = ops.convert_to_tensor(
      transforms, name="transforms", dtype=dtypes.float32)

  if image_or_images.dtype.base_dtype not in _IMAGE_DTYPES:
    raise TypeError("Invalid dtype %s." % image_or_images.dtype)
  if len(image_or_images.get_shape()) == 2:
    images = image_or_images[None, :, :, None]
  elif len(image_or_images.get_shape()) == 3:
    images = image_or_images[None, :, :, :]
  elif len(image_or_images.get_shape()) == 4:
    images = image_or_images
  else:
    raise TypeError("Images should have rank between 2 and 4")
  if len(transform_or_transforms.get_shape()) == 1:
    transforms = transform_or_transforms[None]
  elif len(transform_or_transforms.get_shape()) == 2:
    transforms = transform_or_transforms
  else:
    raise TypeError("Transforms should have rank 1 or 2.")

  # Invert transformations
  transforms = _flat_transforms_to_matrices(transforms=transforms)
  inverse = linalg_ops.matrix_inverse(transforms)
  transforms = _transform_matrices_to_flat(inverse)
  output = gen_image_ops.image_projective_transform(
      grad, transforms, interpolation=interpolation)
  if len(image_or_images.get_shape()) == 2:
    return [output[0, :, :, 0], None]
  elif len(image_or_images.get_shape()) == 3:
    return [output[0, :, :, :], None]
  else:
    return [output, None] 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:41,代碼來源:image_ops.py

示例4: _MatrixDeterminantGrad

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import matrix_inverse [as 別名]
def _MatrixDeterminantGrad(op, grad):
  """Gradient for MatrixDeterminant."""
  a = op.inputs[0]
  c = op.outputs[0]
  a_adj_inv = linalg_ops.matrix_inverse(a, adjoint=True)
  multipliers = array_ops.reshape(
      grad * c, array_ops.concat(0, [array_ops.shape(c), [1, 1]]))
  return multipliers * a_adj_inv 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:10,代碼來源:linalg_grad.py

示例5: posdef_inv_matrix_inverse

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import matrix_inverse [as 別名]
def posdef_inv_matrix_inverse(tensor, identity, damping):
    """Computes inverse(tensor + damping * identity) directly."""
    return linalg_ops.matrix_inverse(tensor + damping * identity) 
開發者ID:gd-zhang,項目名稱:noisy-K-FAC,代碼行數:5,代碼來源:utils.py

示例6: _MatrixDeterminantGrad

# 需要導入模塊: from tensorflow.python.ops import linalg_ops [as 別名]
# 或者: from tensorflow.python.ops.linalg_ops import matrix_inverse [as 別名]
def _MatrixDeterminantGrad(op, grad):
  """Gradient for MatrixDeterminant."""
  a = op.inputs[0]
  c = op.outputs[0]
  a_adj_inv = linalg_ops.matrix_inverse(a, adjoint=True)
  multipliers = array_ops.reshape(grad * c,
                                  array_ops.concat([array_ops.shape(c), [1, 1]],
                                                   0))
  return multipliers * a_adj_inv 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:11,代碼來源:linalg_grad.py


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