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 #include <shogun/lib/common.h> 00011 #include <shogun/lib/SGVector.h> 00012 #include <shogun/mathematics/Math.h> 00013 #include <shogun/mathematics/linalg/linsolver/IterativeShiftedLinearFamilySolver.h> 00014 00015 namespace shogun 00016 { 00017 00018 template <class T, class ST> 00019 CIterativeShiftedLinearFamilySolver<T, ST>::CIterativeShiftedLinearFamilySolver() 00020 : CIterativeLinearSolver<T, T>() 00021 { 00022 } 00023 00024 template <class T, class ST> 00025 CIterativeShiftedLinearFamilySolver<T, ST> 00026 ::CIterativeShiftedLinearFamilySolver(bool store_residuals) 00027 : CIterativeLinearSolver<T, T>(store_residuals) 00028 { 00029 } 00030 00031 template <class T, class ST> 00032 CIterativeShiftedLinearFamilySolver<T, ST>::~CIterativeShiftedLinearFamilySolver() 00033 { 00034 } 00035 00036 template <class T, class ST> 00037 void CIterativeShiftedLinearFamilySolver<T, ST>::compute_zeta_sh_new( 00038 const SGVector<ST>& zeta_sh_old, const SGVector<ST>& zeta_sh_cur, const SGVector<ST>& shifts, 00039 const T& beta_old, const T& beta_cur, const T& alpha, SGVector<ST>& zeta_sh_new) 00040 { 00041 // compute zeta_sh_new according to Jergerlehner, eq. 2.44 00042 // [see IterativeShiftedLinearFamilySolver.h] 00043 for (index_t i=0; i<zeta_sh_new.vlen; ++i) 00044 { 00045 ST numer=zeta_sh_old[i]*zeta_sh_cur[i]*beta_old; 00046 00047 ST denom=beta_cur*alpha*(zeta_sh_old[i]-zeta_sh_cur[i]) 00048 +beta_old*zeta_sh_old[i]*(1.0-beta_cur*shifts[i]); 00049 00050 // handle division by zero 00051 if (denom==static_cast<ST>(0.0)) 00052 denom=static_cast<ST>(CMath::MACHINE_EPSILON); 00053 00054 zeta_sh_new[i]=numer/denom; 00055 } 00056 } 00057 00058 template <class T, class ST> 00059 void CIterativeShiftedLinearFamilySolver<T, ST>::compute_beta_sh( 00060 const SGVector<ST>& zeta_sh_new, const SGVector<ST>& zeta_sh_cur, const T& beta_cur, 00061 SGVector<ST>& beta_sh_cur) 00062 { 00063 // compute beta_sh_cur according to Jergerlehner, eq. 2.42 00064 // [see IterativeShiftedLinearFamilySolver.h] 00065 for (index_t i=0; i<beta_sh_cur.vlen; ++i) 00066 { 00067 ST numer=beta_cur*zeta_sh_new[i]; 00068 ST denom=zeta_sh_cur[i]; 00069 00070 // handle division by zero 00071 if (denom==static_cast<ST>(0.0)) 00072 denom=static_cast<ST>(CMath::MACHINE_EPSILON); 00073 00074 beta_sh_cur[i]=numer/denom; 00075 } 00076 } 00077 00078 template <class T, class ST> 00079 void CIterativeShiftedLinearFamilySolver<T, ST>::compute_alpha_sh( 00080 const SGVector<ST>& zeta_sh_cur, const SGVector<ST>& zeta_sh_old, 00081 const SGVector<ST>& beta_sh_old, const T& beta_old, const T& alpha, SGVector<ST>& alpha_sh) 00082 { 00083 // compute alpha_sh_cur according to Jergerlehner, eq. 2.43 00084 // [see IterativeShiftedLinearFamilySolver.h] 00085 for (index_t i=0; i<alpha_sh.vlen; ++i) 00086 { 00087 ST numer=alpha*zeta_sh_cur[i]*beta_sh_old[i]; 00088 ST denom=zeta_sh_old[i]*beta_old; 00089 00090 // handle division by zero 00091 if (denom==static_cast<ST>(0.0)) 00092 denom=static_cast<ST>(CMath::MACHINE_EPSILON); 00093 00094 alpha_sh[i]=numer/denom; 00095 } 00096 } 00097 00098 template class CIterativeShiftedLinearFamilySolver<float64_t>; 00099 template class CIterativeShiftedLinearFamilySolver<float64_t, complex128_t>; 00100 }