SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
IterativeSolverIterator.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2013 Soumyajit De
8  */
9 
10 #ifndef ITERATIVE_SOLVER_ITERATOR_H_
11 #define ITERATIVE_SOLVER_ITERATOR_H_
12 
13 #include <shogun/lib/config.h>
14 
16 
17 using namespace Eigen;
18 
19 namespace shogun
20 {
21 
26 typedef struct _IterInfo
27 {
30 
33 } IterInfo;
34 
43 template<class T> class IterativeSolverIterator
44 {
45 
47 
48 public:
59  IterativeSolverIterator(const VectorXt& b,
60  index_t max_iteration_limit=1000,
61  float64_t relative_tolerence=1E-5,
62  float64_t absolute_tolerence=1E-5)
63  : m_max_iteration_limit(max_iteration_limit),
64  m_tolerence(absolute_tolerence+relative_tolerence*b.norm()),
65  m_success(false)
66  {
67  m_iter_info.residual_norm=std::numeric_limits<float64_t>::max();
68  m_iter_info.iteration_count=0;
69  }
70 
72  void begin(const VectorXt& residual)
73  {
74  m_iter_info.residual_norm=residual.norm();
75  m_iter_info.iteration_count=0;
76  }
77 
79  const bool end(const VectorXt& residual)
80  {
81  m_iter_info.residual_norm=residual.norm();
82 
83  m_success=m_iter_info.residual_norm < m_tolerence;
84  return m_success || m_iter_info.iteration_count >= m_max_iteration_limit;
85  }
86 
88  const IterInfo get_iter_info() const
89  {
90  return m_iter_info;
91  }
92 
94  const bool succeeded(const VectorXt& residual)
95  {
96  m_iter_info.residual_norm=residual.norm();
97 
98  m_success=m_iter_info.residual_norm < m_tolerence;
99  return m_success;
100  }
101 
103  void operator++()
104  {
105  m_iter_info.iteration_count++;
106  }
107 
108 private:
110  IterInfo m_iter_info;
111 
113  const index_t m_max_iteration_limit;
114 
116  const float64_t m_tolerence;
117 
119  bool m_success;
120 };
121 
122 }
123 
124 #endif // ITERATIVE_SOLVER_ITERATOR_H_
void begin(const VectorXt &residual)
int32_t index_t
Definition: common.h:62
Definition: SGMatrix.h:20
struct shogun::_IterInfo IterInfo
struct that contains current state of the iteration for iterative linear solvers
const bool end(const VectorXt &residual)
template class that is used as an iterator for an iterative linear solver. In the iteration of solvin...
struct that contains current state of the iteration for iterative linear solvers
IterativeSolverIterator(const VectorXt &b, index_t max_iteration_limit=1000, float64_t relative_tolerence=1E-5, float64_t absolute_tolerence=1E-5)
double float64_t
Definition: common.h:50
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
const bool succeeded(const VectorXt &residual)
Matrix::Scalar max(Matrix m)
Definition: Redux.h:68

SHOGUN Machine Learning Toolbox - Documentation