40 static const Index i,j;
50 _perfData <<
"Conjugated Gradients for ||A*x - b||^2, x.dimensions: " << _x.
dimensions <<
'\n' 51 <<
"A.ranks: " << _A.
ranks() <<
'\n';
53 _perfData <<
" with symmetric positive definite Operator A\n";
56 _perfData <<
"Conjugated Gradients for ||x - b||^2, x.dimensions: " << _x.
dimensions <<
'\n';
58 _perfData <<
"x.ranks: " << _x.
ranks() <<
'\n' 59 <<
"b.ranks: " << _b.
ranks() <<
'\n' 60 <<
"maximum number of steps: " << _numSteps <<
'\n' 61 <<
"convergence epsilon: " << _convergenceEpsilon <<
'\n';
64 auto calculateResidual = [&]()->
value_t {
66 residual(i&0) =
_b(i&0) - _A(i/2,j/2)*_x(j&0);
72 auto updateGradient = [&]() {
77 grad(i&0) = (*_Ap)(j/2,i/2) * residual(j&0);
83 currResidual = calculateResidual();
84 _perfData.
add(stepCount, currResidual, _x);
89 while ((_numSteps == 0 || stepCount < _numSteps)
90 && currResidual/normB > _convergenceEpsilon
91 && std::abs(lastResidual-currResidual)/normB > _convergenceEpsilon
92 && std::abs(1-currResidual/lastResidual)/normB > _convergenceEpsilon)
101 if (derivative <= 0) {
102 direction = gradient;
110 _perfData.
add(stepCount, currResidual, _x, stepFlags);
115 value_t oldGradNorm = gradientNorm;
118 double beta = gradientNorm / oldGradNorm ;
119 direction = gradient;
120 direction += oldDirection * beta;
bool assumeSymmetricPositiveDefiniteOperator
calculates the gradient as b-Ax instead of A^T(b-Ax)
Header file for the Index class.
Header file for the IndexedTensorMoveable class.
Header file for the steepest descent algorithms.
Header file defining lists of indexed tensors.
Header file for the classes defining factorisations of Tensors.
class to compactly represent tangent vectors of the manifold of constant TT-rank
Specialized TensorNetwork class used to represent TTTensor and TToperators.
The main namespace of xerus.
Header file for the ALS algorithm and its variants.
void ProjectiveVectorTransport(const TTTensor &_newBase, TTTangentVector &_tangentVector)
simple vector transport by projecting onto the new tangent plane
double solve(const TTOperator *_Ap, TTTensor &_x, const TTTensor &_b, size_t _numSteps, value_t _convergenceEpsilon, PerformanceData &_perfData=NoPerfData) const
TTRetractionI retraction
the retraction type I to project from point + tangent vector to a new point on the manifold ...
value_t frob_norm() const
Wrapper class for all geometric (ie. Riemannian) CG variants.
std::vector< size_t > ranks() const
Gets the ranks of the TTNetwork.
void SubmanifoldRetractionI(TTTensor &_U, const TTTangentVector &_change)
retraction that performs componentwise addition of and where is the i-th component of the riemanni...
TTVectorTransport vectorTransport
the vector transport from old tangent space to new one
static XERUS_force_inline value_t frob_norm(const Tensor &_tensor)
Calculates the frobenius norm of the given tensor.
Header file for shorthand notations that are xerus specific but used throughout the library...
double value_t
The type of values to be used by xerus.
Class used to represent indices that can be used to write tensor calculations in index notation...
void line_search(TTTensor &_x, value_t &_alpha, const TTTangentVector &_direction, value_t _derivative, value_t &_residual, std::function< void(TTTensor &, const TTTangentVector &)> _retraction, std::function< value_t()> _calculate_residual, value_t _changeInAlpha=0.5)
const GeometricCGVariant GeometricCG
default variant of the steepest descent algorithm using the lapack solver
value_t scalar_product(const TTTangentVector &_other) const
Header file for the TensorNetwork class.
Header file for the CG algorithm.
std::vector< size_t > dimensions
Dimensions of the external indices, i.e. the dimensions of the tensor represented by the network...