diff options
author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2008-12-15 07:26:12 +0000 |
---|---|---|
committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2008-12-15 07:26:12 +0000 |
commit | 1f4a944064bc42284c33e6b755353d191cf288e8 (patch) | |
tree | c8cb2253dea5f395e0f867aa6976433bd3eb00de /models/pow_model.hpp | |
download | opt-utilities-1f4a944064bc42284c33e6b755353d191cf288e8.tar.bz2 |
git-svn-id: file:///home/svn/opt_utilities@1 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'models/pow_model.hpp')
-rw-r--r-- | models/pow_model.hpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/models/pow_model.hpp b/models/pow_model.hpp new file mode 100644 index 0000000..79baa4b --- /dev/null +++ b/models/pow_model.hpp @@ -0,0 +1,120 @@ +#ifndef POW_MODEL_H_ +#define POW_MODEL_H_ +#include <core/fitter.hpp> +#include <cmath> + +namespace opt_utilities +{ + template <typename Ty,typename Tx,typename Tp,typename Tstr> + class pow_model + :public model<Ty,Tx,Tp,Tstr> + { + private: + model<Ty,Tx,Tp,Tstr>* do_clone()const + { + return new pow_model<Ty,Tx,Tp,Tstr>(*this); + } + private: + pow_model() + { + } + + private: + model<Ty,Tx,Tp,Tstr>* pm1; + typename value_type_trait<Tp>::value_type idx; + + public: + pow_model(const model<Ty,Tx,Tp,Tstr>& m1, + const typename value_type_trait<Tp>::value_type& index) + :pm1(m1.clone()),idx(index) + { + int np1=m1.get_num_params(); + + for(int i=0;i<np1;++i) + { + param_info<Tp,Tstr> p(m1.get_param_info(i)); + //param_info<Tp,Tstr> p1(p.get_name(),p.get_default_value()); + this->push_param_info(p); + } + } + + pow_model(const pow_model& rhs) + :pm1(NULL),idx(0) + { + int np1(0); + if(rhs.pm1) + { + pm1=rhs.pm1->clone(); + np1=rhs.pm1->get_num_params(); + for(int i=0;i<np1;++i) + { + param_info<Tp,Tstr> p(rhs.pm1->get_param_info(i)); + param_info<Tp,Tstr> p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p1); + } + } + idx=rhs.idx; + } + + pow_model& operator=(const pow_model& rhs) + { + if(this==&rhs) + { + return *this; + } + if(!pm1) + { + //delete pm1; + pm1->destroy(); + } + + int np1(0); + if(rhs.pm1) + { + pm1=rhs.pm1->clone(); + np1=rhs.pm1->get_num_params(); + for(int i=0;i<np1;++i) + { + param_info<Tp,Tstr> p(rhs.pm1->get_param_info(i)); + // param_info<Tp,Tstr> p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p); + } + } + idx=rhs.idx; + + return *this; + } + + ~pow_model() + { + if(!pm1) + { + //delete pm1; + pm1->destroy(); + } + } + + public: + Ty do_eval(const Tx& x,const Tp& param) + { + if(!pm1) + { + throw opt_exception("incomplete model!"); + } + + return std::pow(pm1->eval(x,param),idx); + } + }; + + template <typename Ty,typename Tx,typename Tp,typename Tstr> + pow_model<Ty,Tx,Tp,Tstr> pow(const model<Ty,Tx,Tp,Tstr>& m1, + const typename value_type_trait<Tp>::value_type& idx) + { + return pow_model<Ty,Tx,Tp,Tstr>(m1,idx); + } +}; + + + +#endif +//EOF |