Made by Xinyu Chen • 🌐 https://xinychen.github.io
- Kronecker分解
- 撰写本文的初衷在于传播知识,为感兴趣的读者提供参考素材。
- 禁止将本文放在其他网站上供人下载,唯一下载网站为https://xinychen.github.io/books/tensor_book.pdf。
- 禁止将本文用于任何形式的商业活动。
例. 计算Kronecker积并求Kronecker分解。
- 计算Kronecker积
import numpy as np
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6, 7], [8, 9, 10]])
X = np.kron(A, B)
print('X = ')
print(X)
- 求Kronecker分解
def permute(mat, A_dim1, A_dim2, B_dim1, B_dim2):
ans = np.zeros((A_dim1 * A_dim2, B_dim1 * B_dim2))
for j in range(A_dim2):
for i in range(A_dim1):
ans[A_dim1 * j + i, :] = mat[i * B_dim1 : (i + 1) * B_dim1,
j * B_dim2 : (j + 1) * B_dim2].reshape(B_dim1 * B_dim2, order = 'F')
return ans
X_tilde = permute(X, 2, 2, 2, 3)
print('X_tilde = ')
print(X_tilde)
print()
u, s, v = np.linalg.svd(X_tilde, full_matrices = False)
A_hat = np.sqrt(s[0]) * u[:, 0].reshape(2, 2, order = 'F')
B_hat = np.sqrt(s[0]) * v[0, :].reshape(2, 3, order = 'F')
print('A_hat = ')
print(A_hat)
print()
print('B_hat = ')
print(B_hat)