将LinearOperators 组合成一个块状下三角矩阵。
继承自:LinearOperator,Module
用法
tf.linalg.LinearOperatorBlockLowerTriangular(
operators, is_non_singular=None, is_self_adjoint=None,
is_positive_definite=None, is_square=None,
name='LinearOperatorBlockLowerTriangular'
)参数
-
operatorsLinearOperator对象的可迭代对象的可迭代对象,每个对象都具有相同的dtype。operators的每个元素对应于一个行分区,按从上到下的顺序。每个row-partition 中的运算符从左到右填写。例如,operators = [[op_0], [op_1, op_2], [op_3, op_4, op_5]]创建一个具有完整块结构[[op_0, 0, 0], [op_1, op_2, 0], [op_3, op_4, op_5]]的LinearOperatorBlockLowerTriangular。第i行中的运算符数量必须等于i,以便每个运算符落在块结构的对角线上或之下。LinearOperator落在对角线上的(每行的最后一个元素)必须是正方形的。其他LinearOperator的域维度必须等于同一column-partition 中的LinearOperator的域维度,并且范围维度等于同一row-partition 中的LinearOperator的范围维度。 -
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] 矩阵。如果设置为False,这将引发ValueError。 -
name此LinearOperator的名称。
抛出
-
TypeError如果所有运算符都没有相同的dtype。 -
ValueError如果operators为空、包含错误数量的元素或包含形状不兼容的运算符。
属性
-
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取决于此运算符是否为正方形。 -
operators -
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。
该运算符使用嵌套的线性运算符列表进行初始化,这些线性运算符组合成一个新的LinearOperator,其基础矩阵表示为正方形,并且每个运算符都在主对角线之上或之下,其他地方为零。外部列表的每个元素是与块结构的row-partition相对应的LinearOperators列表。 row-partion i 中的 LinearOperator 的数量必须等于 i 。
例如,按块 3 x 3 LinearOperatorBlockLowerTriangular 使用列表 [[op_00], [op_10, op_11], [op_20, op_21, op_22]] 进行初始化,其中 op_ij , i < 3, j <= i 是 LinearOperator 实例。 LinearOperatorBlockLowerTriangular 表现为以下块状矩阵,其中 0 表示 appropriately-sized [batch] 零矩阵:
[[op_00, 0, 0],
[op_10, op_11, 0],
[op_20, op_21, op_22]]
对角线上的每个 op_jj 都需要表示一个方阵,因此将具有形状 batch_shape_j + [M_j, M_j] 。分块结构的j 行中的LinearOperator 必须具有与op_jj 相同的range_dimension,并且j 列中的LinearOperators 必须具有与op_jj 相同的domain_dimension。
如果对角线上的每个 op_jj 具有形状 batch_shape_j + [M_j, M_j] ,则组合运算符具有形状 broadcast_batch_shape + [sum M_j, sum M_j] ,其中 broadcast_batch_shape 是 batch_shape_j , j = 0, 1, ..., J 的相互广播,假设中间批次形状广播。即使组合形状被很好地定义,组合算子的方法也可能由于定义算子的方法中缺乏广播能力而失败。
例如,要创建一个由三个 2 x 2 运算符组合而成的 4 x 4 线性运算符:
>>> operator_0 = tf.linalg.LinearOperatorFullMatrix([[1., 2.], [3., 4.]])
>>> operator_1 = tf.linalg.LinearOperatorFullMatrix([[1., 0.], [0., 1.]])
>>> operator_2 = tf.linalg.LinearOperatorLowerTriangular([[5., 6.], [7., 8]])
>>> operator = LinearOperatorBlockLowerTriangular(
... [[operator_0], [operator_1, operator_2]])
operator.to_dense()
<tf.Tensor:shape=(4, 4), dtype=float32, numpy=
array([[1., 2., 0., 0.],
[3., 4., 0., 0.],
[1., 0., 5., 0.],
[0., 1., 7., 8.]], dtype=float32)>
operator.shape
TensorShape([4, 4])
operator.log_abs_determinant()
<tf.Tensor:shape=(), dtype=float32, numpy=4.3820267>
x0 = [[1., 6.], [-3., 4.]]
x1 = [[0., 2.], [4., 0.]]
x = tf.concat([x0, x1], 0) # Shape [2, 4] Tensor
operator.matmul(x)
<tf.Tensor:shape=(4, 2), dtype=float32, numpy=
array([[-5., 14.],
[-9., 34.],
[ 1., 16.],
[29., 18.]], dtype=float32)>
上面的matmul等价于:
>>> tf.concat([operator_0.matmul(x0),
... operator_1.matmul(x0) + operator_2.matmul(x1)], axis=0)
<tf.Tensor:shape=(4, 2), dtype=float32, numpy=
array([[-5., 14.],
[-9., 34.],
[ 1., 16.],
[29., 18.]], dtype=float32)>
形状兼容性
该运算符作用于具有兼容形状的 [batch] 矩阵。 x 是与 matmul 和 solve 的形状兼容的批处理矩阵,如果
operator.shape = [B1,...,Bb] + [M, N], with b >= 0
x.shape = [B1,...,Bb] + [N, R], with R >= 0.
例如:
创建一个 [2, 3] 批 4 x 4 线性算子:
>>> matrix_44 = tf.random.normal(shape=[2, 3, 4, 4])
>>> operator_44 = tf.linalg.LinearOperatorFullMatrix(matrix_44)
创建一个 [1, 3] 批次的 5 x 4 线性运算符:
>>> matrix_54 = tf.random.normal(shape=[1, 3, 5, 4])
>>> operator_54 = tf.linalg.LinearOperatorFullMatrix(matrix_54)
创建一个 [1, 3] 批 5 x 5 线性运算符:
>>> matrix_55 = tf.random.normal(shape=[1, 3, 5, 5])
>>> operator_55 = tf.linalg.LinearOperatorFullMatrix(matrix_55)
组合创建一个 [2, 3] 批次的 9 x 9 运算符:
>>> operator_99 = LinearOperatorBlockLowerTriangular(
... [[operator_44], [operator_54, operator_55]])
>>> operator_99.shape
TensorShape([2, 3, 9, 9])
创建一个形状 [2, 1, 9] 的向量批并将运算符应用于它。
>>> x = tf.random.normal(shape=[2, 1, 9])
>>> y = operator_99.matvec(x)
>>> y.shape
TensorShape([2, 3, 9])
创建向量的块状列表并将运算符应用于它。返回一个分块列表。
>>> x4 = tf.random.normal(shape=[2, 1, 4])
>>> x5 = tf.random.normal(shape=[2, 3, 5])
>>> y_blockwise = operator_99.matvec([x4, x5])
>>> y_blockwise[0].shape
TensorShape([2, 3, 4])
>>> y_blockwise[1].shape
TensorShape([2, 3, 5])
性能
假设operator是由Drow-partitions和Dcolumn-partitions组成的LinearOperatorBlockLowerTriangular,这样算子的总数就是N = D * (D + 1) // 2。
operator.matmul的复杂度等于各个运算符的matmul复杂度之和。operator.solve的复杂度等于对角线上运算符的solve复杂度和对角线外运算符的matmul复杂度之和。operator.determinant的复杂度等于对角线上运算符的determinant复杂度之和。
矩阵属性提示
此 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.LinearOperatorBlockLowerTriangular.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.matmul用法及代码示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.solve用法及代码示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.assert_non_singular用法及代码示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.matvec用法及代码示例
- Python tf.linalg.LinearOperatorBlockDiag.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorBlockDiag.assert_non_singular用法及代码示例
- Python tf.linalg.LinearOperatorBlockDiag.matmul用法及代码示例
- Python tf.linalg.LinearOperatorBlockDiag.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorBlockDiag.matvec用法及代码示例
- Python tf.linalg.LinearOperatorBlockDiag用法及代码示例
- Python tf.linalg.LinearOperatorBlockDiag.solve用法及代码示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代码示例
- Python tf.linalg.LinearOperatorIdentity.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorPermutation.solve用法及代码示例
- Python tf.linalg.LinearOperatorKronecker.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.matvec用法及代码示例
- Python tf.linalg.LinearOperatorLowerTriangular.matvec用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.linalg.LinearOperatorBlockLowerTriangular。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
