xerus
a general purpose tensor library
xerus::TTNetwork< isOperator > Class Template Reference

Specialized TensorNetwork class used to represent TTTensor and TToperators. More...

#include <performanceData.h>

Inheritance diagram for xerus::TTNetwork< isOperator >:
Collaboration diagram for xerus::TTNetwork< isOperator >:

Public Member Functions

 TTNetwork ()
 Constructs an order zero TTNetwork. More...
 
 TTNetwork (const TTNetwork &_cpy)=default
 TTNetworks are default copy constructable. More...
 
 TTNetwork (TTNetwork &&_mov) noexcept=default
 TTNetworks are default move constructable. More...
 
 TTNetwork (const size_t _degree)
 Constructs an zero initialized TTNetwork with the given degree and ranks all equal to one. More...
 
 TTNetwork (Tensor::DimensionTuple _dimensions)
 Constructs an zero initialized TTNetwork with the given dimensions and ranks all equal to one. More...
 
 TTNetwork (const Tensor &_tensor, const double _eps=EPSILON, const size_t _maxRank=std::numeric_limits< size_t >::max())
 Constructs a TTNetwork from the given Tensor. More...
 
 TTNetwork (const Tensor &_tensor, const double _eps, const RankTuple &_maxRanks)
 Constructs a TTNetwork from the given Tensor. More...
 
void assume_core_position (const size_t _pos)
 stores _pos as the current core position without verifying of ensuring that this is the case More...
 
void canonicalize_left ()
 Move the core to the left. More...
 
void canonicalize_right ()
 Move the core to the left. More...
 
std::pair< TensorNetwork, TensorNetworkchop (const size_t _position) const
 Splits the TTNetwork into two parts by removing the node. More...
 
Tensorcomponent (const size_t _idx)
 Complete access to a specific component of the TT decomposition. More...
 
virtual void contract_unconnected_subnetworks () override
 Contracts all nodes that are not connected to any external links. More...
 
size_t degrees_of_freedom ()
 calculates the number of degrees of freedom of the manifold of fixed tt-rank that the given TTTensor is part of More...
 
virtual void fix_mode (const size_t _mode, const size_t _slatePosition) override
 Fixes a specific mode to a specific value, effectively reducing the order by one. More...
 
virtual value_t frob_norm () const override
 Calculates the frobenious norm of the TensorNetwork. More...
 
const Tensorget_component (const size_t _idx) const
 Read access to a specific component of the TT decomposition. More...
 
virtual TensorNetworkget_copy () const override
 Returns a new copy of the network. More...
 
template<>
TTNetwork< true > identity (const std::vector< size_t > &_dimensions)
 
void move_core (const size_t _position, const bool _keepRank=false)
 Move the core to a new position. More...
 
virtual void operator*= (const value_t _factor) override
 Calculates the entrywise multiplication of this TensorNetwork with a constant _factor. More...
 
TTNetworkoperator+= (const TTNetwork &_other)
 Adds a given TTNetwork to this one. More...
 
TTNetworkoperator-= (const TTNetwork &_other)
 Subtracts the _other TTNetwork entrywise from this one. More...
 
virtual void operator/= (const value_t _divisor) override
 Calculates the entrywise divison of this TensorNetwork by a constant _divisor. More...
 
TTNetworkoperator= (const TTNetwork &_other)=default
 TTNetworks are default assignable. More...
 
TTNetworkoperator= (TTNetwork &&_other)=default
 TTNetworks are default move-assignable. More...
 
size_t rank (const size_t _i) const
 Gets the rank of a specific egde of the TTNetwork. More...
 
std::vector< size_t > ranks () const
 Gets the ranks of the TTNetwork. More...
 
virtual void require_correct_format () const override
 Tests whether the network resembles that of a TTTensor and checks consistency with the underlying tensor objects. More...
 
virtual void resize_mode (const size_t _mode, const size_t _newDim, const size_t _cutPos=~0ul) override
 Resizes a specific mode of the TensorNetwork. More...
 
void round (const std::vector< size_t > &_maxRanks, const double _eps=EPSILON)
 Reduce all ranks up to a given accuracy and maximal number. More...
 
void round (const size_t _maxRank)
 Reduce all ranks to the given number. More...
 
void round (const int _maxRank)
 Reduce all ranks to the given number. More...
 
void round (const value_t _eps)
 Reduce all ranks up to a given accuracy. More...
 
void set_component (const size_t _idx, Tensor _T)
 Sets a specific component of the TT decomposition. More...
 
void soft_threshold (const double _tau, const bool _preventZero=false)
 Applies the soft threshholding operation to all ranks. More...
 
void soft_threshold (const std::vector< double > &_taus, const bool _preventZero=false)
 Applies soft threshholding operations to all ranks. More...
 
virtual bool specialized_contraction (std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &_out, internal::IndexedTensorReadOnly< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other) const override
 (Internal) Calculates the contraction between _me and _other and stores the result in _out. Requires that *this is the tensorObjectReadOnly of _me. More...
 
template<>
bool specialized_contraction_f (std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &, internal::IndexedTensorReadOnly< TensorNetwork > &&, internal::IndexedTensorReadOnly< TensorNetwork > &&)
 
