LinearOperator 就像循環矩陣一樣。
繼承自:LinearOperator,Module
用法
tf.linalg.LinearOperatorCirculant(
spectrum, input_output_dtype=tf.dtypes.complex64, is_non_singular=None,
is_self_adjoint=None, is_positive_definite=None, is_square=True,
name='LinearOperatorCirculant'
)參數
-
spectrum形狀[B1,...,Bb, N]Tensor。允許的數據類型:float16,float32,float64,complex64,complex128。類型可以不同於input_output_dtype -
input_output_dtypedtype用於輸入/輸出。 -
is_non_singular期望這個運算符是非奇異的。 -
is_self_adjoint期望這個算子等於它的厄米轉置。如果spectrum是真實的,這將永遠是真實的。 -
is_positive_definite期望這個算子是正定的,意思是二次形式x^H A x對所有非零具有正實部x.請注意,我們不要求算子自伴是正定的。看:https://en.wikipedia.org/wiki/Positive-definite_matrix
#Extension_for_non_symmetric_matrices -
is_square期望此運算符的行為類似於方形 [batch] 矩陣。 -
name附加到此類創建的所有操作的名稱。
屬性
-
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] -
block_depth遞歸定義的循環塊的深度定義了這個Operator.使用
A這個Operator的密集表示,block_depth = 1表示A是對稱循環。例如,A = |w z y x| |x w z y| |y x w z| |z y x w|block_depth = 2表示A是具有對稱循環塊的塊對稱循環。例如,使用W,X,Y,Z對稱循環,A = |W Z Y X| |X W Z Y| |Y X W Z| |Z Y X W|block_depth = 3表示A是塊對稱循環,塊對稱循環塊。 -
block_shape -
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。 -
spectrum -
tensor_rank與此運算符對應的矩陣的秩(在張量的意義上)。如果此運算符的作用類似於帶有
A.shape = [B1,...,Bb, M, N]的批處理矩陣A,則返回b + 2。
該運算符的作用類似於循環矩陣 A ,對於某些 b >= 0 ,形狀為 [B1,...,Bb, N, N] 。第一個 b 索引索引批處理成員。對於每個批次索引 (i1,...,ib) , A[i1,...,ib,::] 是一個 N x N 矩陣。此矩陣A 未具體化,但為了廣播此形狀將是相關的。
循環矩陣的說明
循環意味著 A 的條目由單個向量生成,即卷積核 h : A_{mn}:= h_{m-n mod N} 。使用 h = [w, x, y, z] ,
A = |w z y x|
|x w z y|
|y x w z|
|z y x w|
這意味著矩陣乘法 v = Au 的結果具有在 h 與 u 的 Lth 列之間進行循環卷積的 Lth 列。
頻譜方麵的說明
在 [batch] 頻譜 H 和傅裏葉變換方麵有一個等效的說明。這裏我們考慮A.shape = [N, N] 並忽略批量維度。定義離散傅裏葉變換 (DFT) 及其逆
DFT[ h[n] ] = H[k]:= sum_{n = 0}^{N - 1} h_n e^{-i 2pi k n / N}
IDFT[ H[k] ] = h[n] = N^{-1} sum_{k = 0}^{N - 1} H_k e^{i 2pi k n / N}
從這些定義中,我們看到
H[0] = sum_{n = 0}^{N - 1} h_n
H[1] = "the first positive frequency"
H[N - 1] = "the first negative frequency"
粗略地說,使用 * 逐元素乘法,矩陣乘法等於傅立葉乘法器的作用:A u = IDFT[ H * DFT[u] ]。準確地說,給定 [N, R] 矩陣 u ,讓 DFT[u] 為 [N, R] 矩陣,其中 rth 列等於 u 的 rth 列的 DFT。類似地定義IDFT。矩陣乘法可以按列表示:
(A u)_r = IDFT[ H * (DFT[u])_r ]
從譜中推導出算子屬性。
令 U 為 kth 歐幾裏得基向量,而 U = IDFT[u] 。上麵的公式表明 A U = H_k * U 。我們得出結論H的元素是這個算子的特征值。所以
- 此運算符是正定的當且僅當
Real{H} > 0。
傅立葉變換的一般性質是厄米特函數和實值變換之間的對應關係。
假設 H.shape = [B1,...,Bb, N] 。我們說 H 是 Hermitian 譜,如果 % 表示模除,
H[..., n % N] = ComplexConjugate[ H[..., (-n) % N] ]
- 當且僅當
H是 Hermitian 時,此運算符對應於實矩陣。 - 當且僅當
H為實數時,此運算符是自伴的。
參見例如“Discrete-Time 信號處理”,奧本海姆和謝弗。
自伴正定算子示例
# spectrum is real ==> operator is self-adjoint
# spectrum is positive ==> operator is positive definite
spectrum = [6., 4, 2]
operator = LinearOperatorCirculant(spectrum)
# IFFT[spectrum]
operator.convolution_kernel()
==> [4 + 0j, 1 + 0.58j, 1 - 0.58j]
operator.to_dense()
==> [[4 + 0.0j, 1 - 0.6j, 1 + 0.6j],
[1 + 0.6j, 4 + 0.0j, 1 - 0.6j],
[1 - 0.6j, 1 + 0.6j, 4 + 0.0j]]
根據實際卷積核定義的示例
# convolution_kernel is real ==> spectrum is Hermitian.
convolution_kernel = [1., 2., 1.]]
spectrum = tf.signal.fft(tf.cast(convolution_kernel, tf.complex64))
# spectrum is Hermitian ==> operator is real.
# spectrum is shape [3] ==> operator is shape [3, 3]
# We force the input/output type to be real, which allows this to operate
# like a real matrix.
operator = LinearOperatorCirculant(spectrum, input_output_dtype=tf.float32)
operator.to_dense()
==> [[ 1, 1, 2],
[ 2, 1, 1],
[ 1, 2, 1]]
Hermitian 譜示例
# spectrum is shape [3] ==> operator is shape [3, 3]
# spectrum is Hermitian ==> operator is real.
spectrum = [1, 1j, -1j]
operator = LinearOperatorCirculant(spectrum)
operator.to_dense()
==> [[ 0.33 + 0j, 0.91 + 0j, -0.24 + 0j],
[-0.24 + 0j, 0.33 + 0j, 0.91 + 0j],
[ 0.91 + 0j, -0.24 + 0j, 0.33 + 0j]
當頻譜為 Hermitian 時強製實數 dtype 的示例
# spectrum is shape [4] ==> operator is shape [4, 4]
# spectrum is real ==> operator is self-adjoint
# spectrum is Hermitian ==> operator is real
# spectrum has positive real part ==> operator is positive-definite.
spectrum = [6., 4, 2, 4]
# Force the input dtype to be float32.
# Cast the output to float32. This is fine because the operator will be
# real due to Hermitian spectrum.
operator = LinearOperatorCirculant(spectrum, input_output_dtype=tf.float32)
operator.shape
==> [4, 4]
operator.to_dense()
==> [[4, 1, 0, 1],
[1, 4, 1, 0],
[0, 1, 4, 1],
[1, 0, 1, 4]]
# convolution_kernel = tf.signal.ifft(spectrum)
operator.convolution_kernel()
==> [4, 1, 0, 1]
性能
假設 operator 是形狀為 [N, N] 和 x.shape = [N, R] 的 LinearOperatorCirculant。然後
operator.matmul(x)是O(R*N*Log[N])operator.solve(x)是O(R*N*Log[N])operator.determinant()涉及大小Nreduce_prod。
如果相反 operator 和 x 具有形狀 [B1,...,Bb, N, N] 和 [B1,...,Bb, N, R] ,則每個操作的複雜性都會增加 B1*...*Bb 。
矩陣屬性提示
此 LinearOperator 使用 is_X 形式的布爾標誌初始化,用於 X = non_singular, self_adjoint, positive_definite, square 。它們具有以下含義:
- 如果
is_X == True,調用者應該期望操作符具有屬性X。這是一個應該實現的承諾,但不是運行時斷言。例如,有限的浮點精度可能會導致違反這些承諾。 - 如果
is_X == False,調用者應該期望操作符沒有X。 - 如果
is_X == None(默認),調用者應該沒有任何期望。
參考:
Toeplitz 和循環矩陣 - 評論:灰色,2006 年 (pdf)
相關用法
- Python tf.linalg.LinearOperatorCirculant2D.solve用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.diag_part用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.assert_non_singular用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant.diag_part用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant.assert_non_singular用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.assert_non_singular用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.matmul用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.solve用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant.solve用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.matmul用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.diag_part用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant.matmul用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.linalg.LinearOperatorCirculant。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
