From 20c287b91345e348cc00b8a0da53ff967be0cac9 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Sat, 14 May 2011 16:24:05 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@197 ed2142bd-67ad-457f-ba7c-d818d4011675 --- distributions/component.hpp | 9 +- distributions/kmm_component.hpp | 205 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 distributions/kmm_component.hpp (limited to 'distributions') diff --git a/distributions/component.hpp b/distributions/component.hpp index d761bf8..ee13adb 100644 --- a/distributions/component.hpp +++ b/distributions/component.hpp @@ -46,7 +46,14 @@ namespace opt_utilities { for(int i=0;i0) + { + add_component(*rhs.components[i],rhs.get_param_info(rhs.weight_num[i-1]).get_value()); + } + else + { + add_component(*rhs.components[i]); + } } for(int i=0;i +#include +#include +#include +#include + + + +namespace opt_utilities +{ + template + class kmm_component + :public model,optvec,optvec,std::string> + { + private: + std::vector,optvec,optvec,std::string>*> components; + std::vector weight_num; + private: + kmm_component* do_clone()const + { + return new kmm_component(*this); + } + + const char* do_get_type_name()const + { + return "Multi-distribution"; + } + public: + kmm_component() + { + //this->push_param_info(param_info >("x0",0)); + //this->push_param_info(param_info >("sigma",1)); + } + + kmm_component(const kmm_component& rhs) + { + for(int i=0;i=1) + { + add_component(*rhs.components[i],rhs.get_param_info(rhs.weight_num[i-1]).get_value()); + } + else + { + add_component(*rhs.components[i]); + } + } + for(int i=0;idestroy(); + } + components.clear(); + for(int i=0;idestroy(); + } + } + + + public: + void add_component(const model,optvec,optvec,std::string>& m,const T& w=0) + { + int morder=components.size(); + components.push_back(m.clone()); + std::ostringstream oss; + oss<1) + { + param_info,std::string> p1(std::string("_w")+smorder,w); + this->push_param_info(p1); + weight_num.push_back(this->get_num_params()-1); + } + int np=m.get_num_params(); + for(int i=0;i,std::string> p(m.get_param_info(i)); + param_info,std::string> p1(p.get_name()+smorder,p.get_value()); + this->push_param_info(p1); + } + } + + optvec convert_unit_sph(const optvec& p) + { + int ndim=p.size()+1; + optvec result(ndim); + result[0]=1; + for(int i=0;i do_eval(const optvec& x,const optvec& param) + { + T result(0); + optvec weight_angle; + for(int i=0;i weight(convert_unit_sph(weight_angle)); + + int pnum=0; + for(int i=0;i p(components[i]->get_num_params()); + for(int j=0;jeval(x,p)[0]*weight[i]); + ++pnum; + } + optvec result1(1); + result1[0]=result;; + return result1; + } + + optvec eval_unsumed(const optvec& x,const optvec& param) + { + optvec weight_angle; + for(int i=0;i weight(convert_unit_sph(weight_angle)); + optvec result(components.size()); + int pnum=0; + for(int i=0;i p(components[i]->get_num_params()); + for(int j=0;jeval(x,p)[0]*weight[i]); + ++pnum; + } + + return result; + } + + + + private: + std::string do_get_information()const + { + return ""; + } + }; +} + + + +#endif +//EOF -- cgit v1.2.2