template<>
bool specialized_contraction_f (std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &_out, internal::IndexedTensorReadOnly< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other)
 
virtual void specialized_evaluation (internal::IndexedTensorWritable< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other) override
 (Internal) Evaluates _other into _me. Requires that *this is the tensorObjectReadOnly of _me. More...
 
virtual bool specialized_sum (std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &_out, internal::IndexedTensorReadOnly< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other) const override
 (Internal) Calculates the sum between _me and _other and stores the result in _out. Requires that *this is the tensorObjectReadOnly of _me. More...
 
template<bool B = isOperator, typename std::enable_if< B, int >::type = 0>
void transpose ()
 Transpose the TTOperator. More...
 
void use_dense_representations ()
 Converts all components to use dense representations. More...
 
- Public Member Functions inherited from xerus::TensorNetwork
 TensorNetwork ()
 Constructs an order zero TensorNetwork. More...
 
 TensorNetwork (const TensorNetwork &_cpy)=default
 Copy Constructor. More...
 
 TensorNetwork (TensorNetwork &&_mv) noexcept=default
 Move Constructor. More...
 
 TensorNetwork (Tensor _other)
 Constructs the trivial TensorNetwork containing the given Tensor as single node. More...
 
 TensorNetwork (std::unique_ptr< Tensor > &&_tensor)
 Constructs the trivial TensorNetwork containing the given Tensor as single node. The TN takes the ownership of the pointer. More...
 
 TensorNetwork (size_t _degree)
 Constructs the trivial TensorNetwork containing a Tensor with the given degree. More...
 
 TensorNetwork (const ZeroNode _nodeStatus)
 (Internal) Constructs an order zero TensorNetwork. More...
 
virtual ~TensorNetwork ()=default
 Destructor. More...
 
void contract (const size_t _nodeId1, const size_t _nodeId2)
 Contracts the nodes with indices _nodeId1 and _nodeId2. More...
 
size_t contract (const std::set< size_t > &_ids)
 Contracts the nodes with with indices included in the given set _ids. More...
 
double contraction_cost (const size_t _nodeId1, const size_t _nodeId2) const
 Approximates the cost of contraction two given nodes. More...
 
size_t datasize () const
 Calculates the storage requirement of the current representation. More...
 
size_t degree () const
 Gets the degree of the TensorNetwork. More...
 
void draw (const std::string &_filename) const
 Draws a graph representation of the TensorNetwork. More...
 
std::pair< size_t, size_t > find_common_edge (const size_t _nodeA, const size_t _nodeB) const
 Finds the position of a single common edge between two nodes. More...
 
 operator Tensor () const
 Explicit cast to Tensor. More...
 
template<typename... args>
internal::IndexedTensor< TensorNetworkoperator() (args... _args)
 Indexes the TensorNetwork for read/write use. More...
 
template<typename... args>
internal::IndexedTensorReadOnly< TensorNetworkoperator() (args... _args) const
 Indexes the TensorNetwork for read only use. More...
 
internal::IndexedTensor< TensorNetworkoperator() (const std::vector< Index > &_indices)
 Indexes the TensorNetwork for read/write use. More...
 
internal::IndexedTensor< TensorNetworkoperator() (std::vector< Index > &&_indices)
 Indexes the TensorNetwork for read/write use. More...
 
internal::IndexedTensorReadOnly< TensorNetworkoperator() (const std::vector< Index > &_indices) const
 Indexes the TensorNetwork for read only use. More...
 
internal::IndexedTensorReadOnly< TensorNetworkoperator() (std::vector< Index > &&_indices) const
 Indexes the TensorNetwork for read only use. More...
 
TensorNetworkoperator= (const TensorNetwork &_cpy)=default
 TensorNetworks are copy assignable. More...
 
TensorNetworkoperator= (TensorNetwork &&_mv)=default
 TensorNetworks are move assignable. More...
 
value_t operator[] (const size_t _position) const
 Read the value at a specific position. More...
 
value_t operator[] (const std::vector< size_t > &_positions) const
 Read the value at a specific position. More...
 
void reduce_representation ()
 Contracts all nodes that are joined by a full-rank edge. More...
 
virtual void remove_slate (const size_t _mode, const size_t _slatePosition)
 removes the given _slatePosition from the _mode. this reduces the given dimension by one More...
 
void require_valid_network (const bool _check_erased=true) const
 Sanity checks the network. More...
 
void reshuffle_nodes (const std::function< size_t(size_t)> &_f)
 reshuffled the nodes according to the given function More...
 
virtual void round_edge (const size_t _nodeA, const size_t _nodeB, const size_t _maxRank, const double _eps, const double _softThreshold)
 Thresholds the rank between two given nodes. More...
 
void sanitize ()
 Removes all erased nodes from the TensorNetwork. More...
 
void swap_external_links (const size_t _i, const size_t _j)
 Swaps the external indices _i and _j, effectively changing those indices for the represented Tensor (e.g. a transposition for matrices). More...
 
