Types

TensorTrains.TensorTrainType
TensorTrain{F<:Number, N} <: AbstractTensorTrain{F,N}

A type for representing a Tensor Train

  • F is the type of the matrix entries
  • N is the number of indices of each tensor (2 virtual ones + N-2 physical ones)
source
TensorTrains.PeriodicTensorTrainType
PeriodicTensorTrain{F<:Number, N} <: AbstractPeriodicTensorTrain{F,N}

A type for representing a Tensor Train with periodic boundary conditions

  • F is the type of the matrix entries
  • N is the number of indices of each tensor (2 virtual ones + N-2 physical ones)
source

Functions

TensorTrains.normalize_eachmatrix!Function
normalize_eachmatrix!(A::AbstractTensorTrain)

Divide each matrix by its maximum (absolute) element and return the sum of the logs of the individual normalizations. This is used to keep the entries from exploding during computations

source
TensorTrains.flat_ttFunction
flat_tt([T = Float64], bondsizes::AbstractVector{<:Integer}, q...)
flat_tt([T = Float64], d::Integer, L::Integer, q...)

Construct a (normalized) Tensor Train filled with one(T), by specifying either:

  • bondsizes: the size of each bond
  • d a fixed size for all bonds, L the length

and

  • q a Tuple/Vector specifying the number of values taken by each variable on a single site
source
TensorTrains.rand_ttFunction
rand_tt([T = Float64], bondsizes::AbstractVector{<:Integer}, q...)
rand_tt([T = Float64], d::Integer, L::Integer, q...)

Construct a Tensor Train with rand(T) entries, by specifying either:

  • bondsizes: the size of each bond
  • d a fixed size for all bonds, L the length

and

  • q a Tuple/Vector specifying the number of values taken by each variable on a single site
source
TensorTrains.flat_periodic_ttFunction
flat_periodic_tt(bondsizes::AbstractVector{<:Integer}, q...)
flat_periodic_tt(d::Integer, L::Integer, q...)

Construct a (normalized) Tensor Train with periodic boundary conditions filled with a constant, by specifying either:

  • bondsizes: the size of each bond
  • d a fixed size for all bonds, L the length

and

  • q a Tuple/Vector specifying the number of values taken by each variable on a single site
source
TensorTrains.rand_periodic_ttFunction
rand_periodic_tt(bondsizes::AbstractVector{<:Integer}, q...)
rand_periodic_tt(d::Integer, L::Integer, q...)

Construct a Tensor Train with periodic boundary conditions with entries random in [0,1], by specifying either:

  • bondsizes: the size of each bond
  • d a fixed size for all bonds, L the length

and

  • q a Tuple/Vector specifying the number of values taken by each variable on a single site
source
TensorTrains.evaluateFunction
evaluate(A::AbstractTensorTrain, X...)

Evaluate the Tensor Train A at input X

Example:

    L = 3
    q = (2, 3)
    A = rand_tt(4, L, q...)
    X = [[rand(1:qi) for qi in q] for l in 1:L]
    evaluate(A, X)
source
TensorTrains.marginalsFunction
marginals(A::AbstractTensorTrain; l, r)

Compute the marginal distributions $p(x^l)$ at each site

Optional arguments

  • l = accumulate_L(A)[1], r = accumulate_R(A)[1] pre-computed partial normalizations
source
TensorTrains.twovar_marginalsFunction
twovar_marginals(A::AbstractTensorTrain; l, r, M, Δlmax)

Compute the marginal distributions for each pair of sites $p(x^l, x^m)$

Optional arguments

  • l = accumulate_L(A)[1], r = accumulate_R(A)[1], M = accumulate_M(A) pre-computed partial normalizations
  • maxdist = length(A): compute marginals only at distance maxdist: $|l-m|\le maxdist$
source
TensorTrains.lognormalizationFunction
lognormalization(A::AbstractTensorTrain)

