💡

# 自明なテンソルトレインの例: x1+x2+x3...

2024/06/23に公開

テンソルトレインの自明な例について考える

$$A\left(i_1, i_2, i_3\right):=i_1+i_2+i_3,$$

ここで、

$$i_1 \in\{1,2,3\}, \quad i_2 \in\{1,2,3,4\}, \quad i_3 \in\{1,2,3,4,5\} .$$

である。

このTT形式は、

$$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],$$

ここで、

$$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]$$

\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}

\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}

テンソルの数は元々、345=60であった。

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]

#only(prod(T[:, i, :] for (T, i) in zip(tt, inds_)))
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])