virtual void transfer_core (const size_t _from, const size_t _to, const bool _allowRankReduction=true)
 Transfers the core from one given node to another. More...
 

Static Public Member Functions

static size_t degrees_of_freedom (const std::vector< size_t > &_dimensions, const std::vector< size_t > &_ranks)
 calculates the number of degrees of freedom of the manifold of fixed tt-rank _ranks with the given _dimensions More...
 
static TTNetwork XERUS_warn_unused dirac (std::vector< size_t > _dimensions, const std::vector< size_t > &_position)
 : Returns a TTNetwork with a single entry equals oen and all other zero. More...
 
static TTNetwork XERUS_warn_unused dirac (std::vector< size_t > _dimensions, const size_t _position)
 : Returns a Tensor with a single entry equals oen and all other zero. More...
 
template<bool B = isOperator, typename std::enable_if< B, int >::type = 0>
static TTNetwork XERUS_warn_unused identity (const std::vector< size_t > &_dimensions)
 : Construct a TTOperator with the given dimensions representing the identity. More...
 
static TTNetwork XERUS_warn_unused kronecker (const std::vector< size_t > &_dimensions)
 : Returns a TTNetwork representation of the kronecker delta. More...
 
static TTNetwork XERUS_warn_unused ones (const std::vector< size_t > &_dimensions)
 : Returns a the (rank one) TT-Tensor with all entries equal to one. More...
 
template<class distribution = std::normal_distribution<value_t>, class generator = std::mt19937_64>
static TTNetwork XERUS_warn_unused random (std::vector< size_t > _dimensions, const std::vector< size_t > &_ranks, distribution &_dist=xerus::misc::defaultNormalDistribution, generator &_rnd=xerus::misc::randomEngine)
 Transforms a given TensorNetwork to a TTNetwork. More...
 
template<class distribution = std::normal_distribution<value_t>, class generator = std::mt19937_64>
static TTNetwork XERUS_warn_unused random (const std::vector< size_t > &_dimensions, const size_t _rank, distribution &_dist=xerus::misc::defaultNormalDistribution, generator &_rnd=xerus::misc::randomEngine)
 Random constructs a TTNetwork with the given dimensions and ranks limited by the given rank. More...
 
template<class distribution = std::normal_distribution<value_t>, class generator = std::mt19937_64>
static TTNetwork XERUS_warn_unused random (const std::vector< size_t > &_dimensions, const std::vector< size_t > &_ranks, const std::function< void(Tensor &)> &_modifySingularValues, distribution &_dist=xerus::misc::defaultNormalDistribution, generator &_rnd=xerus::misc::randomEngine)
 Random constructs a TTNetwork with the given dimensions and ranks. More...
 
static std::vector< size_t > reduce_to_maximal_ranks (std::vector< size_t > _ranks, const std::vector< size_t > &_dimensions)
 Reduces the given ranks to the maximal possible. More...
 
static bool specialized_contraction_f (std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &_out, internal::IndexedTensorReadOnly< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other)
 
static bool specialized_sum_f (std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &_out, internal::IndexedTensorReadOnly< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other)
 
- Static Public Member Functions inherited from xerus::TensorNetwork
static void add_network_to_network (internal::IndexedTensorWritable< TensorNetwork > &&_base, internal::IndexedTensorReadOnly< TensorNetwork > &&_toInsert)
 Inserts all nodes from _toInsert into _base, creating links where demanded by the indices. More...
 
static void link_traces_and_fix (internal::IndexedTensorWritable< TensorNetwork > &&_base)
 Finds traces defined by the indices and internally links the corresponding indices. Also applys all fixed indices. More...
 

Public Attributes

bool canonicalized
 Flag indicating whether the TTNetwork is canonicalized. More...
 
size_t corePosition
 The position of the core. More...
 
- Public Attributes inherited from xerus::TensorNetwork
std::vector< size_t > dimensions
 Dimensions of the external indices, i.e. the dimensions of the tensor represented by the network. More...
 
std::vector< LinkexternalLinks
 The open links of the network in order. More...
 
std::vector< TensorNodenodes
 The nodes constituting the network. The order determines the ids of the nodes. More...
 

Static Public Attributes

static constexpr const size_t N = isOperator?2:1
 The number of external links in each node, i.e. one for TTTensors and two for TTOperators. More...
 

Protected Member Functions

bool exceeds_maximal_ranks () const
 Tests whether any rank exceeds the theoretic maximal value it should have. More...
 
size_t num_ranks () const
 Return the number of ranks, i.e. 0 for degree zero and degree()/N-1 otherwise. More...
 
- Protected Member Functions inherited from xerus::TensorNetwork
std::vector< Linkinit_from_dimension_array ()
 : Sets the externalLinks and returns an Link vector for a node, assuming that this node is the only node there is and all given dimensions are open. More...
 
void perform_traces (const size_t _nodeId)
 Performs all traces in the given node. More...
 
TensorNetwork stripped_subnet (const std::function< bool(size_t)> &_idF=[](size_t){ return true;}) const
 Creates a dataless copy of a subnet. More...
 

Static Protected Member Functions

