SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2013 Soumyajit De 00008 */ 00009 00010 #ifndef ITERATIVE_LINEAR_SOLVER_H_ 00011 #define ITERATIVE_LINEAR_SOLVER_H_ 00012 00013 #include <shogun/lib/config.h> 00014 #include <shogun/mathematics/linalg/linsolver/LinearSolver.h> 00015 00016 namespace shogun 00017 { 00018 00024 template<class T, class ST=T> class CIterativeLinearSolver : public CLinearSolver<T, ST> 00025 { 00026 00027 public: 00029 CIterativeLinearSolver(); 00030 00032 CIterativeLinearSolver(bool store_residuals); 00033 00035 virtual ~CIterativeLinearSolver(); 00036 00044 virtual SGVector<T> solve(CLinearOperator<T>* A, SGVector<ST> b) = 0; 00045 00047 void set_iteration_limit(index_t iteration_limit) 00048 { 00049 m_max_iteration_limit=iteration_limit; 00050 if (m_store_residuals) 00051 { 00052 m_residuals=SGVector<float64_t>(m_max_iteration_limit); 00053 m_residuals.set_const(0.0); 00054 } 00055 } 00056 00058 const index_t get_iteration_limit() const 00059 { 00060 return m_max_iteration_limit; 00061 } 00062 00064 void set_relative_tolerence(float64_t relative_tolerence) 00065 { 00066 m_relative_tolerence=relative_tolerence; 00067 } 00068 00070 const float64_t get_relative_tolerence() const 00071 { 00072 return m_relative_tolerence; 00073 } 00074 00076 void set_absolute_tolerence(float64_t absolute_tolerence) 00077 { 00078 m_absolute_tolerence=absolute_tolerence; 00079 } 00080 00082 const float64_t get_absolute_tolerence() const 00083 { 00084 return m_absolute_tolerence; 00085 } 00086 00088 SGVector<float64_t> get_residuals() const 00089 { 00090 return m_residuals; 00091 } 00092 00094 virtual const char* get_name() const 00095 { 00096 return "IterativeLinearSolver"; 00097 } 00098 00099 protected: 00100 00102 index_t m_max_iteration_limit; 00103 00105 float64_t m_relative_tolerence; 00106 00108 float64_t m_absolute_tolerence; 00109 00111 SGVector<float64_t> m_residuals; 00112 00114 bool m_store_residuals; 00115 private: 00117 void init(); 00118 00119 }; 00120 00121 } 00122 00123 #endif // ITERATIVE_LINEAR_SOLVER_H_