Contents:
@author: Daniele Bigoni (dabi@imm.dtu.dk)
TensorToolbox is the collection of tools for Tensor decomposition and arithmetic
@copyright: 2014 The Technical University of Denmark
Find the index corresponding to the unfolded (flat) version of a tensor
Parameters: |
|
---|---|
Returns: | index for the flatten tensor |
Find the index corresponding to the folded version of a tensor from the flatten version
Parameters: |
|
---|---|
Returns: | list of int – the index for the folded version |
Note : | this routine can be used to get the indexes of a TTmat from indices of a matkron (matrix obtained using np.kron): (i,j) in N^d x N^d -> ((i_1,..,i_d),(j_1,..,j_d)) in (N x .. x N) x (N x .. x N) |
This function reshapes a 2D-matrix obtained as kron product of len(nrows)==len(ncols) matrices, to a len(nrows)-tensor that can be used as input for the TTmat constructor. Applies the Van Loan-Pitsianis reordering of the matrix elements.
Parameters: |
|
---|
Mapping from the multidimensional matrix indexing to the tt matrix indexing
(rowidxs,colidxs) = ((i_1,...,i_d),(j_1,...,j_d)) -> (l_1,...,l_d)
Parameters: |
|
---|---|
Returns: | tuple,int indices in the tt format |
Mapping from the tt matrix indexing to the multidimensional matrix indexing
(l_1,...,l_d) -> (rowidxs,colidxs) = ((i_1,...,i_d),(j_1,...,j_d))
Parameters: |
|
---|---|
Returns: | (rowidxs,colidxs) = ((i_1,..,i_d),(j_1,..,j_d)) indices in the matrix indexing |
Find the rxr submatrix of maximal volume in A(nxr), n>=r
Parameters: | |
---|---|
Returns: | (I,AsqInv,it) where I is the list or rows of A forming the matrix with maximal volume, AsqInv is the inverse of the matrix with maximal volume and it is the number of iterations to convergence |
Raises : | raise exception if the dimension of A is r>n or if A is singular |
Raises : | ConvergenceError if convergence is not reached in maxit iterations |
Given a matrix A nxm, find the maximum volume submatrix with rank r<n,m.
Parameters: |
|
---|---|
Parma int maxvolit: | |
maximum number of iterations in the maxvol routine |
|
Returns: | (I,J,AsqInv,it) where I and J are the list of rows and columns of A that compose the submatrix of maximal volume, AsqInv is the inverse of such matrix and it is the number of iteration to convergence |
Used to store the computed values of a TTcross approximation. Usually needed when the single function evaluation is demanding or when we need to restart TTcross later on.
Parameters: |
|
---|
Used to store any object in the library.
Parameters: |
---|
A tensor wrapper is a data structure W that given a multi-dimensional scalar function f(X,params), and a set of coordinates {{x1}_i1,{x2}_i2,..,{xd}_id} indexed by the multi index {i1,..,id}, let you access f(x1_i1,..,xd_id) by W[i1,..,id]. The function evaluations are performed “as needed” and stored for future accesses.
Parameters: |
|
---|
alias of object
Always returns the number of dimensions of the original tensor
Always returns the shape of the of the original tensor
Constructor of multidimensional tensor in Tensor Train format
Parameters: |
|
---|
Interpolates the values of the TTvec at arbitrary points, using the interpolation matrices ``Ms’‘.
Parameters: | |
---|---|
Returns: | TTvec interpolation |
Return type: | TTvec |
>>> from DABISpectralToolbox import DABISpectral1D as S1D
>>> Ms = [ S1D.LinearInterpolationMatrix(X[i],XI[i]) for i in range(d) ]
>>> is_sparse = [True]*d
>>> TTapproxI = TTapprox.interpolate(Ms,eps=1e-8,is_sparse=is_sparse)
Construct a TT representation of A using TT cross. This routine manage the outer loops for incremental ttcross or passes everything to ttcross if lr_r are specified.
Parameters: |
|
---|
Project the TTvec onto a set of basis provided, using the Generalized Vandermonde matrices ``Vs’’ and weights ``Ws’‘.
Parameters: |
|
---|---|
Returns: | TTvec containting the Fourier coefficients |
Return type: | TTvec |
>>> from DABISpectralToolbox import DABISpectral1D as S1D
>>> P = S1D.Poly1D(S1D.JACOBI,(0,0))
>>> x,w = S1D.Quadrature(10,S1D.GAUSS)
>>> X = [x]*d
>>> W = [w]*d
>>> # Compute here the TTapprox at points X
>>> TTapprox = TTvec(....)
>>> # Project
>>> Vs = [ P.GradVandermonde1D(x,10,0,norm=False) ] * d
>>> is_sparse = [False]*d
>>> TTfourier = TTapprox.project(Vs,W,eps=1e-8,is_sparse=is_sparse)
Returns the shape of the tensor represented
Construct a TT representation of A using TT cross
Parameters: |
|
---|
Returns the rank-1 multidimensional random vector in Tensor Train format
Returns the rank-1 multidimensional vector of zeros in Tensor Train format
Constructor of multidimensional matrix in Tensor Train format
Parameters: |
|
---|
Note
the method __getitem__ is not overwritten, thus the indices used to access the tensor refer to the flatten versions of the matrices composing the matrix tensor.
Returns the multidimensional identity operator in Tensor Train format
Returns the rank-1 multidimensional random matrix in Tensor Train format
Constructor of multidimensional tensor in Quantics Tensor Train format
Parameters: |
|
---|
Return the shape of the folded tensor
Returns the rank-1 multidimensional vector of zeros in Quantics Tensor Train format
Constructor of multidimensional matrix in Quantics Tensor Train format
Parameters: |
|
---|
Returns the number of cols of the unfolded matrices
Returns the number of rows of the unfolded matrices
Returns the number of cols of the folded matrices
Returns the number of rows of the folded matrices
Return the number of dimensions of the tensor space
Constructor of the Spectral Tensor Train approximation. Given a function f(x,theta,params):(Is, It) -> R with dim(Is)=n and dim(It)=d, construct an approximation of g(theta,params): It -> h_t(Is). For example Is could be the discretization of a spatial dimension, and It some parameter space, so that f(x,theta,params) describes a scalar field depending some parameters that vary in It. The params in the definition of f can be constants used by the function or othere objects that must be passed to the function definition.
Parameters: |
|
---|
Note
For a description of the remaining parameters see TTvec.
Evaluate the surrogate on points x
Parameters: | x (np.ndarray) – 1 or 2 dimensional array of points in the parameter space where to evaluate the function. In 2 dimensions, each row is an entry, i.e. x.shape[1] == self.param_dim |
---|---|
Returns: | an array with dimension equal to the space dimension (range_dim) plus one. If A is the returned vector and range_dim=2, then A[:,:,i] is the value of the surrogate for x[i,:] |
Compute the integral of the approximated function
Returns: | an array with dimension equal to the space dimension (range_dim), containing the value of the integral. |
---|
Constructor of multidimensional tensor in Tensor Train format
Parameters: |
|
---|
Interpolates the values of the TTvec at arbitrary points, using the interpolation matrices ``Ms’‘.
Parameters: | |
---|---|
Returns: | TTvec interpolation |
Return type: | TTvec |
>>> from DABISpectralToolbox import DABISpectral1D as S1D
>>> Ms = [ S1D.LinearInterpolationMatrix(X[i],XI[i]) for i in range(d) ]
>>> is_sparse = [True]*d
>>> TTapproxI = TTapprox.interpolate(Ms,eps=1e-8,is_sparse=is_sparse)
Construct a TT representation of A using TT cross. This routine manage the outer loops for incremental ttcross or passes everything to ttcross if lr_r are specified.
Parameters: |
|
---|
Project the TTvec onto a set of basis provided, using the Generalized Vandermonde matrices ``Vs’’ and weights ``Ws’‘.
Parameters: |
|
---|---|
Returns: | TTvec containting the Fourier coefficients |
Return type: | TTvec |
>>> from DABISpectralToolbox import DABISpectral1D as S1D
>>> P = S1D.Poly1D(S1D.JACOBI,(0,0))
>>> x,w = S1D.Quadrature(10,S1D.GAUSS)
>>> X = [x]*d
>>> W = [w]*d
>>> # Compute here the TTapprox at points X
>>> TTapprox = TTvec(....)
>>> # Project
>>> Vs = [ P.GradVandermonde1D(x,10,0,norm=False) ] * d
>>> is_sparse = [False]*d
>>> TTfourier = TTapprox.project(Vs,W,eps=1e-8,is_sparse=is_sparse)
Returns the shape of the tensor represented
Construct a TT representation of A using TT cross
Parameters: |
|
---|
Constructor of multidimensional matrix in Tensor Train format
Parameters: |
|
---|
Note
the method __getitem__ is not overwritten, thus the indices used to access the tensor refer to the flatten versions of the matrices composing the matrix tensor.
Constructor of the Spectral Tensor Train approximation. Given a function f(x,theta,params):(Is, It) -> R with dim(Is)=n and dim(It)=d, construct an approximation of g(theta,params): It -> h_t(Is). For example Is could be the discretization of a spatial dimension, and It some parameter space, so that f(x,theta,params) describes a scalar field depending some parameters that vary in It. The params in the definition of f can be constants used by the function or othere objects that must be passed to the function definition.
Parameters: |
|
---|
Note
For a description of the remaining parameters see TTvec.
Evaluate the surrogate on points x
Parameters: | x (np.ndarray) – 1 or 2 dimensional array of points in the parameter space where to evaluate the function. In 2 dimensions, each row is an entry, i.e. x.shape[1] == self.param_dim |
---|---|
Returns: | an array with dimension equal to the space dimension (range_dim) plus one. If A is the returned vector and range_dim=2, then A[:,:,i] is the value of the surrogate for x[i,:] |
Compute the integral of the approximated function
Returns: | an array with dimension equal to the space dimension (range_dim), containing the value of the integral. |
---|
Kron product between two tensors in TT format. Complexity: O(1)
Multidimensional contraction of tensor A with vectors in list U. Complexity: O(dnr^2)
Parameters: |
|
---|
Compute the norm of tensor A
Parameters: |
|
---|
Solves the system \(Ax=b\) using the Steepest Descent method in Tensor Train format.
Parameters: |
|
---|---|
Returns: | tuple (x,conv,info)
|
Solves the system \(Ax=b\) using the Conjugate Gradient method in Tensor Train format.
Parameters: |
|
---|---|
Returns: | tuple (x,conv,info)
|
Solves the system \(Ax=b\) using the Bi-Conjugate Gradient Stabilized method using Tensor Train format.
Parameters: |
|
---|---|
Returns: | tuple (x,conv,info)
|
Solves the system \(Ax=b\) using the Generalized Minimum Residual method with Modified Gram-Schmidt iterations using Tensor Train format.
Parameters: |
|
---|---|
Returns: | tuple (x,conv,info)
|
Note : | not optimized for symmetric A |