39 std::function<
value_t()> _calculate_residual,
43 value_t currAlpha = _alpha / _changeInAlpha;
45 _retraction(_x, currAlpha/dirNorm * _direction);
46 value_t bestResidual = _calculate_residual();
51 currAlpha *= _changeInAlpha;
53 _retraction(_x, currAlpha/dirNorm * _direction);
54 value_t newResidual = _calculate_residual();
56 if (newResidual < bestResidual) {
57 bestResidual = newResidual;
58 bestAlpha = currAlpha;
65 _x = std::move(bestX);
69 const value_t min_decrease = 1e-4;
71 while (_alpha > 1e-16 && bestResidual > _residual - min_decrease * _alpha/dirNorm * _derivative) {
73 _alpha *= _changeInAlpha;
75 _retraction(_x, _alpha/dirNorm * _direction);
76 bestResidual = _calculate_residual();
79 _residual = bestResidual;
85 static const Index i,j;
94 _perfData <<
"Steepest Descent for ||A*x - b||^2, x.dimensions: " << _x.
dimensions <<
'\n' 95 <<
"A.ranks: " << _A.
ranks() <<
'\n';
97 _perfData <<
" with symmetric positive definite Operator A\n";
100 _perfData <<
"Steepest Descent for ||x - b||^2, x.dimensions: " << _x.
dimensions <<
'\n';
102 _perfData <<
"x.ranks: " << _x.
ranks() <<
'\n' 103 <<
"b.ranks: " << _b.
ranks() <<
'\n' 104 <<
"maximum number of steps: " << _numSteps <<
'\n' 105 <<
"convergence epsilon: " << _convergenceEpsilon <<
'\n';
108 auto updateResidual = [&]() {
109 if (_Ap !=
nullptr) {
110 residual(i&0) =
_b(i&0) - _A(i/2,j/2)*_x(j&0);
117 auto updatePerfdata = [&]() {
118 _perfData.
add(currResidual);
125 while ((_numSteps == 0 || stepCount < _numSteps)
126 && currResidual > _convergenceEpsilon
127 && std::abs(lastResidual-currResidual) > _convergenceEpsilon
128 && std::abs(1-currResidual/lastResidual) > _convergenceEpsilon)
132 if (_Ap !=
nullptr) {
137 y(j&0) = (*preconditioner)(j/2,i/2) * y(i&0);
145 y(i&0) = _A(j/2,i/2) * residual(j&0);
147 y(j&0) = (*preconditioner)(j/2,i/2) * y(i&0);
161 lastResidual = currResidual;
164 while (alpha > 1e-30 && lastResidual < currResidual){
Header file for the Index class.
#define XERUS_REQUIRE_TEST
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
The main namespace of xerus.
Header file for the ALS algorithm and its variants.
Wrapper class for all steepest descent variants.
double solve(const TTOperator *_Ap, TTTensor &_x, const TTTensor &_b, size_t _numSteps, value_t _convergenceEpsilon, PerformanceData &_perfData=NoPerfData) const
value_t frob_norm() const
TTOperator * preconditioner
std::vector< size_t > ranks() const
Gets the ranks of the TTNetwork.
static XERUS_force_inline value_t frob_norm(const Tensor &_tensor)
Calculates the frobenius norm of the given tensor.
TTRetractionII retraction
the retraction to project from point + tangent vector to a new point on the manifold ...
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...
const SteepestDescentVariant SteepestDescent
default variant of the steepest descent algorithm using the lapack solver
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)
bool assumeSymmetricPositiveDefiniteOperator
calculates the gradient as b-Ax instead of A^T(b-Ax)
void SubmanifoldRetractionII(TTTensor &_U, const TTTensor &_change)
retraction that performs componentwise addition of and where is the i-th component of the riemanni...
Header file for the TensorNetwork class.
std::vector< size_t > dimensions
Dimensions of the external indices, i.e. the dimensions of the tensor represented by the network...