xerus
a general purpose tensor library
steepestDescent.h
Go to the documentation of this file.
1 // Xerus - A General Purpose Tensor Library
2 // Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3 //
4 // Xerus is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published
6 // by the Free Software Foundation, either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // Xerus is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // For further information on Xerus visit https://libXerus.org
18 // or contact us at contact@libXerus.org.
19 
25 #pragma once
26 
27 #include "../ttNetwork.h"
28 #include "../performanceData.h"
29 #include "retractions.h"
30 
31 namespace xerus {
32 
33 
34  void line_search(TTTensor &_x, value_t &_alpha, const TTTangentVector &_direction, value_t _derivative, value_t &_residual,
35  std::function<void(TTTensor &, const TTTangentVector &)> _retraction,
36  std::function<value_t()> _calculate_residual,
37  value_t _changeInAlpha = 0.5
38  );
39 
46  protected:
47  double solve(const TTOperator *_Ap, TTTensor &_x, const TTTensor &_b, size_t _numSteps, value_t _convergenceEpsilon, PerformanceData &_perfData = NoPerfData) const;
48 
49  public:
50  size_t numSteps;
54 
56 
57  // TODO preconditioner
58 
60  SteepestDescentVariant(size_t _numSteps, value_t _convergenceEpsilon, bool _symPosOp, TTRetractionII _retraction)
61  : numSteps(_numSteps), convergenceEpsilon(_convergenceEpsilon),
62  assumeSymmetricPositiveDefiniteOperator(_symPosOp), preconditioner(nullptr), retraction(_retraction)
63  { }
64 
67  : numSteps(0), convergenceEpsilon(0.0), assumeSymmetricPositiveDefiniteOperator(false), preconditioner(nullptr), retraction(_retraction)
68  { }
69 
79  double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, value_t _convergenceEpsilon, PerformanceData &_perfData = NoPerfData) const {
80  return solve(&_A, _x, _b, numSteps, _convergenceEpsilon, _perfData);
81  }
82 
92  double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, size_t _numSteps, PerformanceData &_perfData = NoPerfData) const {
93  return solve(&_A, _x, _b, _numSteps, convergenceEpsilon, _perfData);
94  }
95 
104  double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, PerformanceData &_perfData = NoPerfData) const {
105  return solve(&_A, _x, _b, numSteps, convergenceEpsilon, _perfData);
106  }
107 
116  double operator()(TTTensor &_x, const TTTensor &_b, value_t _convergenceEpsilon, PerformanceData &_perfData = NoPerfData) const {
117  return solve(nullptr, _x, _b, numSteps, _convergenceEpsilon, _perfData);
118  }
119 
128  double operator()(TTTensor &_x, const TTTensor &_b, size_t _numSteps, PerformanceData &_perfData = NoPerfData) const {
129  return solve(nullptr, _x, _b, _numSteps, convergenceEpsilon, _perfData);
130  }
131 
132  double operator()(TTTensor &_x, const TTTensor &_b, PerformanceData &_perfData = NoPerfData) const {
133  return solve(nullptr, _x, _b, numSteps, convergenceEpsilon, _perfData);
134  }
135  };
136 
139 }
140 
double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, size_t _numSteps, PerformanceData &_perfData=NoPerfData) const
SteepestDescentVariant(TTRetractionII _retraction)
definition using only the retraction. In the following an operator() including either convergenceEpsi...
double operator()(TTTensor &_x, const TTTensor &_b, value_t _convergenceEpsilon, PerformanceData &_perfData=NoPerfData) const
double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, PerformanceData &_perfData=NoPerfData) const
Specialized TensorNetwork class used to represent TTTensor and TToperators.
double operator()(TTTensor &_x, const TTTensor &_b, PerformanceData &_perfData=NoPerfData) const
The main namespace of xerus.
Definition: basic.h:37
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
size_t numSteps
maximum number of steps to perform. set to 0 for infinite
Storage class for the performance data collected during an algorithm (typically iteration count...
value_t convergenceEpsilon
default value for the change in the residual at which the algorithm assumes it is converged ...
TTNetwork< false > TTTensor
double operator()(TTTensor &_x, const TTTensor &_b, size_t _numSteps, PerformanceData &_perfData=NoPerfData) const
PerformanceData NoPerfData
Header file for several retractions of type I and II as well as simple vector transport.
TTRetractionII retraction
the retraction to project from point + tangent vector to a new point on the manifold ...
double value_t
The type of values to be used by xerus.
Definition: basic.h:43
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)
std::function< void(TTTensor &, const TTTensor &)> TTRetractionII
Definition: retractions.h:71
SteepestDescentVariant(size_t _numSteps, value_t _convergenceEpsilon, bool _symPosOp, TTRetractionII _retraction)
fully defining constructor. alternatively SteepestDescentVariant can be created by copying a predefin...
double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, value_t _convergenceEpsilon, PerformanceData &_perfData=NoPerfData) const
bool assumeSymmetricPositiveDefiniteOperator
calculates the gradient as b-Ax instead of A^T(b-Ax)