本文整理汇总了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
示例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)
示例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]
示例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
示例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)
示例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