LinearOperator 的作用类似于 [batch] 方单位矩阵。
继承自:LinearOperator,Module
用法
tf.linalg.LinearOperatorIdentity(
num_rows, batch_shape=None, dtype=None, is_non_singular=True,
is_self_adjoint=True, is_positive_definite=True, is_square=True,
assert_proper_shapes=False, name='LinearOperatorIdentity'
)参数
-
num_rows标量非负整数Tensor。相应单位矩阵中的行数。 -
batch_shape可选1-D整数Tensor。前导维度的形状。如果None,则此运算符没有前导维度。 -
dtype此运算符表示的矩阵的数据类型。 -
is_non_singular期望这个运算符是非奇异的。 -
is_self_adjoint期望这个算子等于它的厄米转置。 -
is_positive_definite期望这个算子是正定的,意思是二次形式x^H A x对所有非零具有正实部x.请注意,我们不要求算子自伴是正定的。看:https://en.wikipedia.org/wiki/Positive-definite_matrix#Extension_for_non-symmetric_matrices -
is_square期望此运算符的行为类似于方形 [batch] 矩阵。 -
assert_proper_shapesPythonbool。如果False,仅执行初始化和方法参数是否具有正确形状的静态检查。如果True和静态检查没有定论,则将断言添加到图中。 -
name此LinearOperator的名称
抛出
-
ValueError如果num_rows被静态确定为非标量或负数。 -
ValueError如果batch_shape被静态确定为不是一维或负数。 -
ValueError如果以下任何一项不是True:{is_self_adjoint, is_non_singular, is_positive_definite}。 -
TypeError如果num_rows或batch_shape是 ref-type(例如变量)。
属性
-
H返回当前的伴随LinearOperator.给定
A表示此LinearOperator,返回A*。请注意,调用self.adjoint()和self.H是等效的。 -
batch_shapeTensorShape这批尺寸的LinearOperator.如果此运算符的作用类似于带有
A.shape = [B1,...,Bb, M, N]的批处理矩阵A,则返回TensorShape([B1,...,Bb]),相当于A.shape[:-2] -
domain_dimension此运算符的域的维度(在向量空间的意义上)。如果此运算符的作用类似于带有
A.shape = [B1,...,Bb, M, N]的批处理矩阵A,则返回N。 -
dtypeTensor的DType由此LinearOperator处理。 -
graph_parents这个的图依赖列表LinearOperator. (已弃用)警告:此函数已弃用。它将在未来的版本中删除。更新说明:请勿调用
graph_parents。 -
is_non_singular -
is_positive_definite -
is_self_adjoint -
is_square返回True/False取决于此运算符是否为正方形。 -
parameters用于实例化此LinearOperator的参数字典。 -
range_dimension此运算符范围的维度(在向量空间的意义上)。如果此运算符的作用类似于带有
A.shape = [B1,...,Bb, M, N]的批处理矩阵A,则返回M。 -
shapeTensorShape这个的LinearOperator.如果此运算符的作用类似于带有
A.shape = [B1,...,Bb, M, N]的批处理矩阵A,则返回TensorShape([B1,...,Bb, M, N]),等效于A.shape。 -
tensor_rank与此运算符对应的矩阵的秩(在张量的意义上)。如果此运算符的作用类似于带有
A.shape = [B1,...,Bb, M, N]的批处理矩阵A,则返回b + 2。
该运算符的作用类似于 [batch] 单位矩阵 A ,对于某些 b >= 0 ,其形状为 [B1,...,Bb, N, N] 。第一个 b 索引索引批处理成员。对于每个批次索引 (i1,...,ib) , A[i1,...,ib,::] 是一个 N x N 矩阵。此矩阵A 未具体化,但为了广播此形状将是相关的。
LinearOperatorIdentity 使用 num_rows 以及可选的 batch_shape 和 dtype 参数进行初始化。如果 batch_shape 是 None ,则此运算符有效地传递所有参数。如果提供了batch_shape,则可能会发生广播,这将需要制作副本。
# Create a 2 x 2 identity matrix.
operator = LinearOperatorIdentity(num_rows=2, dtype=tf.float32)
operator.to_dense()
==> [[1., 0.]
[0., 1.]]
operator.shape
==> [2, 2]
operator.log_abs_determinant()
==> 0.
x = ... Shape [2, 4] Tensor
operator.matmul(x)
==> Shape [2, 4] Tensor, same as x.
y = tf.random.normal(shape=[3, 2, 4])
# Note that y.shape is compatible with operator.shape because operator.shape
# is broadcast to [3, 2, 2].
# This broadcast does NOT require copying data, since we can infer that y
# will be passed through without changing shape. We are always able to infer
# this if the operator has no batch_shape.
x = operator.solve(y)
==> Shape [3, 2, 4] Tensor, same as y.
# Create a 2-batch of 2x2 identity matrices
operator = LinearOperatorIdentity(num_rows=2, batch_shape=[2])
operator.to_dense()
==> [[[1., 0.]
[0., 1.]],
[[1., 0.]
[0., 1.]]]
# Here, even though the operator has a batch shape, the input is the same as
# the output, so x can be passed through without a copy. The operator is able
# to detect that no broadcast is necessary because both x and the operator
# have statically defined shape.
x = ... Shape [2, 2, 3]
operator.matmul(x)
==> Shape [2, 2, 3] Tensor, same as x
# Here the operator and x have different batch_shape, and are broadcast.
# This requires a copy, since the output is different size than the input.
x = ... Shape [1, 2, 3]
operator.matmul(x)
==> Shape [2, 2, 3] Tensor, equal to [x, x]
形状兼容性
该运算符作用于具有兼容形状的 [batch] 矩阵。 x 是与 matmul 和 solve 的形状兼容的批处理矩阵,如果
operator.shape = [B1,...,Bb] + [N, N], with b >= 0
x.shape = [C1,...,Cc] + [N, R],
and [C1,...,Cc] broadcasts with [B1,...,Bb] to [D1,...,Dd]
性能
如果 batch_shape 初始化参数是 None :
operator.matmul(x)是O(1)operator.solve(x)是O(1)operator.determinant()是O(1)
如果提供了batch_shape 初始化arg,并且静态检查不能排除广播的需要:
operator.matmul(x)是O(D1*...*Dd*N*R)operator.solve(x)是O(D1*...*Dd*N*R)operator.determinant()是O(B1*...*Bb)
矩阵属性提示
此 LinearOperator 使用 is_X 形式的布尔标志初始化,用于 X = non_singular, self_adjoint, positive_definite, square 。它们具有以下含义:
- 如果
is_X == True,调用者应该期望操作符具有属性X。这是一个应该实现的承诺,但不是运行时断言。例如,有限的浮点精度可能会导致违反这些承诺。 - 如果
is_X == False,调用者应该期望操作符没有X。 - 如果
is_X == None(默认),调用者应该没有任何期望。
相关用法
- Python tf.linalg.LinearOperatorIdentity.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorIdentity.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorIdentity.matvec用法及代码示例
- Python tf.linalg.LinearOperatorIdentity.solve用法及代码示例
- Python tf.linalg.LinearOperatorIdentity.matmul用法及代码示例
- Python tf.linalg.LinearOperatorIdentity.assert_non_singular用法及代码示例
- Python tf.linalg.LinearOperatorInversion.solve用法及代码示例
- Python tf.linalg.LinearOperatorInversion.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorInversion.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorInversion用法及代码示例
- Python tf.linalg.LinearOperatorInversion.matmul用法及代码示例
- Python tf.linalg.LinearOperatorInversion.matvec用法及代码示例
- Python tf.linalg.LinearOperatorInversion.assert_non_singular用法及代码示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代码示例
- Python tf.linalg.LinearOperatorPermutation.solve用法及代码示例
- Python tf.linalg.LinearOperatorKronecker.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.matvec用法及代码示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorLowerTriangular.matvec用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.linalg.LinearOperatorIdentity。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
