テンソルトレインの自明な例について考える
\begin{equation}
A\left(i_1, i_2, i_3\right):=i_1+i_2+i_3,
\end{equation}
ここで、
\begin{equation}
i_1 \in\{1,2,3\}, \quad i_2 \in\{1,2,3,4\}, \quad i_3 \in\{1,2,3,4,5\} .
\end{equation}
である。
このTT形式は、
\begin{equation}
A\left(i_1, i_2, i_3\right)=G_1\left[i_1\right] G_2\left[i_2\right] G_3\left[i_3\right],
\end{equation}
ここで、
\begin{equation}
G_1\left[i_1\right]:=\left[\begin{array}{ll}
i_1 & 1
\end{array}\right], \quad G_2\left[i_2\right]:=\left[\begin{array}{ll}
1 & 0 \\
i_2 & 1
\end{array}\right], \quad G_3\left[i_3\right]:=\left[\begin{array}{l}
1 \\
i_3
\end{array}\right]
\end{equation}
確認
\begin{equation}
\begin{aligned}
& A\left(i_1, i_2, i_3\right)=\left[\begin{array}{ll}
i_1 & 1
\end{array}\right]\left[\begin{array}{ll}
1 & 0 \\
i_2 & 1
\end{array}\right]\left[\begin{array}{l}
1 \\
i_3
\end{array}\right]= \\
&=\left[\begin{array}{ll}
i_1+i_2 & 1
\end{array}\right]\left[\begin{array}{l}
1 \\
i_3
\end{array}\right]=i_1+i_2+i_3 .
\end{aligned}
\end{equation}
具体的な各コアテンソルは、
\begin{equation}
\begin{aligned}
& G_1=\left(\left[\begin{array}{ll}
1 & 1
\end{array}\right],\left[\begin{array}{ll}
2 & 1
\end{array}\right],\left[\begin{array}{ll}
3 & 1
\end{array}\right]\right) \\
& G_2=\left(\left[\begin{array}{ll}
1 & 0 \\
1 & 1
\end{array}\right],\left[\begin{array}{ll}
1 & 0 \\
2 & 1
\end{array}\right],\left[\begin{array}{ll}
1 & 0 \\
3 & 1
\end{array}\right],\left[\begin{array}{ll}
1 & 0 \\
4 & 1
\end{array}\right]\right) \\
& G_3=\left(\left[\begin{array}{l}
1 \\
1
\end{array}\right],\left[\begin{array}{l}
1 \\
2
\end{array}\right],\left[\begin{array}{l}
1 \\
3
\end{array}\right],\left[\begin{array}{l}
1 \\
4
\end{array}\right],\left[\begin{array}{l}
1 \\
5
\end{array}\right]\right)
\end{aligned}
\end{equation}
テンソルの数は元々、345=60であった。
一方で、テンソルトレインは、32の要素しか用いてない。
juliaでの実装例
T1 = zeros(Float64, 1,3,2)
T1[1, 1, :] = [1 1]
T1[1, 2, :] = [2 1]
T1[1, 3, :] = [3 1]
T2 = zeros(Float64, 2,4,2)
T2[: ,1, :] = [1 0;1 1]
T2[:, 2, :] = [1 0;2 1]
T2[:, 3, :] = [1 0;3 1]
T2[:, 4, :] = [1 0;4 1]
T3 = zeros(Float64, 2,5,1)
T3[:, 1, 1] = [1;1]
T3[:, 2, 1] = [1;2]
T3[:, 3, 1] = [1;3]
T3[:, 4, 1] = [1;4]
T3[:, 5, 1] = [1;5]
tt = [T1, T2, T3]
test
inds_ = [1, 1, 1]
inds_2 = [2, 2, 2]
inds_3 = [3, 4, 5]
function wa(tt::Vector{Array{Float64, 3}}, inds_::Vector{Int64})
return only(prod(T[:, i, :] for (T, i) in zip(tt, inds_)))
end
3 == wa(tt, inds_)
6 == wa(tt, inds_2)
12 == wa(tt, inds_3)
要素数
sum([prod(size(T)) for T in tt])
参考資料
上記の例は以下の資料を参考にしました。
https://bayesgroup.github.io/team/arodomanov/tt_hse16_slides.pdf
Discussion