xerus
a general purpose tensor library
cg.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 
42  protected:
43  double solve(const TTOperator *_Ap, TTTensor &_x, const TTTensor &_b, size_t _numSteps, value_t _convergenceEpsilon, PerformanceData &_perfData = NoPerfData) const;
44 
45  public:
46  size_t numSteps;
49 
52 
53  // TODO preconditioner
54 
56  GeometricCGVariant(size_t _numSteps, value_t _convergenceEpsilon, bool _symPosOp,
57  TTRetractionI _retraction,
58  TTVectorTransport _vectorTransport
59  )
60  : numSteps(_numSteps), convergenceEpsilon(_convergenceEpsilon), assumeSymmetricPositiveDefiniteOperator(_symPosOp),
61  retraction(_retraction), vectorTransport(_vectorTransport)
62  { }
63 
65  GeometricCGVariant(TTRetractionI _retraction, TTVectorTransport _vectorTransport)
66  : numSteps(0), convergenceEpsilon(0.0), assumeSymmetricPositiveDefiniteOperator(false),
67  retraction(_retraction), vectorTransport(_vectorTransport)
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 
138  extern const GeometricCGVariant GeometricCG;
139 }
140 
double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, value_t _convergenceEpsilon, PerformanceData &_perfData=NoPerfData) const
Definition: cg.h:79
bool assumeSymmetricPositiveDefiniteOperator
calculates the gradient as b-Ax instead of A^T(b-Ax)
Definition: cg.h:48
double operator()(TTTensor &_x, const TTTensor &_b, PerformanceData &_perfData=NoPerfData) const
Definition: cg.h:132
GeometricCGVariant(size_t _numSteps, value_t _convergenceEpsilon, bool _symPosOp, TTRetractionI _retraction, TTVectorTransport _vectorTransport)
fully defining constructor. alternatively CGVariant can be created by copying a predefined variant an...
Definition: cg.h:56
double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, size_t _numSteps, PerformanceData &_perfData=NoPerfData) const
Definition: cg.h:92
std::function< void(TTTensor &, const TTTangentVector &)> TTRetractionI
Definition: retractions.h:70
Specialized TensorNetwork class used to represent TTTensor and TToperators.
The main namespace of xerus.
Definition: basic.h:37
double solve(const TTOperator *_Ap, TTTensor &_x, const TTTensor &_b, size_t _numSteps, value_t _convergenceEpsilon, PerformanceData &_perfData=NoPerfData) const
Definition: cg.cpp:38
Storage class for the performance data collected during an algorithm (typically iteration count...
size_t numSteps
maximum number of steps to perform. set to 0 for infinite
Definition: cg.h:46
TTRetractionI retraction
the retraction type I to project from point + tangent vector to a new point on the manifold ...
Definition: cg.h:50
Wrapper class for all geometric (ie. Riemannian) CG variants.
Definition: cg.h:41
value_t convergenceEpsilon
default value for the change in the residual at which the algorithm assumes it is converged ...
Definition: cg.h:47
double operator()(const TTOperator &_A, TTTensor &_x, const TTTensor &_b, PerformanceData &_perfData=NoPerfData) const
Definition: cg.h:104
TTVectorTransport vectorTransport
the vector transport from old tangent space to new one
Definition: cg.h:51
PerformanceData NoPerfData
Header file for several retractions of type I and II as well as simple vector transport.
double operator()(TTTensor &_x, const TTTensor &_b, size_t _numSteps, PerformanceData &_perfData=NoPerfData) const
Definition: cg.h:128
double value_t
The type of values to be used by xerus.
Definition: basic.h:43
double operator()(TTTensor &_x, const TTTensor &_b, value_t _convergenceEpsilon, PerformanceData &_perfData=NoPerfData) const
Definition: cg.h:116
const GeometricCGVariant GeometricCG
default variant of the steepest descent algorithm using the lapack solver
GeometricCGVariant(TTRetractionI _retraction, TTVectorTransport _vectorTransport)
definition using only the retraction. In the following an operator() including either convergenceEpsi...
Definition: cg.h:65
std::function< void(const TTTensor &, TTTangentVector &)> TTVectorTransport
Definition: retractions.h:72