iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📈

Understanding Matrix Product States

に公開

Purpose

When I tried to understand Matrix Product States (MPS), I didn't get it at all, so I'm going to do some drawing until I feel like I somewhat understand "Matrix Product." [1]

Matrix Product is apparently an example of a tensor network. In the diagram below, representing the tensor on the left as shown on the right is called a Matrix Product. [2]

Tensor of Decomposition into Matrix Product
→

According to reference [2], a "Matrix Product" is explained not as a product of matrices, but as a multi-legged tensor.

Since I feel like the meaning won't eventually become clear just by staring at such diagrams repeatedly, I'd like to consider a specific, simple tensor T^{ijk}.

Matrix Product through a Concrete Example

Considering a 3rd-order tensor

Consider a 3rd-order tensor T^{ijk} where each dimension is 3, as shown below. The reason things are generally confusing is probably because what is called a "dimension" varies slightly depending on the context.

I'll also include an example calculation using NumPy:

T = np.array(range(27)).reshape(3, 3, 3)
print(T)

[[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]]

[[ 9 10 11]
[12 13 14]
[15 16 17]]

[[18 19 20]
[21 22 23]
[24 25 26]]]

Grouping tensor indices

Referring to reference [2], let's group the indices of T^{ijk} into two groups: i and jk. Visually, it looks like this:

Here, we flatten the jk part into a 1st-order tensor on the right. If we assume that the indices of jk are summarized as h = (j,k) at this point, then T^{ijk} can be viewed as a tensor A^{ih}.

A = T.reshape(3, -1)
print(A, f'{A.shape=}')

[[ 0 1 2 3 4 5 6 7 8]
[ 9 10 11 12 13 14 15 16 17]
[18 19 20 21 22 23 24 25 26]] A.shape=(3, 9)

Performing Singular Value Decomposition (SVD)

If we treat the aforementioned A^{ih} as a matrix and perform singular value decomposition (SVD), it results in the following diagram:

Then, if we take the product of \Sigma \cdot V^*, it looks like the diagram below:

T1, s, vh = np.linalg.svd(A)
s = (s * np.eye(3)).flatten()
s.resize(9, 3)
s = s.T
S = (s @ vh).reshape(3, 3, 3)
print(f'{T1.shape=}, {s.shape=}, {vh.shape=}, {S.shape=}')

T1.shape=(3, 3), s.shape=(3, 9), vh.shape=(9, 9), S.shape=(3, 3, 3)

When drawn as a tensor diagram, it looks like this:

Written as a formula, it would be:

\begin{align*} T^{ijk} = T_1^{i\ell} S^{\ell jk} \end{align*}

Note that the bond dimension is 3, which appears in T1.shape[1] or S.shape[0].

Repeating the process...

By grouping the indices of tensor S^{\ell jk} as S^{(\ell j) k} and executing the same procedure, we arrive at the diagram shown at the beginning:

Verifying with Python calculations

Since we have already obtained T1 and S, let's decompose S into a matrix product.

A2 = S.reshape(-1, 3)
u2, s2, T3 = np.linalg.svd(A2)
s2 = (s2 * np.eye(3)).flatten()
s2.resize(9, 3)
T2 = (u2 @ s2).reshape(3, 3, 3)
print(f'{T1.shape=}, {T2.shape=}, {T3.shape=}')

T1.shape=(3, 3), T2.shape=(3, 3, 3), T3.shape=(3, 3)

Now, the tensor T^{ijk} has been decomposed into a matrix product:

\begin{align*} T^{ijk} = T_1^{i\ell} T_2^{\ell j m} T_3^{mk} \end{align*}

Verification

Let's perform the contraction calculation:

T12 = np.einsum('il,ljm', T1, T2)
T123 = np.einsum('ijm,mk', T12, T3)
print(np.round(T123, 2))

[[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]]

[[ 9. 10. 11.]
[12. 13. 14.]
[15. 16. 17.]]

[[18. 19. 20.]
[21. 22. 23.]
[24. 25. 26.]]]

We obtained the original tensor T.
Just to be sure, looking at T1, T2, and T3, they look like this:

print(np.round(T1, 2))

[[-0.17 0.9 0.41]
[-0.51 0.28 -0.82]
[-0.85 -0.34 0.41]]

print(np.round(T2, 2))

[[[-36.97 -0.44 0. ]
[-44.85 -0.07 -0. ]
[-52.73 0.3 -0. ]]

[[ -4.83 1.4 0. ]
[ -0.51 1.2 0. ]
[ 3.82 1. 0. ]]

[[ -0. -0. 0. ]
[ 0. -0. -0. ]
[ -0. -0. -0. ]]]

print(np.round(T3, 2))

[[ 0.54 0.58 0.61]
[-0.73 -0.03 0.68]
[ 0.41 -0.82 0.41]]

Summary

In the end, I still don't understand the real benefits of using a matrix product, but I've explored a simple sample to see what steps are required to bring it into the matrix product format.
I haven't looked into other decomposition methods or uniqueness yet, but as this is the first step, I'd like to investigate the remaining questions over time.

References

[1] Matrix product state simulation method
[2] Foundations and Applications of Tensor Networks (Japanese Title: テンソルネットワークの基礎と応用)
[3] Matrix Product State / Tensor Train

脚注
  1. I looked through references [1], [2], and [3] in that order, but I still didn't understand anything. ↩︎

  2. The extra clutter in the right image is because I'm reusing the diagram. ↩︎

GitHubで編集を提案

Discussion