Compute the natural logarithm of the normalization $\log Z=\log \sum_{x^1,\ldots,x^L} A^1(x^1)\cdots A^L(x^L)$. Throws an error if the normalization is negative.

source
TensorTrains.normalizationFunction
normalization(A::AbstractTensorTrain)

Compute the normalization $Z=\sum_{x^1,\ldots,x^L} A^1(x^1)\cdots A^L(x^L)$ and return it as a Logarithmic, which stores the sign and the logarithm of the absolute value (see the docs of LogarithmicNumbers.jl https://github.com/cjdoris/LogarithmicNumbers.jl?tab=readme-ov-file#documentation)

source
Missing docstring.

Missing docstring for normalize!. Check Documenter's build log for details.

Base.:+Function
Base.:(+)(A::AbstracTensorTrain, B::AbstracTensorTrain)

Compute the sum of two Tensor Trains. Matrix sizes are doubled

source
Base.:-Function
Base.:(-)(A::AbstracTensorTrain, B::AbstracTensorTrain)

Compute the difference of two Tensor Trains. Matrix sizes are doubled

source
LinearAlgebra.dotFunction
LinearAlgebra.dot(A::AbstractTensorTrain, B::AbstractTensorTrain)

Compute the inner product between tensor trains A and B

\[A\cdot B = \sum_{x^1,x^2,\ldots,x^L}A^1(x^1)A^2(x^2)\cdots A^L(x^L)B^1(x^1)B^2(x^2)\cdots B^L(x^L)\]

source
dot(q::InfiniteUniformTensorTrain, p::InfiniteUniformTensorTrain)

Return the "dot product" between the infinite tensor trains q and p.

Since two infinite tensor trains are either equal or orthogonal (orthogonality catastrophe), what is actually returned here is the leading eigenvalue of the transfer operator obtained from the matrices of q and p

source
LinearAlgebra.normFunction
LinearAlgebra.norm(A::AbstractTensorTrain)

Compute the 2-norm (Frobenius norm) of tensor train A

\[\lVert A\rVert_2 = \sqrt{\sum_{x^1,x^2,\ldots,x^L}\left[A^1(x^1)A^2(x^2)\cdots A^L(x^L)\right]^2} = \sqrt{A\cdot A}\]

source
TensorTrains.norm2mFunction
norm2m(A::AbstractTensorTrain, B::AbstractTensorTrain)

Given two tensor trains A,B, compute norm(A - B)^2 as

\[\lVert A-B\rVert_2^2 = \lVert A \rVert_2^2 + \lVert B \rVert_2^2 - 2A\cdot B\]

source
StatsBase.sample!Function
sample!([rng], x, A::AbstractTensorTrain; r)

Draw an exact sample from A interpreted as a probability distribution and store the result in x. A doesn't need to be normalized, however error will be raised if it is found to take negative values.

Optionally specify a random number generator rng as the first argument (defaults to Random.default_rng()) and provide a pre-computed rz = accumulate_R(A).

The output is x, p, the sampled sequence and its probability

source
StatsBase.sampleFunction
sample([rng], A::AbstractTensorTrain; r)

Draw an exact sample from A interpreted as a probability distribution. A doesn't need to be normalized, however error will be raised if it is found to take negative values.

Optionally specify a random number generator rng as the first argument (defaults to Random.default_rng()) and provide a pre-computed rz = accumulate_R(A).

The output is x, p, the sampled sequence and its probability

source
TensorTrains.orthogonalize_right!Function
orthogonalize_right!(A::AbstractTensorTrain; svd_trunc::SVDTrunc)

Bring A to right-orthogonal form by means of SVD decompositions.

Optionally perform truncations by passing a SVDTrunc.

source
TensorTrains.orthogonalize_left!Function
orthogonalize_left!(A::AbstractTensorTrain; svd_trunc::SVDTrunc)

Bring A to left-orthogonal form by means of SVD decompositions.

Optionally perform truncations by passing a SVDTrunc.

source
TensorTrains.compress!Function
compress!(A::AbstractTensorTrain; svd_trunc::SVDTrunc)

Compress A by means of SVD decompositions + truncations

source

Uniform Tensor Trains

TensorTrains.AbstractUniformTensorTrainType
AbstractUniformTensorTrain{F,N} <: AbstractPeriodicTensorTrain{F,N}

An abstract type for representing tensor trains with periodic boundary conditions and all matrices equal

  • F is the type of the matrix entries
  • N is the number of indices of each tensor (2 virtual ones + N-2 physical ones)
source
TensorTrains.UniformTensorTrainType
UniformTensorTrain{F<:Number, N} <: AbstractUniformTensorTrain{F,N}

A type for representing a tensor train with periodic boundary conditions, all matrices equal and a fixed length L.

  • F is the type of the matrix entries
  • N is the number of indices of each tensor (2 virtual ones + N-2 physical ones)

FIELDS

  • tensor only one is stored
  • L the length of the tensor train
  • z a re-scaling constant
source
TensorTrains.InfiniteUniformTensorTrainType
InfiniteUniformTensorTrain{F<:Number, N} <: AbstractUniformTensorTrain{F,N}

A type for representing an infinite tensor train with periodic boundary conditions and all matrices equal.

  • F is the type of the matrix entries
  • N is the number of indices of each tensor (2 virtual ones + N-2 physical ones)

FIELDS

  • tensor only one is stored
  • z a re-scaling constant
source
TensorTrains.symmetrized_uniform_tensor_trainFunction
symmetrized_uniform_tensor_train(A::AbstractTensorTrain)

Convert a tensor train $f(x^1,x^2,\ldots,x^L)$ into a UniformTensorTrain $g$ such that

\[g(\mathcal P[x^1,x^2,\ldots,x^L]) = g(x^1,x^2,\ldots,x^L) = \sum_{l=1}^L f(x^l, x^{l+1},\ldots,x^L,x^1,\ldots,x^{l-1})\]

for any cyclic permutation $\mathcal P$

source

Truncators

TensorTrains.TruncThreshType
TruncThresh{T} <: SVDTrunc

A type used to perform SVD-based truncations based on a threshold ε. Given a vector $\lambda$ of $m$ singular values, those below $\varepsilon\sqrt{\sum_{k=1}^m \lambda_k^2}$ are truncated to zero.

FIELDS

  • ε: threshold.
svd_trunc = TruncThresh(1e-5)
M = rand(5,6)
M_trunc = svd_trunc(M)
source
TensorTrains.TruncBondType
TruncBond{T} <: SVDTrunc

A type used to perform SVD-based truncations based on bond size m'. Given a vector $\lambda$ of $m$ singular values, only the $m'$ largest are kept, the others are truncated to zero.

FIELDS

  • mprime: number of singular values to retain
svd_trunc = TruncBond(3)
M = rand(5,6)
M_trunc = svd_trunc(M)
source
TensorTrains.TruncBondMaxType
TruncBondMax{T} <: SVDTrunc

Similar to TruncBond, but also stores the maximum error $\sqrt{\frac{\sum_{k=m'+1}^m\lambda_k^2}{\sum_{k=1}^m\lambda_k^2}}$ made since the creation of the object

FIELDS

  • mprime: number of singular values to retain
  • maxerr: a 1-element vector storing the maximum error
source

Infinite Tensor Trains

TensorTrains.TruncVUMPSType
TruncVUMPS{TI, TF} <: SVDTrunc

A type used to perform truncations of an InfiniteUniformTensorTrain to a target bond size d. It uses the Variational Uniform Matrix Product States (VUMPS) algorithm from MPSKit.jl.

FIELDS

  • d: target bond dimension
  • maxiter = 100: max number of iterations for the VUMPS algorithm
  • tol = 1e-14: tolerance for the VUMPS algorithm
p = rand_infinite_uniform_tt(10, 2, 2)
compress!(p, TruncVUMPS(5))
source