scipy.linalg.

matmul_toeplitz#

scipy.linalg.matmul_toeplitz(c_or_cr, x, check_finite=False, workers=None)[原始碼]#

使用 FFT 的高效 Toeplitz 矩陣-矩陣乘法

此函數返回 Toeplitz 矩陣與稠密矩陣之間的矩陣乘法結果。

Toeplitz 矩陣具有常數對角線,其中 c 作為第一列,r 作為第一行。如果未給定 r,則假定 r == conjugate(c)

警告

從 SciPy 1.17 開始,多維輸入將被視為批次處理,而不是 ravel 化的。為了保留現有行為,請在將參數傳遞給 matmul_toeplitz 之前 ravel 參數。

參數:
c_or_crarray_like 或 (array_like, array_like) 元組

向量 c,或陣列元組 (c, r)。如果未提供,則假定 r = conjugate(c);在這種情況下,如果 c[0] 是實數,則 Toeplitz 矩陣是 Hermitian 矩陣。r[0] 會被忽略;Toeplitz 矩陣的第一列是 [c[0], r[1:]]

x(M,) 或 (M, K) array_like

要與之相乘的矩陣。

check_finitebool,可選

是否檢查輸入矩陣是否僅包含有限數字。 停用可能會提高效能,但如果輸入包含無限大或 NaN,可能會導致問題(結果完全是 NaN)。

workersint,可選

傳遞給 scipy.fft.fft 和 ifft。用於平行計算的最大工作進程數。如果為負數,則值會從 os.cpu_count() 環繞。請參閱 scipy.fft.fft 以取得更多詳細資訊。

返回:
T @ x(M,) 或 (M, K) ndarray

矩陣乘法 T @ x 的結果。返回值的形狀與 x 的形狀相符。

參見

toeplitz

Toeplitz 矩陣

solve_toeplitz

使用 Levinson 遞迴求解 Toeplitz 系統

註解

Toeplitz 矩陣嵌入在循環矩陣中,並且使用 FFT 來有效計算矩陣-矩陣乘積。

由於計算基於 FFT,因此整數輸入將產生浮點輸出。這與 NumPy 的 matmul 不同,後者保留輸入的資料類型。

這部分基於在 [1] 中找到的實作,該實作在 MIT 許可下授權。有關該方法的更多資訊,請參閱參考文獻 [2]。參考文獻 [3][4] 具有更多 Python 的參考實作。

在版本 1.6.0 中新增。

參考文獻

[1]

Jacob R Gardner, Geoff Pleiss, David Bindel, Kilian Q Weinberger, Andrew Gordon Wilson, “GPyTorch: Blackbox Matrix-Matrix Gaussian Process Inference with GPU Acceleration”,貢獻者包括 Max Balandat 和 Ruihan Wu。線上提供:cornellius-gp/gpytorch

[2]

J. Demmel, P. Koev, and X. Li, “A Brief Survey of Direct Linear Solvers”。在 Z. Bai, J. Demmel, J. Dongarra, A. Ruhe, 和 H. van der Vorst, 編輯。《Templates for the Solution of Algebraic Eigenvalue Problems: A Practical Guide》。SIAM,費城,2000 年。可在此處取得:http://www.netlib.org/utk/people/JackDongarra/etemplates/node384.html

[3]

R. Scheibler, E. Bezzam, I. Dokmanic, Pyroomacoustics:用於音訊房間模擬和陣列處理演算法的 Python 套件,Proc. IEEE ICASSP, Calgary, CA, 2018. LCAV/pyroomacoustics pyroomacoustics/adaptive/util.py

[4]

Marano S, Edwards B, Ferrari G and Fah D (2017), “Fitting Earthquake Spectra: Colored Noise and Incomplete Data”, Bulletin of the Seismological Society of America., January, 2017. Vol. 107(1), pp. 276-291.

範例

將 Toeplitz 矩陣 T 與矩陣 x 相乘

    [ 1 -1 -2 -3]       [1 10]
T = [ 3  1 -1 -2]   x = [2 11]
    [ 6  3  1 -1]       [2 11]
    [10  6  3  1]       [5 19]

若要指定 Toeplitz 矩陣,僅需第一列和第一行。

>>> import numpy as np
>>> c = np.array([1, 3, 6, 10])    # First column of T
>>> r = np.array([1, -1, -2, -3])  # First row of T
>>> x = np.array([[1, 10], [2, 11], [2, 11], [5, 19]])
>>> from scipy.linalg import toeplitz, matmul_toeplitz
>>> matmul_toeplitz((c, r), x)
array([[-20., -80.],
       [ -7.,  -8.],
       [  9.,  85.],
       [ 33., 218.]])

透過建立完整的 Toeplitz 矩陣並將其與 x 相乘來檢查結果。

>>> toeplitz(c, r) @ x
array([[-20, -80],
       [ -7,  -8],
       [  9,  85],
       [ 33, 218]])

永遠不會明確形成完整矩陣,因此此常式適用於非常大的 Toeplitz 矩陣。

>>> n = 1000000
>>> matmul_toeplitz([1] + [0]*(n-1), np.ones(n))
array([1., 1., 1., ..., 1., 1., 1.], shape=(1000000,))