static void construct_train_from_full (TensorNetwork &_out, const Tensor &_A, const double _eps)
 Constructs a TTNetwork in _out by decomposing the given Tensor _A. More...
 

Additional Inherited Members

- Public Types inherited from xerus::TensorNetwork
using RankTuple = std::vector< size_t >
 : Represention of the ranks of a TensorNetwork. More...
 
- Protected Types inherited from xerus::TensorNetwork
enum  ZeroNode : bool { ZeroNode::None, ZeroNode::Add }
 Internal indicator to prevent the creation of an degree zero node in TensorNetwork constructor. More...
 

Detailed Description

template<bool isOperator>
class xerus::TTNetwork< isOperator >

Specialized TensorNetwork class used to represent TTTensor and TToperators.

TTTensors correspond to isOperator=FALSE and TTOperators correspond to isOperator=FALSE.

Definition at line 37 of file performanceData.h.

Constructor & Destructor Documentation

◆ TTNetwork() [1/7]

template<bool isOperator>
xerus::TTNetwork< isOperator >::TTNetwork ( )
explicit

Constructs an order zero TTNetwork.

This is an empty TensorNetwork. Internally the network contains one order zero node with entry zero.

Definition at line 46 of file ttNetwork.cpp.

◆ TTNetwork() [2/7]

template<bool isOperator>
xerus::TTNetwork< isOperator >::TTNetwork ( const TTNetwork< isOperator > &  _cpy)
default

TTNetworks are default copy constructable.

◆ TTNetwork() [3/7]

template<bool isOperator>
xerus::TTNetwork< isOperator >::TTNetwork ( TTNetwork< isOperator > &&  _mov)
defaultnoexcept

TTNetworks are default move constructable.

◆ TTNetwork() [4/7]

template<bool isOperator>
xerus::TTNetwork< isOperator >::TTNetwork ( const size_t  _degree)
explicit

Constructs an zero initialized TTNetwork with the given degree and ranks all equal to one.

Naturally for TTOperators the degree must be even.

Definition at line 55 of file ttNetwork.cpp.

◆ TTNetwork() [5/7]

template<bool isOperator>
xerus::TTNetwork< isOperator >::TTNetwork ( Tensor::DimensionTuple  _dimensions)
explicit

Constructs an zero initialized TTNetwork with the given dimensions and ranks all equal to one.

Naturally for TTOperators the degree must be even.

Definition at line 58 of file ttNetwork.cpp.

◆ TTNetwork() [6/7]

template<bool isOperator>
xerus::TTNetwork< isOperator >::TTNetwork ( const Tensor _tensor,
const double  _eps = EPSILON,
const size_t  _maxRank = std::numeric_limits<size_t>::max() 
)
explicit

Constructs a TTNetwork from the given Tensor.

The higher order SVD algorithm is used to decompose the given Tensor into the TT format.

Parameters
_tensorThe Tensor to decompose.
_epsthe accuracy to be used in the decomposition.
_maxRankthe maximal allowed rank (applies to all positions).

Definition at line 50 of file ttNetwork.cpp.

◆ TTNetwork() [7/7]

template<bool isOperator>
xerus::TTNetwork< isOperator >::TTNetwork ( const Tensor _tensor,
const double  _eps,
const RankTuple _maxRanks 
)
explicit

Constructs a TTNetwork from the given Tensor.

The higher order SVD algorithm is used to decompose the given Tensor into the TT format.

Parameters
_tensorThe Tensor to decompose.
_epsthe accuracy to be used in the decomposition.
_maxRanksmaximal ranks to be used

Definition at line 112 of file ttNetwork.cpp.

Member Function Documentation

◆ assume_core_position()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::assume_core_position ( const size_t  _pos)

stores _pos as the current core position without verifying of ensuring that this is the case

this is particularly useful after constructing an own TT tensor with set_component calls as these will assume that all orthogonalities are destroyed

Definition at line 735 of file ttNetwork.cpp.

◆ canonicalize_left()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::canonicalize_left ( )

Move the core to the left.

Basically calls move_core() with _position = 0

Definition at line 632 of file ttNetwork.cpp.

◆ canonicalize_right()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::canonicalize_right ( )

Move the core to the left.

Basically calls move_core() with _position = degree()-1

Definition at line 638 of file ttNetwork.cpp.

◆ chop()

template<bool isOperator>
std::pair< TensorNetwork, TensorNetwork > xerus::TTNetwork< isOperator >::chop ( const size_t  _position) const

Splits the TTNetwork into two parts by removing the node.

Parameters
_positionindex of the component to be removed, thereby also defining the position of the split.
Returns
a std::pair containing the two remaining parts as TensorNetworks.

Definition at line 515 of file ttNetwork.cpp.

◆ component()

template<bool isOperator>
Tensor & xerus::TTNetwork< isOperator >::component ( const size_t  _idx)

Complete access to a specific component of the TT decomposition.

Note
This function will not update rank and external dimension informations if it is used to set a component.

This function gives complete access to the components, only intended for internal use.

Parameters
_idxindex of the component to access.
Returns
a reference to the requested component.

Definition at line 457 of file ttNetwork.cpp.

