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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
