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


Python linalg_ops.matrix_inverse函数代码示例

本文整理汇总了Python中tensorflow.python.ops.linalg_ops.matrix_inverse函数的典型用法代码示例。如果您正苦于以下问题:Python matrix_inverse函数的具体用法?Python matrix_inverse怎么用?Python matrix_inverse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: benchmarkMatrixInverseOp

  def benchmarkMatrixInverseOp(self):
    for adjoint in False, True:
      for size in self.sizes:
        data = self._GenerateData(size)

        with ops.Graph().as_default(), \
            session.Session() as sess, \
            ops.device("/cpu:0"):
          inv = linalg_ops.matrix_inverse(data, adjoint=adjoint)
          self.run_op_benchmark(
              sess,
              control_flow_ops.group(inv),
              min_iters=25,
              name="matrix_inverse_cpu_{size}_{adjoint}".format(
                  size=size, adjoint="adjoint" if adjoint else "noadjoint"))

        if test.is_gpu_available(True):
          with ops.Graph().as_default(), \
              session.Session() as sess, \
              ops.device("/gpu:0"):
            inv = linalg_ops.matrix_inverse(data, adjoint=adjoint)
            self.run_op_benchmark(
                sess,
                control_flow_ops.group(inv),
                min_iters=25,
                name="matrix_inverse_gpu_{size}_{adjoint}".format(
                    size=size, adjoint="adjoint" if adjoint else "noadjoint"))
开发者ID:LiorPe,项目名称:tensorflow,代码行数:27,代码来源:matrix_inverse_op_test.py

示例2: benchmarkMatrixInverseOp

  def benchmarkMatrixInverseOp(self):
    for adjoint in False, True:
      for shape in self.shapes:
        with ops.Graph().as_default(), \
            session.Session(config=benchmark.benchmark_config()) as sess, \
            ops.device("/cpu:0"):
          matrix = self._GenerateMatrix(shape)
          inv = linalg_ops.matrix_inverse(matrix, adjoint=adjoint)
          variables.global_variables_initializer().run()
          self.run_op_benchmark(
              sess,
              control_flow_ops.group(inv),
              min_iters=25,
              name="matrix_inverse_cpu_{shape}_adjoint_{adjoint}".format(
                  shape=shape, adjoint=adjoint))

        if test.is_gpu_available(True):
          with ops.Graph().as_default(), \
              session.Session(config=benchmark.benchmark_config()) as sess, \
              ops.device("/gpu:0"):
            matrix = self._GenerateMatrix(shape)
            inv = linalg_ops.matrix_inverse(matrix, adjoint=adjoint)
            variables.global_variables_initializer().run()
            self.run_op_benchmark(
                sess,
                control_flow_ops.group(inv),
                min_iters=25,
                name="matrix_inverse_gpu_{shape}_adjoint_{adjoint}".format(
                    shape=shape, adjoint=adjoint))
开发者ID:bunbutter,项目名称:tensorflow,代码行数:29,代码来源:matrix_inverse_op_test.py

示例3: testNotInvertible

 def testNotInvertible(self):
   # The input should be invertible.
   with self.test_session():
     with self.assertRaisesOpError("Input is not invertible."):
       # All rows of the matrix below add to zero.
       tensor3 = constant_op.constant([[1., 0., -1.], [-1., 1., 0.],
                                       [0., -1., 1.]])
       linalg_ops.matrix_inverse(tensor3).eval()
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:8,代码来源:matrix_inverse_op_test.py

示例4: testConcurrentExecutesWithoutError

 def testConcurrentExecutesWithoutError(self):
   with self.session(use_gpu=True) as sess:
     all_ops = []
     for adjoint_ in True, False:
       matrix1 = random_ops.random_normal([5, 5], seed=42)
       matrix2 = random_ops.random_normal([5, 5], seed=42)
       inv1 = linalg_ops.matrix_inverse(matrix1, adjoint=adjoint_)
       inv2 = linalg_ops.matrix_inverse(matrix2, adjoint=adjoint_)
       all_ops += [inv1, inv2]
     inv = sess.run(all_ops)
     self.assertAllEqual(inv[0], inv[1])
     self.assertAllEqual(inv[2], inv[3])