◆ construct_train_from_full()

template<bool isOperator>
static void xerus::TTNetwork< isOperator >::construct_train_from_full ( TensorNetwork _out,
const Tensor _A,
const double  _eps 
)
staticprotected

Constructs a TTNetwork in _out by decomposing the given Tensor _A.

◆ contract_unconnected_subnetworks()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::contract_unconnected_subnetworks ( )
overridevirtual

Contracts all nodes that are not connected to any external links.

Reimplemented from xerus::TensorNetwork.

Definition at line 748 of file ttNetwork.cpp.

◆ degrees_of_freedom() [1/2]

template<bool isOperator>
size_t xerus::TTNetwork< isOperator >::degrees_of_freedom ( const std::vector< size_t > &  _dimensions,
const std::vector< size_t > &  _ranks 
)
static

calculates the number of degrees of freedom of the manifold of fixed tt-rank _ranks with the given _dimensions

Definition at line 406 of file ttNetwork.cpp.

◆ degrees_of_freedom() [2/2]

template<bool isOperator>
size_t xerus::TTNetwork< isOperator >::degrees_of_freedom ( )

calculates the number of degrees of freedom of the manifold of fixed tt-rank that the given TTTensor is part of

Definition at line 426 of file ttNetwork.cpp.

◆ dirac() [1/2]

template<bool isOperator>
TTNetwork< isOperator > xerus::TTNetwork< isOperator >::dirac ( std::vector< size_t >  _dimensions,
const std::vector< size_t > &  _position 
)
static

: Returns a TTNetwork with a single entry equals oen and all other zero.

Parameters
_dimensionsthe dimensions of the new tensor.
_positionThe position of the one

Definition at line 257 of file ttNetwork.cpp.

◆ dirac() [2/2]

template<bool isOperator>
TTNetwork< isOperator > xerus::TTNetwork< isOperator >::dirac ( std::vector< size_t >  _dimensions,
const size_t  _position 
)
static

: Returns a Tensor with a single entry equals oen and all other zero.

Parameters
_dimensionsthe dimensions of the new tensor.
_positionThe position of the one

Definition at line 281 of file ttNetwork.cpp.

◆ exceeds_maximal_ranks()

template<bool isOperator>
bool xerus::TTNetwork< isOperator >::exceeds_maximal_ranks ( ) const
protected

Tests whether any rank exceeds the theoretic maximal value it should have.

Does not check for the actual minimal rank for this tensor. But if any rank exceeds the theoretic maximum it is guaranteed not to be the minimal rank.

Returns
TRUE if any rank exceeds its theoretic maximum.

Definition at line 349 of file ttNetwork.cpp.

◆ fix_mode()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::fix_mode ( const size_t  _mode,
const size_t  _slatePosition 
)
overridevirtual

Fixes a specific mode to a specific value, effectively reducing the order by one.

Parameters
_modethe mode in which the slate shall be fixed, e.g. 0 to fix the first mode.
_slatePositionthe position in the corresponding mode that shall be used.

Reimplemented from xerus::TensorNetwork.

Definition at line 432 of file ttNetwork.cpp.

◆ frob_norm()

template<bool isOperator>
value_t xerus::TTNetwork< isOperator >::frob_norm ( ) const
overridevirtual

Calculates the frobenious norm of the TensorNetwork.

Returns
the frobenious norm of the TensorNetwork.

Reimplemented from xerus::TensorNetwork.

Definition at line 782 of file ttNetwork.cpp.

◆ get_component()

template<bool isOperator>
const Tensor & xerus::TTNetwork< isOperator >::get_component ( const size_t  _idx) const

Read access to a specific component of the TT decomposition.

This function should be used to access the components, instead of direct access via nodes[...], because the implementation does not store the first component in nodes[0] but rather as nodes[1] etc. nodes[0] is an order one node with dimension one only used to allow the first component to be an order three tensor.

Parameters
_idxindex of the component to access.
Returns
a const reference to the requested component.

Definition at line 464 of file ttNetwork.cpp.

◆ get_copy()

template<bool isOperator>
TensorNetwork * xerus::TTNetwork< isOperator >::get_copy ( ) const
overridevirtual

Returns a new copy of the network.

Reimplemented from xerus::TensorNetwork.

Definition at line 743 of file ttNetwork.cpp.

◆ identity() [1/2]

template<>
TTNetwork< true > xerus::TTNetwork< true >::identity ( const std::vector< size_t > &  _dimensions)

Definition at line 195 of file ttNetwork.cpp.

◆ identity() [2/2]

template<bool isOperator>
template<bool B = isOperator, typename std::enable_if< B, int >::type = 0>
static TTNetwork XERUS_warn_unused xerus::TTNetwork< isOperator >::identity ( const std::vector< size_t > &  _dimensions)
static

: Construct a TTOperator with the given dimensions representing the identity.

Only applicable for TTOperators, i.e. not for TTtensors

Parameters
_dimensionsthe dimensions of the new TTOperator.

◆ kronecker()

template<bool isOperator>
TTNetwork< isOperator > xerus::TTNetwork< isOperator >::kronecker ( const std::vector< size_t > &  _dimensions)
static

