#ifndef LSNEWTON_GG_HPP #define LSNEWTON_GG_HPP #include #include #include #include #include #include using std::cout; using std::cerr; using std::endl; namespace opt_utilities { template void lsnewton_cg_f(func_obj& foo,pT& x0,const rT& threshold) { for(int k=0;;++k) { cerr<::epsilon()); rT djBkdj=0; pT Bkdj; resize(Bkdj,get_size(x0)); pT x1,x2; typename element_type_trait::element_type h=1; for(int i=0;i class lsnewton_cg :public opt_method { public: typedef pT array1d_type; typedef rT T; private: func_obj* p_fo; optimizer* p_optimizer; //typedef blitz::Array array2d_type; private: array1d_type start_point; array1d_type end_point; private: rT threshold; private: rT func(const pT& x) { assert(p_fo!=0); return p_fo->eval(x); } public: lsnewton_cg() :threshold(1e-4) {} virtual ~lsnewton_cg() { }; lsnewton_cg(const lsnewton_cg& rhs) :p_fo(rhs.p_fo),p_optimizer(rhs.p_optimizer), start_point(rhs.start_point), end_point(rhs.end_point), threshold(rhs.threshold) { } lsnewton_cg& operator=(const lsnewton_cg& rhs) { threshold=rhs.threshold; p_fo=rhs.p_fo; p_optimizer=rhs.p_optimizer; opt_eq(start_point,rhs.start_point); opt_eq(end_point,rhs.end_point); } opt_method* do_clone()const { return new lsnewton_cg(*this); } void do_set_start_point(const array1d_type& p) { start_point.resize(get_size(p)); opt_eq(start_point,p); } array1d_type do_get_start_point()const { return start_point; } void do_set_precision(rT t) { threshold=t; } rT do_get_precision()const { return threshold; } void do_set_optimizer(optimizer& o) { p_optimizer=&o; p_fo=p_optimizer->ptr_func_obj(); } pT do_optimize() { lsnewton_cg_f(*p_fo,start_point,threshold); opt_eq(end_point,start_point); return end_point; } }; } #endif //EOF