From f945de88af78d98ba63b7ac91df5d659406a4cd3 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Tue, 18 Aug 2009 13:58:35 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@43 ed2142bd-67ad-457f-ba7c-d818d4011675 --- methods/aga/aga.hpp | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 methods/aga/aga.hpp diff --git a/methods/aga/aga.hpp b/methods/aga/aga.hpp new file mode 100644 index 0000000..f5edff3 --- /dev/null +++ b/methods/aga/aga.hpp @@ -0,0 +1,249 @@ +#ifndef AGA_METHOD +#define AGA_METHOD +#include +//#include +#include +#include +#include +#include +#include +#include +#include +/* + * +*/ +#include +using std::cout; +using std::endl; + +namespace opt_utilities +{ + + template + struct vp_pair + { + rT v; + pT p; + }; + + template + class vp_comp + { + public: + bool operator()(const vp_pair& x1, + const vp_pair& x2) + { + return x1.v + class aga_method + :public opt_method + { + public: + typedef pT array1d_type; + private: + int n1,n2,n0; + func_obj* p_fo; + optimizer* p_optimizer; + rT threshold; + pT lower_bound; + pT upper_bound; + + typename element_type_trait::element_type decay_factor; + pT reproduction_box; + std::vector > samples; + std::vector buffer; + + private: + typename element_type_trait::element_type uni_rand + (typename element_type_trait::element_type x1, + typename element_type_trait::element_type x2) + { + return rand()/(double)RAND_MAX*(x2-x1)+x1; + } + + private: + rT func(const pT& x) + { + assert(p_fo!=0); + return p_fo->eval(x); + } + + public: + aga_method(int _n1,int _n2) + :threshold(1e-4),p_fo(0),p_optimizer(0), + n1(_n1),n2(_n2),samples(n1*n2+n1),n0(n1*n2+n1), + decay_factor(.999) + { + } + + aga_method() + :threshold(1e-4),p_fo(0),p_optimizer(0), + n1(50),n2(20),samples(n1*n2+n1),n0(n1*n2+n1), + decay_factor(.999) + { + } + + + virtual ~aga_method() + { + }; + + aga_method(const aga_method& rhs) + :threshold(rhs.threshold), + p_fo(rhs.p_fo),p_optimizer(rhs.p_optimizer), + n1(rhs.n1),n2(rhs.n2), + samples(rhs.samples),n0(rhs.n0) + { + } + + aga_method& operator=(const aga_method& rhs) + { + threshold=rhs.threshold; + p_fo=rhs.p_fo; + p_optimizer=rhs.p_optimizer; + samples=rhs.samples; + n1=rhs.n1; + n2=rhs.n2; + n0=rhs.n0; + } + + void set_decay_factor(typename element_type_trait::element_type _decay_factor) + { + decay_factor=_decay_factor; + } + + + opt_method* do_clone()const + { + return new aga_method(*this); + } + + void do_set_start_point(const array1d_type& p) + { + for(int i=0;i& o) + { + p_optimizer=&o; + p_fo=p_optimizer->ptr_func_obj(); + } + + bool iter() + { + rT sum2=0; + rT sum=0; + for(int i=0;i >()); + if(sum2/samples.size()-pow(sum/samples.size(),2)get_element(upper_bound,j)) + { + set_element(p,j,get_element(upper_bound,j)); + } + if(get_element(p,j)p; + } + + }; + +} + + +#endif +//EOF -- cgit v1.2.2