使用示例rank-2逼近3x4x5张量X
,由:
Eigen::Tensor<double, 2> A0(3, 2);
Eigen::Tensor<double, 2> A1(4, 2);
Eigen::Tensor<double, 2> A2(5, 2);
这使用的符号类似于low rank tensor appoximations上的出版物。从(A0,A1,A2)重建X
的本征中正确的语句是什么?
我已经做到了:
template<typename Scalar, int Dimensions_>
struct LowRankTensor
{
std::array<Eigen::Tensor<Scalar, 2>, Dimensions_> bases;
Eigen::Tensor<Scalar, Dimensions_> S;
};
template<typename Scalar, int Dimension>
Eigen::Tensor<double, Dimension> Full(LowRankTensor<Scalar, Dimension> lr)
{
Eigen::Tensor<double, Dimension> X = lr.S;
for(int d=0; d < Dimension; d++)
{
Eigen::array<Eigen::IndexPair<long>, 1> outer = {Eigen::IndexPair<long>{0, 1}};
Eigen::Tensor<double, Dimension> Xd = X.contract(lr.bases(d), outer);
X = Xd;
}
return X;
}
LowRankTensor<double, 3> lr;
lr.bases = {A0, A1, A2};
lr.S = Identity<3>();
auto X = Full(lr);
但是,这确实涉及大量数据副本。假设lr.S
已初始化为身份张量。