: Returns a TTNetwork representation of the kronecker delta.

That is each entry is one if all indices are equal and zero otherwise. Note iff d=2 this coincides with identity.

Parameters
_dimensionsthe dimensions of the new tensor.

Definition at line 224 of file ttNetwork.cpp.

◆ move_core()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::move_core ( const size_t  _position,
const bool  _keepRank = false 
)

Move the core to a new position.

The core is moved to _position and the nodes between the old and the new position are orthogonalized accordingly. If the TTNetwork is not yet canonicalized it will be with _position as new corePosition.

Parameters
_positionthe new core position.
_keepRankby default a rank revealing QR decomposition is used to move the core and the ranks are reduced accordingly. If _keepRank is set the rank is not reduced, this is need e.g. in the ALS.

Definition at line 582 of file ttNetwork.cpp.

◆ num_ranks()

template<bool isOperator>
size_t xerus::TTNetwork< isOperator >::num_ranks ( ) const
protected

Return the number of ranks, i.e. 0 for degree zero and degree()/N-1 otherwise.

Definition at line 363 of file ttNetwork.cpp.

◆ ones()

template<bool isOperator>
TTNetwork< isOperator > xerus::TTNetwork< isOperator >::ones ( const std::vector< size_t > &  _dimensions)
static

: Returns a the (rank one) TT-Tensor with all entries equal to one.

Parameters
_dimensionsthe dimensions of the new tensor.

Definition at line 170 of file ttNetwork.cpp.

◆ operator*=()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::operator*= ( const value_t  _factor)
overridevirtual

Calculates the entrywise multiplication of this TensorNetwork with a constant _factor.

Internally this only results in a change in the global factor.

Parameters
_factorthe factor.

Reimplemented from xerus::TensorNetwork.

Definition at line 860 of file ttNetwork.cpp.

◆ operator+=()

template<bool isOperator>
TTNetwork< isOperator > & xerus::TTNetwork< isOperator >::operator+= ( const TTNetwork< isOperator > &  _other)

Adds a given TTNetwork to this one.

To be well-defined it is required that the dimensions of this and _other coincide. The rank of the result are in general the entrywise sum of the ranks of this and _other.

Parameters
_otherthe TTNetwork to add.
Returns
reference to this TTNetwork.

Definition at line 797 of file ttNetwork.cpp.

◆ operator-=()

template<bool isOperator>
TTNetwork< isOperator > & xerus::TTNetwork< isOperator >::operator-= ( const TTNetwork< isOperator > &  _other)

Subtracts the _other TTNetwork entrywise from this one.

To be well-defined it is required that the dimensions of this and _other coincide. The rank of the result are in general the entrywise sum of the ranks of this and _other.

Parameters
_otherthe Tensor to be subtracted to this one.
Returns
a reference to this TTNetwork.

Definition at line 851 of file ttNetwork.cpp.

◆ operator/=()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::operator/= ( const value_t  _divisor)
overridevirtual

Calculates the entrywise divison of this TensorNetwork by a constant _divisor.

Internally this only results in a change in the global factor.

Parameters
_divisorthe divisor.

Reimplemented from xerus::TensorNetwork.

Definition at line 872 of file ttNetwork.cpp.

◆ operator=() [1/2]

template<bool isOperator>
TTNetwork& xerus::TTNetwork< isOperator >::operator= ( const TTNetwork< isOperator > &  _other)
default

TTNetworks are default assignable.

◆ operator=() [2/2]

template<bool isOperator>
TTNetwork& xerus::TTNetwork< isOperator >::operator= ( TTNetwork< isOperator > &&  _other)
default

TTNetworks are default move-assignable.

◆ random() [1/3]

template<bool isOperator>
template<class distribution = std::normal_distribution<value_t>, class generator = std::mt19937_64>
static TTNetwork XERUS_warn_unused xerus::TTNetwork< isOperator >::random ( std::vector< size_t >  _dimensions,
const std::vector< size_t > &  _ranks,
distribution &  _dist = xerus::misc::defaultNormalDistribution,
generator &  _rnd = xerus::misc::randomEngine 
)
inlinestatic

Transforms a given TensorNetwork to a TTNetwork.

This is not yet implemented different from casting to Tensor and then using a HOSVD.

Parameters
_networkThe network to transform.
_epsthe accuracy to be used in the transformation. Random constructs a TTNetwork with the given dimensions and ranks.

The entries of the componend tensors are sampled independendly using the provided random generator and distribution.

Parameters
_dimensionsthe dimensions of the to be created TTNetwork.
_ranksthe ranks of the to be created TTNetwork.
_rndthe random engine to be passed to the constructor of the component tensors.
_distthe random distribution to be passed to the constructor of the component tensors.

Definition at line 129 of file ttNetwork.h.

◆ random() [2/3]

template<bool isOperator>
template<class distribution = std::normal_distribution<value_t>, class generator = std::mt19937_64>
static TTNetwork XERUS_warn_unused xerus::TTNetwork< isOperator >::random ( const std::vector< size_t > &  _dimensions,
const size_t  _rank,
distribution &  _dist = xerus::misc::defaultNormalDistribution,
generator &  _rnd = xerus::misc::randomEngine 
)
inlinestatic

