From ead43a943036a41b306dbfc5fcd5341fb58bdba8 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Mon, 9 Apr 2012 14:24:53 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@235 ed2142bd-67ad-457f-ba7c-d818d4011675 --- methods/conjugate_gradient/conjugate_gradient.hpp | 129 +++++++++++++--------- 1 file changed, 77 insertions(+), 52 deletions(-) diff --git a/methods/conjugate_gradient/conjugate_gradient.hpp b/methods/conjugate_gradient/conjugate_gradient.hpp index edec92d..c22aac8 100644 --- a/methods/conjugate_gradient/conjugate_gradient.hpp +++ b/methods/conjugate_gradient/conjugate_gradient.hpp @@ -1,6 +1,6 @@ /** \file conjugate_gradient.hpp - \brief conjugate gradient optimization method + \brief powerll optimization method \author Junhua Gu */ @@ -13,9 +13,10 @@ #include #include #include "../linmin/linmin.hpp" +#include #include #include -#include + namespace opt_utilities { /** @@ -34,10 +35,11 @@ namespace opt_utilities func_obj* p_fo; optimizer* p_optimizer; volatile bool bstop; + //typedef blitz::Array array2d_type; const char* do_get_type_name()const { - return "conjugate gradient"; + return "conjugate gradient method"; } private: array1d_type start_point; @@ -45,6 +47,9 @@ namespace opt_utilities private: rT threshold; + array1d_type g; + array1d_type h; + array1d_type xi; private: rT func(const pT& x) { @@ -54,24 +59,86 @@ namespace opt_utilities private: + void clear_xi() + { + } + + void init_xi(int n) + { + clear_xi(); + g=array1d_type(n); + h=array1d_type(n); + xi=array1d_type(n); + } + + void cg(array1d_type& p,const T ftol, + int& iter,T& fret) + { + const int ITMAX=200; + const T EPS=std::numeric_limits::epsilon(); + + int j,its; + int n=p.size(); + T gg,gam,fp,dgg; + fp=func(p); + xi=gradient(*p_fo,p); + for(j=0;j& rhs) :opt_method(rhs),p_fo(rhs.p_fo),p_optimizer(rhs.p_optimizer), start_point(rhs.start_point), end_point(rhs.end_point), - threshold(rhs.threshold) + threshold(rhs.threshold),g(0),h(0),xi(0) { } @@ -128,54 +195,12 @@ namespace opt_utilities pT do_optimize() { bstop=false; + init_xi((int)get_size(start_point)); + + int iter=100; opt_eq(end_point,start_point); - pT xn; - opt_eq(xn,start_point); - pT Delta_Xn1(gradient(*p_fo,start_point)); - for(size_t i=0;i