开发者ID:bunbutter,项目名称:tensorflow,代码行数:12,代码来源:matrix_inverse_op_test.py

示例5: _MatrixDeterminantGrad

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:eerwitt,项目名称:tensorflow,代码行数:7,代码来源:linalg_grad.py

示例6: _image_projective_transform_grad

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(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 = matrices_to_flat_transforms(inverse)
  output = gen_image_ops.image_projective_transform_v2(
      images=grad,
      transforms=transforms,
      output_shape=array_ops.shape(image_or_images)[1:3],
      interpolation=interpolation)
  return [output, None, None]
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:29,代码来源:image_ops.py

示例7: _LogMatrixDeterminantGrad

def _LogMatrixDeterminantGrad(op, _, grad_b):
  """Gradient for LogMatrixDeterminant."""
  a = op.inputs[0]
  c = op.outputs[1]
  a_adj_inv = linalg_ops.matrix_inverse(a, adjoint=True)
  multipliers = array_ops.reshape(
      grad_b, array_ops.concat([array_ops.shape(c), [1, 1]], 0))
  return multipliers * a_adj_inv
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:8,代码来源:linalg_grad.py

示例8: _MatrixDeterminantGrad

def _MatrixDeterminantGrad(op, grad):
  """Gradient for MatrixDeterminant.

  Returns:
    gradient
  Args:
    op: op
    grad: grad
  """
  a = op.inputs[0]
  c = op.outputs[0]
  ainv = linalg_ops.matrix_inverse(a)
  return grad * c * array_ops.transpose(ainv)
开发者ID:Billlee1231,项目名称:tensorflow,代码行数:13,代码来源:linalg_grad.py

示例9: _verifyInverse

 def _verifyInverse(self, x, np_type):
   for adjoint in False, True:
     y = x.astype(np_type)
     with self.test_session(use_gpu=True):
       # Verify that x^{-1} * x == Identity matrix.
       inv = linalg_ops.matrix_inverse(y, adjoint=adjoint)
       tf_ans = math_ops.matmul(inv, y, adjoint_b=adjoint)
       np_ans = np.identity(y.shape[-1])
       if x.ndim > 2:
         tiling = list(y.shape)
         tiling[-2:] = [1, 1]
         np_ans = np.tile(np_ans, tiling)
       out = tf_ans.eval()
       self.assertAllClose(np_ans, out)
       self.assertShapeEqual(y, tf_ans)
开发者ID:LiorPe,项目名称:tensorflow,代码行数:15,代码来源:matrix_inverse_op_test.py

示例10: _define_distance_to_clusters

  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:AliMiraftab,项目名称:tensorflow,代码行数:37,代码来源:gmm_ops.py

示例11: _image_projective_transform_grad

def _image_projective_transform_grad(op, grad):
  images = op.inputs[0]
  transforms = op.inputs[1]

  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)
  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:finardi,项目名称:tensorflow,代码行数:36,代码来源:image_ops.py

示例12: MatrixInverseCompositeGrad

def MatrixInverseCompositeGrad(l, grad):
  l_inverse = linalg_ops.matrix_inverse(l)
  return _GradWithInverseL(l, l_inverse, grad)
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:3,代码来源:cholesky_op_test.py

示例13: posdef_inv_matrix_inverse

def posdef_inv_matrix_inverse(tensor, identity, damping):
  """Computes inverse(tensor + damping * identity) directly."""
  return linalg_ops.matrix_inverse(tensor + damping * identity)
开发者ID:abidrahmank,项目名称:tensorflow,代码行数:3,代码来源:utils.py

示例14: _MatrixDeterminantGrad

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)
  return grad * c * a_adj_inv
开发者ID:Baaaaam,项目名称:tensorflow,代码行数:6,代码来源:linalg_grad.py

示例15: testWrongDimensions

 def testWrongDimensions(self):
   # The input to the inverse should be at least a 2-dimensional tensor.
   tensor3 = constant_op.constant([1., 2.])
   with self.assertRaises(ValueError):
     linalg_ops.matrix_inverse(tensor3)
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:5,代码来源:matrix_inverse_op_test.py


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