Random constructs a TTNetwork with the given dimensions and ranks limited by the given rank.

The entries of the componend tensors are sampled independendly using the provided random generator and distribution.

Parameters
_dimensionsthe dimensions of the to be created TTNetwork.
_rankthe maximal allowed rank.
_rndthe random engine to be passed to the constructor of the component tensors.
_distthe random distribution to be passed to the constructor of the component tensors.

Definition at line 167 of file ttNetwork.h.

◆ random() [3/3]

template<bool isOperator>
template<class distribution = std::normal_distribution<value_t>, class generator = std::mt19937_64>
static TTNetwork XERUS_warn_unused xerus::TTNetwork< isOperator >::random ( const std::vector< size_t > &  _dimensions,
const std::vector< size_t > &  _ranks,
const std::function< void(Tensor &)> &  _modifySingularValues,
distribution &  _dist = xerus::misc::defaultNormalDistribution,
generator &  _rnd = xerus::misc::randomEngine 
)
inlinestatic

Random constructs a TTNetwork with the given dimensions and ranks.

The entries of the componend tensors are sampled independendly using the provided random generator and distribution. the singular values of all matricisations M(1..n,n+1..N) are fixed according to the given function a posteriori The callback function is assumed to take a reference to a diagonal tensor and modify it to represent the desired singular values.

Definition at line 179 of file ttNetwork.h.

◆ rank()

template<bool isOperator>
size_t xerus::TTNetwork< isOperator >::rank ( const size_t  _i) const

Gets the rank of a specific egde of the TTNetwork.

Parameters
_iPosition of the edge in question.
Returns
The current rank of edge _i.

Definition at line 728 of file ttNetwork.cpp.

◆ ranks()

template<bool isOperator>
std::vector< size_t > xerus::TTNetwork< isOperator >::ranks ( ) const

Gets the ranks of the TTNetwork.

Returns
A vector containing the current ranks.

Definition at line 717 of file ttNetwork.cpp.

◆ reduce_to_maximal_ranks()

template<bool isOperator>
std::vector< size_t > xerus::TTNetwork< isOperator >::reduce_to_maximal_ranks ( std::vector< size_t >  _ranks,
const std::vector< size_t > &  _dimensions 
)
static

Reduces the given ranks to the maximal possible.

If a given rank is already smaller or equal it is left unchanged.

Parameters
_ranksthe inital ranks to be reduced.
_dimensionsthe dimensions used to calculate the maximal ranks.
Returns
the reduced ranks.

Definition at line 370 of file ttNetwork.cpp.

◆ require_correct_format()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::require_correct_format ( ) const
overridevirtual

Tests whether the network resembles that of a TTTensor and checks consistency with the underlying tensor objects.

Note that this will NOT check for orthogonality of canonicalized TTNetworks.

Reimplemented from xerus::TensorNetwork.

Definition at line 290 of file ttNetwork.cpp.

◆ resize_mode()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::resize_mode ( const size_t  _mode,
const size_t  _newDim,
const size_t  _cutPos = ~0ul 
)
overridevirtual

Resizes a specific mode of the TensorNetwork.

Parameters
_modethe mode to resize.
_newDimthe new value that resized mode shall have.
_cutPosthe position within the selected mode in front of which slates are inserted or removed. By default the current dimension, i.e new slates are added after the last current one and removed starting from the last one.

Reimplemented from xerus::TensorNetwork.

Definition at line 438 of file ttNetwork.cpp.

◆ round() [1/4]

template<bool isOperator>
void xerus::TTNetwork< isOperator >::round ( const std::vector< size_t > &  _maxRanks,
const double  _eps = EPSILON 
)

Reduce all ranks up to a given accuracy and maximal number.

Parameters
_maxRanksmaximal allowed ranks. All current ranks that are larger than the given ones are reduced by truncation.
_epsthe accuracy to use for truncation in the individual SVDs.

Definition at line 644 of file ttNetwork.cpp.

◆ round() [2/4]

template<bool isOperator>
void xerus::TTNetwork< isOperator >::round ( const size_t  _maxRank)

Reduce all ranks to the given number.

Parameters
_maxRankmaximal allowed rank. All current ranks that are larger than this are reduced by truncation.

Definition at line 669 of file ttNetwork.cpp.

◆ round() [3/4]

template<bool isOperator>
void xerus::TTNetwork< isOperator >::round ( const int  _maxRank)

Reduce all ranks to the given number.

Parameters
_maxRankmaximal allowed rank. All current ranks that are larger than this are reduced by truncation.

Definition at line 675 of file ttNetwork.cpp.

◆ round() [4/4]

template<bool isOperator>
void xerus::TTNetwork< isOperator >::round ( const value_t  _eps)

Reduce all ranks up to a given accuracy.

Parameters
_epsthe accuracy to use for truncation in the individual SVDs.

Definition at line 682 of file ttNetwork.cpp.

◆ set_component()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::set_component ( const size_t  _idx,
Tensor  _T 
)

