Factorize a (discrete) tensor function#

template<class T>
struct TensorCI2#

This class is responsible for building a cross interpolation (CI) of an input tensor. The main output is the tensor train tt (an effective separation of variables), which allows many cheap computations, i.e. the integral.

Subclassed by xfac::CTensorCI2< T, Index >, xfac::QTensorCI< T >

Public Functions

inline TensorCI2(TensorFunction<T> const &f_, vector<int> localDim, TensorCI2Param param_ = {})#

constructs a rank-1 TensorCI2 from a function f:(a1,a2,…,an)->eT where the index ai is in [0,localDim[i]).

inline TensorCI2(function<T(vector<int>)> f_, vector<int> localDim, TensorCI2Param param_ = {})#

constructs a rank-1 TensorCI2 from a function f:(a1,a2,…,an)->eT where the index ai is in [0,localDim[i]).

inline TensorCI2(function<T(vector<int>)> f_, TensorTrain<T> tt_, TensorCI2Param param_ = {})#

constructs a TensorCI2 from a given tensor train, and using the provided function f.

inline TensorCI2(TensorTrain<T> const &tt_, TensorCI2Param param_ = {})#

constructs a TensorCI2 from a given tensor train. It takes the tt as a true function f.

inline void addPivotsAllBonds(vector<vector<int>> const &pivots)#

add global pivots. The tt is not super stable anymore. For that call makeCanonical() afterward.

inline void addPivotsAt(vector<vector<int>> const &pivots, int b)#

add these pivots at a given bond b. The tt is not touched.

template<class Tci>
inline void addPivots(Tci const &ci)#

add all the pivots from another ci at the correct partitions. The tt is not super stable anymore. For that call makeCanonical() afterward.

inline void makeCanonical()#

generate a fully nested tci and well-conditioned tt

inline void iterate(int nIter = 1, int dmrg_type = 2)#

makes nIter half sweeps. The dmrg_type can be 0,1,2

inline size_t len() const#

returns the length of the tensor

inline double trueError(size_t max_n_eval = 1e6) const#

computes the max error |f-tt| if the tensor is smaller than max_n_Eval.

inline vector<vector<int>> getPivotsAt(int b) const#

returns the pivots a given bond b

Public Members

TensorFunction<T> f#

the tensor function f:(a1,a2,…,an)->T

TensorCI2Param param#

parameters of the algorithm

vector<double> pivotError#

max pivot error for each rank

vector<IndexSet<MultiIndex>> Jset#

collection of MultiIndex for each site: left, site, and right set of multiindex

TensorTrain<T> tt#

main output of the Tensor CI

vector<arma::Mat<T>> P#

the pivot matrix in LU form for each bond

int cIter = 0#

counter of iterations. Used for sweeping only.

int center = 0#

current position of the CI center

struct TensorCI2Param#

Parameters of the TensorCI2 algorithm.

Public Members

int bondDim = 30#

the max bond dimension of the tensor train

double reltol = 1e-12#

CI will stop when pivotError < reltol*max(pivotError)

vector<int> pivot1#

the first pivot (optional)

bool fullPiv = false#

whether to search in the full Pi matrix to find a new pivot

int nRookIter = 3#

number of rook pivoting iterations, used when fullPiv=false

vector<vector<double>> weight#

TODO: weight for the tt sum. When not empty, it activates the ENV learning.

function<bool(vector<int>)> cond#

TODO: cond(x)=false when x should not be a pivot.

bool useCachedFunction = true#

whether the internal caching should be used to avoid function call to the same point.

template<class T>
struct TensorTrain#

stores a tensor train, i.e., a list of cubes.

Public Functions

inline T eval(vector<int> const &id) const#

evaluate the tensor train at a given multi index.

inline T operator()(vector<int> const &id) const#

evaluate the tensor train at a given multi index. Same as eval()

T sum(const vector<vector<double>> &weight) const#

compute the weighted sum of the tensor train

inline T sum1() const#

compute the plane sum of the tensor train

inline T overlap(const TensorTrain<T> &tt) const#

compute the overlap with another tensor train

inline double trueError(function<T(vector<int>)> f, size_t max_n_eval = 1e6) const#

computes the max error |f-tt| if the tensor is smaller than max_n_Eval.

inline void sweep(function<array<arma::Mat<T>, 2>(arma::Mat<T>, bool)> mat_decomp)#

for developers

inline void left_to_right(function<array<arma::Mat<T>, 2>(arma::Mat<T>, bool)> mat_decomp)#

for developers

inline void right_to_left(function<array<arma::Mat<T>, 2>(arma::Mat<T>, bool)> mat_decomp)#

for developers

Public Members

vector<arma::Cube<T>> M#

list of 3-leg tensors

template<class T>
TensorTrain<T> xfac::sum(vector<TensorTrain<T>> v, double reltol = 1e-12, int maxBondDim = 0, bool use_svd = false)#

compute the sum of many tensor trains, while compressing along the tree.