SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
IterativeShiftedLinearFamilySolver.cpp
浏览该文件的文档.
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 #include <shogun/lib/common.h>
11 #include <shogun/lib/SGVector.h>
14 
15 namespace shogun
16 {
17 
18 template <class T, class ST>
20  : CIterativeLinearSolver<T, T>()
21  {
22  }
23 
24 template <class T, class ST>
27  : CIterativeLinearSolver<T, T>(store_residuals)
28  {
29  }
30 
31 template <class T, class ST>
33  {
34  }
35 
36 template <class T, class ST>
38  const SGVector<ST>& zeta_sh_old, const SGVector<ST>& zeta_sh_cur, const SGVector<ST>& shifts,
39  const T& beta_old, const T& beta_cur, const T& alpha, SGVector<ST>& zeta_sh_new)
40  {
41  // compute zeta_sh_new according to Jergerlehner, eq. 2.44
42  // [see IterativeShiftedLinearFamilySolver.h]
43  for (index_t i=0; i<zeta_sh_new.vlen; ++i)
44  {
45  ST numer=zeta_sh_old[i]*zeta_sh_cur[i]*beta_old;
46 
47  ST denom=beta_cur*alpha*(zeta_sh_old[i]-zeta_sh_cur[i])
48  +beta_old*zeta_sh_old[i]*(1.0-beta_cur*shifts[i]);
49 
50  // handle division by zero
51  if (denom==static_cast<ST>(0.0))
52  denom=static_cast<ST>(CMath::MACHINE_EPSILON);
53 
54  zeta_sh_new[i]=numer/denom;
55  }
56  }
57 
58 template <class T, class ST>
60  const SGVector<ST>& zeta_sh_new, const SGVector<ST>& zeta_sh_cur, const T& beta_cur,
61  SGVector<ST>& beta_sh_cur)
62  {
63  // compute beta_sh_cur according to Jergerlehner, eq. 2.42
64  // [see IterativeShiftedLinearFamilySolver.h]
65  for (index_t i=0; i<beta_sh_cur.vlen; ++i)
66  {
67  ST numer=beta_cur*zeta_sh_new[i];
68  ST denom=zeta_sh_cur[i];
69 
70  // handle division by zero
71  if (denom==static_cast<ST>(0.0))
72  denom=static_cast<ST>(CMath::MACHINE_EPSILON);
73 
74  beta_sh_cur[i]=numer/denom;
75  }
76  }
77 
78 template <class T, class ST>
80  const SGVector<ST>& zeta_sh_cur, const SGVector<ST>& zeta_sh_old,
81  const SGVector<ST>& beta_sh_old, const T& beta_old, const T& alpha, SGVector<ST>& alpha_sh)
82  {
83  // compute alpha_sh_cur according to Jergerlehner, eq. 2.43
84  // [see IterativeShiftedLinearFamilySolver.h]
85  for (index_t i=0; i<alpha_sh.vlen; ++i)
86  {
87  ST numer=alpha*zeta_sh_cur[i]*beta_sh_old[i];
88  ST denom=zeta_sh_old[i]*beta_old;
89 
90  // handle division by zero
91  if (denom==static_cast<ST>(0.0))
92  denom=static_cast<ST>(CMath::MACHINE_EPSILON);
93 
94  alpha_sh[i]=numer/denom;
95  }
96  }
97 
100 }
static const float64_t MACHINE_EPSILON
Definition: Math.h:2058
void compute_zeta_sh_new(const SGVector< ST > &zeta_sh_old, const SGVector< ST > &zeta_sh_cur, const SGVector< ST > &shifts, const T &beta_old, const T &beta_cur, const T &alpha, SGVector< ST > &zeta_sh_new)
int32_t index_t
Definition: common.h:62
void compute_beta_sh(const SGVector< ST > &zeta_sh_new, const SGVector< ST > &zeta_sh_cur, const T &beta_cur, SGVector< ST > &beta_sh)
index_t vlen
Definition: SGVector.h:494
abstract template base for all iterative linear solvers such as conjugate gradient (CG) solvers...
shogun vector
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void compute_alpha_sh(const SGVector< ST > &zeta_sh_cur, const SGVector< ST > &zeta_sh_old, const SGVector< ST > &beta_sh_old, const T &beta_old, const T &alpha, SGVector< ST > &alpha_sh)
abstract template base for CG based solvers to the solution of shifted linear systems of the form fo...

SHOGUN 机器学习工具包 - 项目文档