Sets a specific component of the TT decomposition.

This function also takes care of adjusting the corresponding link dimensions and external dimensions if needed. However this might still leave the TTNetwork in an invalid if the rank is changed. In this case it is the callers responsibility to also update the other component tensors consistently to account for that rank change.

Parameters
_idxindex of the component to set.
_TTensor to use as the new component tensor.

Definition at line 471 of file ttNetwork.cpp.

◆ soft_threshold() [1/2]

template<bool isOperator>
void xerus::TTNetwork< isOperator >::soft_threshold ( const double  _tau,
const bool  _preventZero = false 
)

Applies the soft threshholding operation to all ranks.

Parameters
_tauthe soft threshholding parameter to be applied. I.e. all singular values are reduced to max(0, Lambda_ui - _tau).

Definition at line 711 of file ttNetwork.cpp.

◆ soft_threshold() [2/2]

template<bool isOperator>
void xerus::TTNetwork< isOperator >::soft_threshold ( const std::vector< double > &  _taus,
const bool  _preventZero = false 
)

Applies soft threshholding operations to all ranks.

Parameters
_tausthe soft threshholding parameters to be applied. I.e. all singular values of the j-th matrification are reduced to max(0, Lambda_ui - _tau[j]).

Definition at line 688 of file ttNetwork.cpp.

◆ specialized_contraction()

template<bool isOperator>
virtual bool xerus::TTNetwork< isOperator >::specialized_contraction ( std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &  _out,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _me,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _other 
) const
inlineoverridevirtual

(Internal) Calculates the contraction between _me and _other and stores the result in _out. Requires that *this is the tensorObjectReadOnly of _me.

Reimplemented from xerus::TensorNetwork.

Definition at line 506 of file ttNetwork.h.

◆ specialized_contraction_f() [1/3]

template<bool isOperator>
static bool xerus::TTNetwork< isOperator >::specialized_contraction_f ( std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &  _out,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _me,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _other 
)
static

◆ specialized_contraction_f() [2/3]

template<>
bool xerus::TTNetwork< false >::specialized_contraction_f ( std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &  ,
internal::IndexedTensorReadOnly< TensorNetwork > &&  ,
internal::IndexedTensorReadOnly< TensorNetwork > &&   
)

Definition at line 883 of file ttNetwork.cpp.

◆ specialized_contraction_f() [3/3]

template<>
bool xerus::TTNetwork< true >::specialized_contraction_f ( std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &  _out,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _me,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _other 
)

Definition at line 889 of file ttNetwork.cpp.

◆ specialized_evaluation()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::specialized_evaluation ( internal::IndexedTensorWritable< TensorNetwork > &&  _me,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _other 
)
overridevirtual

(Internal) Evaluates _other into _me. Requires that *this is the tensorObjectReadOnly of _me.

Reimplemented from xerus::TensorNetwork.

Definition at line 1064 of file ttNetwork.cpp.

◆ specialized_sum()

template<bool isOperator>
virtual bool xerus::TTNetwork< isOperator >::specialized_sum ( std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &  _out,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _me,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _other 
) const
inlineoverridevirtual

(Internal) Calculates the sum between _me and _other and stores the result in _out. Requires that *this is the tensorObjectReadOnly of _me.

Reimplemented from xerus::TensorNetwork.

Definition at line 510 of file ttNetwork.h.

◆ specialized_sum_f()

template<bool isOperator>
bool xerus::TTNetwork< isOperator >::specialized_sum_f ( std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &  _out,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _me,
internal::IndexedTensorReadOnly< TensorNetwork > &&  _other 
)
static

Definition at line 982 of file ttNetwork.cpp.

◆ transpose()

template<bool isOperator>
template<bool B = isOperator, typename std::enable_if< B, int >::type = 0>
void xerus::TTNetwork< isOperator >::transpose ( )
inline

Transpose the TTOperator.

Swaps all external indices to create the transposed operator.

Definition at line 443 of file ttNetwork.h.

◆ use_dense_representations()

template<bool isOperator>
void xerus::TTNetwork< isOperator >::use_dense_representations ( )

Converts all components to use dense representations.

Note
This might be required because not all functionality of TTNetworks is available with sparse component tensors.

Definition at line 450 of file ttNetwork.cpp.

Member Data Documentation

◆ canonicalized

template<bool isOperator>
bool xerus::TTNetwork< isOperator >::canonicalized

Flag indicating whether the TTNetwork is canonicalized.

Definition at line 51 of file ttNetwork.h.

◆ corePosition

template<bool isOperator>
size_t xerus::TTNetwork< isOperator >::corePosition

The position of the core.

If canonicalized is TRUE, corePosition gives the position of the core tensor. All components with smaller index are then left-orthogonalized and all components with larger index right-orthogonalized.

Definition at line 58 of file ttNetwork.h.

◆ N

template<bool isOperator>
constexpr const size_t xerus::TTNetwork< isOperator >::N = isOperator?2:1
static

The number of external links in each node, i.e. one for TTTensors and two for TTOperators.

Definition at line 48 of file ttNetwork.h.


The documentation for this class was generated from the following files: