From 1f4a944064bc42284c33e6b755353d191cf288e8 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Mon, 15 Dec 2008 07:26:12 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@1 ed2142bd-67ad-457f-ba7c-d818d4011675 --- models/add_model.hpp | 169 +++++++++++++++++++++++++++++++++++++++++++ models/beta1d.hpp | 49 +++++++++++++ models/beta2d.hpp | 60 ++++++++++++++++ models/beta2d2.hpp | 73 +++++++++++++++++++ models/bl1d.hpp | 56 +++++++++++++++ models/bpl1d.hpp | 56 +++++++++++++++ models/bremss.hpp | 44 ++++++++++++ models/constant.hpp | 42 +++++++++++ models/dbeta1d.hpp | 62 ++++++++++++++++ models/dbeta2d.hpp | 92 ++++++++++++++++++++++++ models/dbeta2d2.hpp | 100 ++++++++++++++++++++++++++ models/dbeta2d3.hpp | 91 ++++++++++++++++++++++++ models/dl_model.hpp | 178 ++++++++++++++++++++++++++++++++++++++++++++++ models/dlmodel_template.c | 36 ++++++++++ models/func_model.hpp | 57 +++++++++++++++ models/gauss1d.hpp | 47 ++++++++++++ models/lin1d.hpp | 42 +++++++++++ models/models.cc | 176 +++++++++++++++++++++++++++++++++++++++++++++ models/models.hpp | 36 ++++++++++ models/mul_model.hpp | 171 ++++++++++++++++++++++++++++++++++++++++++++ models/nbeta1d.hpp | 49 +++++++++++++ models/nfw1d.hpp | 45 ++++++++++++ models/pl1d.hpp | 43 +++++++++++ models/poly1d.hpp | 67 +++++++++++++++++ models/pow_model.hpp | 120 +++++++++++++++++++++++++++++++ models/strmodel1d.cc | 82 +++++++++++++++++++++ models/strmodel1d.hpp | 39 ++++++++++ models/vecn.hpp | 62 ++++++++++++++++ 28 files changed, 2144 insertions(+) create mode 100644 models/add_model.hpp create mode 100644 models/beta1d.hpp create mode 100644 models/beta2d.hpp create mode 100644 models/beta2d2.hpp create mode 100644 models/bl1d.hpp create mode 100644 models/bpl1d.hpp create mode 100644 models/bremss.hpp create mode 100644 models/constant.hpp create mode 100644 models/dbeta1d.hpp create mode 100644 models/dbeta2d.hpp create mode 100644 models/dbeta2d2.hpp create mode 100644 models/dbeta2d3.hpp create mode 100644 models/dl_model.hpp create mode 100644 models/dlmodel_template.c create mode 100644 models/func_model.hpp create mode 100644 models/gauss1d.hpp create mode 100644 models/lin1d.hpp create mode 100644 models/models.cc create mode 100644 models/models.hpp create mode 100644 models/mul_model.hpp create mode 100644 models/nbeta1d.hpp create mode 100644 models/nfw1d.hpp create mode 100644 models/pl1d.hpp create mode 100644 models/poly1d.hpp create mode 100644 models/pow_model.hpp create mode 100644 models/strmodel1d.cc create mode 100644 models/strmodel1d.hpp create mode 100644 models/vecn.hpp (limited to 'models') diff --git a/models/add_model.hpp b/models/add_model.hpp new file mode 100644 index 0000000..ffac9dc --- /dev/null +++ b/models/add_model.hpp @@ -0,0 +1,169 @@ +#ifndef ADD_MODEL_H_ +#define ADD_MODEL_H_ +#include +#include + +namespace opt_utilities +{ + template + class add_model + :public model + { + private: + model* do_clone()const + { + return new add_model(*this); + } + private: + add_model() + { + } + + private: + model* pm1; + model* pm2; + + public: + add_model(const model& m1, + const model& m2) + :pm1(m1.clone()),pm2(m2.clone()) + { + int np1=m1.get_num_params(); + int np2=m2.get_num_params(); + for(int i=0;i p(m1.get_param_info(i)); + param_info p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p1); + } + for(int i=0;i p(m2.get_param_info(i)); + param_info p2(p.get_name()+"2",p.get_default_value()); + this->push_param_info(p2); + } + } + + add_model(const add_model& rhs) + :pm1(NULL),pm2(NULL) + { + int np1(0),np2(0); + if(rhs.pm1) + { + pm1=rhs.pm1->clone(); + np1=rhs.pm1->get_num_params(); + for(int i=0;i p(rhs.pm1->get_param_info(i)); + param_info p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p1); + } + } + if(rhs.pm2) + { + pm2=rhs.pm2->clone(); + np2=rhs.pm2->get_num_params(); + for(int i=0;i p(rhs.pm2->get_param_info(i)); + param_info p2(p.get_name()+"2",p.get_default_value()); + this->push_param_info(p2); + } + } + } + + add_model& operator=(const add_model& rhs) + { + if(this==&rhs) + { + return *this; + } + if(!pm1) + { + //delete pm1; + pm1->destroy(); + } + if(!pm2) + { + //delete pm2; + pm2->destroy(); + } + int np1(0),np2(0); + if(rhs.pm1) + { + pm1=rhs.pm1->clone(); + np1=rhs.pm1->get_num_params(); + for(int i=0;i p(rhs.pm1->get_param_info(i)); + param_info p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p1); + } + } + if(rhs.pm2) + { + pm2=rhs.pm2->clone(); + np2=rhs.pm2->get_num_params(); + for(int i=0;i p(rhs.pm2->get_param_info(i)); + param_info p2(p.get_name()+"2",p.get_default_value()); + this->push_param_info(p2); + } + } + return *this; + } + + ~add_model() + { + if(!pm1) + { + //delete pm1; + pm1->destroy(); + } + if(!pm2) + { + //delete pm2; + pm2->destroy(); + } + } + + public: + Ty do_eval(const Tx& x,const Tp& param) + { + if(!pm1) + { + throw opt_exception("incomplete model!"); + } + if(!pm2) + { + throw opt_exception("incomplete model!"); + } + Tp p1(pm1->get_num_params()); + Tp p2(pm2->get_num_params()); + int i=0; + int j=0; + for(i=0;iget_num_params();++i,++j) + { + set_element(p1,i,get_element(param,j)); + } + for(i=0;iget_num_params();++i,++j) + { + set_element(p2,i,get_element(param,j)); + } + return pm1->eval(x,p1)+pm2->eval(x,p2); + } + }; + + template + add_model operator+(const model& m1, + const model& m2) + { + return add_model(m1,m2); + } +}; + + + +#endif +//EOF diff --git a/models/beta1d.hpp b/models/beta1d.hpp new file mode 100644 index 0000000..e18aa34 --- /dev/null +++ b/models/beta1d.hpp @@ -0,0 +1,49 @@ +#ifndef BETA_MODEL_H_ +#define BETA_MODEL_H_ +#include +#include +#include + +namespace opt_utilities +{ + template + class beta1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new beta1d(*this); + } + public: + beta1d() + { + this->push_param_info(param_info >("S0",1)); + this->push_param_info(param_info >("rc",10)); + this->push_param_info(param_info >("beta",2./3.)); + this->push_param_info(param_info >("bkg",0)); + } + + + T do_eval(const T& x,const std::vector& param) + { + T S0=get_element(param,0); + T r_c=get_element(param,1); + T beta=get_element(param,2); + T bkg=get_element(param,3); + + return bkg+S0*pow(1+(x*x)/(r_c*r_c),-3*beta+static_cast(.5)); + } + + std::string do_to_string()const + { + return "Beta model\n" + "S=S0*(1+(r/rc)^2)^(-3*beta+0.5)\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/beta2d.hpp b/models/beta2d.hpp new file mode 100644 index 0000000..abb6da1 --- /dev/null +++ b/models/beta2d.hpp @@ -0,0 +1,60 @@ +#ifndef BETA_MODEL2d_H_ +#define BETA_MODEL2d_H_ +#include +#include +#include +#include "vecn.hpp" + + +namespace opt_utilities +{ + + template + class beta2d + :public model,std::vector,std::string> + { + private: + model,std::vector >* do_clone()const + { + return new beta2d(*this); + } + public: + beta2d() + { + this->push_param_info(param_info >("S0",1)); + this->push_param_info(param_info >("rc1",100)); + this->push_param_info(param_info >("rc2",100)); + this->push_param_info(param_info >("rho",0)); + this->push_param_info(param_info >("x0",100)); + this->push_param_info(param_info >("y0",100)); + this->push_param_info(param_info >("beta",2./3.)); + this->push_param_info(param_info >("bkg",0)); + } + + + T do_eval(const vecn& xy,const std::vector& param) + { + T S0=get_element(param,0); + T rc1=get_element(param,1); + T rc2=get_element(param,2); + T rho=get_element(param,3); + T x0=get_element(param,4); + T y0=get_element(param,5); + T beta=get_element(param,6); + T bkg=get_element(param,7); + T x=xy[0]; + T y=xy[1]; + + T r=(x-x0)*(x-x0)/(rc1*rc1)+(y-y0)*(y-y0)/(rc2*rc2) + -2*rho*(x-x0)*(y-y0)/(rc1*rc2); + r=r<0?0:r; + + return bkg+S0*pow(1+r,-3*beta+static_cast(.5)); + } + }; +}; + + + +#endif +//EOF diff --git a/models/beta2d2.hpp b/models/beta2d2.hpp new file mode 100644 index 0000000..bb473a3 --- /dev/null +++ b/models/beta2d2.hpp @@ -0,0 +1,73 @@ +#ifndef BETA_MODEL2d2_H_ +#define BETA_MODEL2d2_H_ +#include +#include +#include +#include "vecn.hpp" + + +namespace opt_utilities +{ + + template + class beta2d2 + :public model,std::vector,std::string> + { + private: + model,std::vector >* do_clone()const + { + return new beta2d2(*this); + } + public: + beta2d2() + { + this->push_param_info(param_info >("r0",20)); + this->push_param_info(param_info >("x0",100)); + this->push_param_info(param_info >("y0",100)); + this->push_param_info(param_info >("epsilon",0)); + this->push_param_info(param_info >("theta",100)); + this->push_param_info(param_info >("ampl",3)); + this->push_param_info(param_info >("beta",2./3.)); + this->push_param_info(param_info >("bkg",0)); + } + + + T do_eval(const vecn& xy,const std::vector& param) + { + T x=xy[0]; + T y=xy[1]; + + T r0=get_element(param,0); + T x0=get_element(param,1); + T y0=get_element(param,2); + T epsilon=get_element(param,3); + T theta=get_element(param,4); + T ampl=get_element(param,5); + T beta=get_element(param,6); + T bkg=get_element(param,7); + + T x_new=(x-x0)*cos(theta)+(y-y0)*sin(theta); + T y_new=(y-y0)*cos(theta)-(x-x0)*sin(theta); + + //T _epsilon=sin(epsilon)-0.00001; + + T _epsilon=epsilon; + + // T r=sqrt(x_new*x_new*(1-_epsilon)*(1-_epsilon) + // + y_new*y_new); + + //r/=(1-_epsilon); + T r_r=x_new*x_new/exp(_epsilon)+y_new*y_new/exp(-_epsilon); + + + return bkg+ampl*pow(1+r_r/r0/r0,-3*beta+static_cast(.5)); + } + + + }; +}; + + + +#endif +//EOF diff --git a/models/bl1d.hpp b/models/bl1d.hpp new file mode 100644 index 0000000..bd0ce7d --- /dev/null +++ b/models/bl1d.hpp @@ -0,0 +1,56 @@ +#ifndef BROKEN_LINE_MODEL_H_ +#define BROKEN_LINE_MODEL_H_ +#include +#include + +namespace opt_utilities +{ + template + class bl1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new bl1d(*this); + } + public: + bl1d() + { + this->push_param_info(param_info >("break point y value",1)); + this->push_param_info(param_info >("break point x value",1)); + this->push_param_info(param_info >("slop 1",1)); + this->push_param_info(param_info >("slop 2",1)); + } + + public: + T do_eval(const T& x,const std::vector& param) + { + T x_b=get_element(param,0); + T f_b=get_element(param,1); + T k1=get_element(param,2); + T k2=get_element(param,3); + if(x +#include + +namespace opt_utilities +{ + template + class bpl1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new bpl1d(*this); + } + public: + bpl1d() + { + this->push_param_info(param_info >("bpx",1)); + this->push_param_info(param_info >("bpy",1)); + this->push_param_info(param_info >("gamma1",1)); + this->push_param_info(param_info >("gamma2",1)); + } + + T do_eval(const T& x,const std::vector& param) + { + T x_b=get_element(param,0); + T f_b=get_element(param,1); + T gamma1=get_element(param,2); + T gamma2=get_element(param,3); + if(x +#include + +namespace opt_utilities +{ + template + class bremss + :public model,std::string> + { + private: + model >* do_clone()const + { + return new bremss(*this); + } + public: + bremss() + { + this->push_param_info(param_info >("norm",1)); + this->push_param_info(param_info >("kT",1)); + } + + T do_eval(const T& x,const std::vector& param) + { + T norm=get_element(param,0); + T kT=get_element(param,1); + + return norm*sqrt(kT)*exp(-x/kT); + } + + private: + std::string do_to_string()const + { + return "Simplified bremss model\n" + "flux=norm*kT^0.5*e^{-E/kT}\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/constant.hpp b/models/constant.hpp new file mode 100644 index 0000000..8d06279 --- /dev/null +++ b/models/constant.hpp @@ -0,0 +1,42 @@ +#ifndef CONSTANT_MODEL_H_ +#define CONSTANT_MODEL_H_ +#include +#include + +namespace opt_utilities +{ + template + class constant + :public model,std::string> + { + private: + model >* do_clone()const + { + return new constant(*this); + } + public: + constant() + { + this->push_param_info(param_info >("c",1)); + } + + public: + T do_eval(const T& x,const std::vector& param) + { + //return x*param[0]+param[1]; + return get_element(param,0); + } + + private: + std::string do_to_string()const + { + return "Constant\n" + "y=C\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/dbeta1d.hpp b/models/dbeta1d.hpp new file mode 100644 index 0000000..71a1f52 --- /dev/null +++ b/models/dbeta1d.hpp @@ -0,0 +1,62 @@ +#ifndef DBETA_MODEL_H_ +#define DBETA_MODEL_H_ +#include +#include +#include +namespace opt_utilities +{ + template + class dbeta1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new dbeta1d(*this); + } + public: + dbeta1d() + { + this->push_param_info(param_info >("S01",1)); + this->push_param_info(param_info >("rc1",30)); + this->push_param_info(param_info >("beta1",.6)); + + this->push_param_info(param_info >("S02",.5)); + this->push_param_info(param_info >("rc2",20)); + this->push_param_info(param_info >("beta2",.4)); + + + this->push_param_info(param_info >("bkg",0)); + } + + + T do_eval(const T& x,const std::vector& param) + { + T S01=get_element(param,0); + T r_c1=get_element(param,1); + T beta1=get_element(param,2); + + T S02=get_element(param,3); + T r_c2=get_element(param,4); + T beta2=get_element(param,5); + + + T bkg=get_element(param,6); + + return bkg+S01*pow(1+(x*x)/(r_c1*r_c1),-3*beta1+static_cast(.5)) + +S02*pow(1+(x*x)/(r_c2*r_c2),-3*beta2+static_cast(.5)); + } + + private: + std::string do_to_string()const + { + return "double 1d beta model\n" + "S=beta(S01,beta1,rc1)+beta(S02,beta2,rc2)\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/dbeta2d.hpp b/models/dbeta2d.hpp new file mode 100644 index 0000000..6811270 --- /dev/null +++ b/models/dbeta2d.hpp @@ -0,0 +1,92 @@ +#ifndef DBETA_MODEL2d_H_ +#define DBETA_MODEL2d_H_ +#include +#include +#include +#include "vecn.hpp" + +namespace opt_utilities +{ + + template + class dbeta2d + :public model,std::vector,std::string> + { + private: + model,std::vector >* do_clone()const + { + return new dbeta2d(*this); + } + + + + public: + dbeta2d() + { + push_param_info(param_info >("S01",1)); + push_param_info(param_info >("rc11",50)); + push_param_info(param_info >("rc21",50)); + push_param_info(param_info >("rho1",0)); + push_param_info(param_info >("x01",200)); + push_param_info(param_info >("y01",200)); + push_param_info(param_info >("beta1",2./3.)); + + push_param_info(param_info >("S02",1)); + push_param_info(param_info >("rc12",60)); + push_param_info(param_info >("rc22",60)); + push_param_info(param_info >("rho2",0)); + push_param_info(param_info >("x02",200)); + push_param_info(param_info >("y02",200)); + push_param_info(param_info >("beta2",2./2.5)); + push_param_info(param_info >("bkg",0)); + } + + T do_eval(const vecn& xy,const std::vector& param) + { + T S01=get_element(param,0); + T rc11=get_element(param,1); + T rc21=get_element(param,2); + T rho1=get_element(param,3); + T x01=get_element(param,4); + T y01=get_element(param,5); + T beta1=get_element(param,6); + T S02=get_element(param,7); + T rc12=get_element(param,8); + T rc22=get_element(param,9); + T rho2=get_element(param,10); + T x02=get_element(param,11); + T y02=get_element(param,12); + T beta2=get_element(param,13); + T bkg=get_element(param,14); + + + T x=xy[0]; + T y=xy[1]; + + rho1=rho1>1?1:rho1; + rho1=rho1<-1?-1:rho1; + rho2=rho2>1?1:rho2; + rho2=rho2<-1?-1:rho2; + + T r1=(x-x01)*(x-x01)/(rc11*rc11)+(y-y01)*(y-y01)/(rc21*rc21) + -2*rho1*(x-x01)*(y-y01)/(rc11*rc21); + + T r2=(x-x02)*(x-x02)/(rc12*rc12)+(y-y02)*(y-y02)/(rc22*rc22) + -2*rho2*(x-x02)*(y-y02)/(rc12*rc22); + // r1=r1<0?0:r1; + //r2=r2<0?0:r2; + assert(r1>=0); + assert(r2>=0); + + + return bkg+S01*pow(1+r1,-3*beta1+static_cast(.5))+ + S02*pow(1+r2,-3*beta2+static_cast(.5)); + } + }; +}; + + + +#endif +//EOF + diff --git a/models/dbeta2d2.hpp b/models/dbeta2d2.hpp new file mode 100644 index 0000000..d968dbc --- /dev/null +++ b/models/dbeta2d2.hpp @@ -0,0 +1,100 @@ +#ifndef DDBETA_OOOMODEL2d2_H_ +#define DDBETA_OOOMODEL2d2_H_ +#include +#include +#include +#include "vecn.hpp" + + +namespace opt_utilities +{ + + template + class dbeta2d2 + :public model,std::vector,std::string> + { + private: + model,std::vector >* do_clone()const + { + return new dbeta2d2(*this); + } + public: + dbeta2d2() + { + this->push_param_info(param_info >("ampl1",1));//0 + this->push_param_info(param_info >("r01",1));//1 + this->push_param_info(param_info >("x01",100));//2 + this->push_param_info(param_info >("y01",100));//3 + this->push_param_info(param_info >("theta1",0));//4 + this->push_param_info(param_info >("beta1",2./3.));//5 + this->push_param_info(param_info >("epsilon1",0));//6 + + + this->push_param_info(param_info >("ampl2",1));//7 + this->push_param_info(param_info >("r02",1));//8 + this->push_param_info(param_info >("x02",100));//9 + this->push_param_info(param_info >("y02",100));//10 + this->push_param_info(param_info >("theta2",0));//11 + this->push_param_info(param_info >("beta2",2./4.));//12 + this->push_param_info(param_info >("epsilon2",0));//13 + + this->push_param_info(param_info >("bkg",0));//14 + } + + + T do_eval(const vecn& xy,const std::vector& param) + { + T x=xy[0]; + T y=xy[1]; + + T ampl1=get_element(param,0); + T r01=get_element(param,1); + T x01=get_element(param,2); + T y01=get_element(param,3); + + T theta1=get_element(param,4); + + T beta1=get_element(param,5); + T epsilon1=get_element(param,6); + + T ampl2=get_element(param,7); + T r02=get_element(param,8); + T x02=get_element(param,9); + T y02=get_element(param,10); + + T theta2=get_element(param,11); + + T beta2=get_element(param,12); + + T epsilon2=get_element(param,13); + T bkg=get_element(param,14); + + T x_new1=(x-x01)*cos(theta1)+(y-y01)*sin(theta1); + T y_new1=(y-y01)*cos(theta1)-(x-x01)*sin(theta1); + + //T r1=sqrt(x_new1*x_new1*(1-epsilon1)*(1-epsilon1) + // + y_new1*y_new1); + //r1/=(1-epsilon1); + + T r1_r1=x_new1*x_new1/exp(epsilon1/30)+y_new1*y_new1/exp(-epsilon1/30); + + T x_new2=(x-x02)*cos(theta2)+(y-y02)*sin(theta2); + T y_new2=(y-y02)*cos(theta2)-(x-x02)*sin(theta2); + + T r2_r2=x_new2*x_new2/exp(epsilon2/30)+y_new2*y_new2/exp(-epsilon2/30); + // T r2=sqrt(x_new2*x_new2*(1-epsilon2)*(1-epsilon2) + // + y_new2*y_new2); + //r2/=(1-epsilon2); + + + + return bkg+ampl1*pow(1+(r1_r1/r01/r01),-3*beta1+static_cast(.5)) + +ampl2*pow(1+(r2_r2/r02/r02),-3*beta2+static_cast(.5)); + } + }; +}; + + + +#endif +//EOF diff --git a/models/dbeta2d3.hpp b/models/dbeta2d3.hpp new file mode 100644 index 0000000..e2edb78 --- /dev/null +++ b/models/dbeta2d3.hpp @@ -0,0 +1,91 @@ +#ifndef DDBETA3_MODEL2d2_H_ +#define DDBETA3_MODEL2d2_H_ +#include +#include +#include +#include "vecn.hpp" + + +namespace opt_utilities +{ + + template + class dbeta2d3 + :public model,std::vector,std::string> + { + private: + model,std::vector >* do_clone()const + { + return new dbeta2d3(*this); + } + public: + dbeta2d3() + { + + this->push_param_info(param_info >("x0",256));//1 + this->push_param_info(param_info >("y0",256));//2 + this->push_param_info(param_info >("epsilon",0));//3 + this->push_param_info(param_info >("theta",0));//4 + + this->push_param_info(param_info >("ampl1",1));//5 + this->push_param_info(param_info >("beta1",0.6));//6 + this->push_param_info(param_info >("r01",30));//7 + + this->push_param_info(param_info >("ampl2",.5));//8 + this->push_param_info(param_info >("beta2",.4));//9 + this->push_param_info(param_info >("r02",20));//10 + + this->push_param_info(param_info >("bkg",0));//11 + + + } + + + T do_eval(const vecn& xy,const std::vector& param) + { + T x=xy[0]; + T y=xy[1]; + + T x0=get_element(param,0); + T y0=get_element(param,1); + T epsilon=get_element(param,2); + T theta=get_element(param,3); + + T ampl1=(get_element(param,4)); + T beta1=(get_element(param,5)); + T r01=(get_element(param,6)); + + T ampl2=(get_element(param,7)); + T beta2=(get_element(param,8)); + T r02=(get_element(param,9)); + + T bkg=get_element(param,10); + + T x_new1=(x-x0)*cos(theta)+(y-y0)*sin(theta); + T y_new1=(y-y0)*cos(theta)-(x-x0)*sin(theta); + + + T r1_r1=x_new1*x_new1/exp(epsilon/30)+y_new1*y_new1/exp(-epsilon/30); + //T r1=sqrt(x_new1*x_new1*(1-epsilon)*(1-epsilon)+y_new1*y_new1)/(1-epsilon); + + T x_new2=(x-x0)*cos(theta)+(y-y0)*sin(theta); + T y_new2=(y-y0)*cos(theta)-(x-x0)*sin(theta); + + T r2_r2=x_new2*x_new2/exp(epsilon/30)+y_new2*y_new2/exp(-epsilon/30); + //T r2=sqrt(x_new2*x_new2*(1-epsilon)*(1-epsilon)+y_new2*y_new2)/(1-epsilon); + + + + return bkg+ampl1*pow(1+(r1_r1/r01/r01),-3*beta1+static_cast(.5)) + +ampl2*pow(1+(r2_r2/r02/r02),-3*beta2+static_cast(.5)); + + //return bkg+pow(1+r1*r1/r01/r01,-3*beta1+static_cast(.5))+ + //pow(1+r2*r2/r02/r02,-3*beta2+static_cast(.5)); + } + }; +}; + + + +#endif +//EOF diff --git a/models/dl_model.hpp b/models/dl_model.hpp new file mode 100644 index 0000000..2fcf227 --- /dev/null +++ b/models/dl_model.hpp @@ -0,0 +1,178 @@ +#ifdef __linux__ + +#ifndef DL_MODEL_H_ +#define DL_MODEL_H_ +#include +#include +#include +#include +#include +#include + +namespace opt_utilities +{ + template + class dl_model + :public model,std::string> + { + private: + T (*calc_model)(T x,const T* p); + int nparams; + mutable void* handle; + private: + model >* do_clone()const + { + dl_model* result=new dl_model(*this); + this->handle=NULL; + return result; + } + + // public: + public: + dl_model() + :handle(NULL) + {} + + + public: + dl_model(const char* file_name) + :handle(NULL) + { + + handle=dlopen(file_name,RTLD_LAZY); + + if(!handle) + { + throw opt_exception("faild loading object"); + } + + calc_model=(T (*)(T,const T*))dlsym(handle,"calc_model"); + + if(!calc_model) + { + throw opt_exception("symble undefined"); + } + + const char* (*get_param_name)(int) + =(const char* (*)(int))dlsym(handle,"get_param_name"); + + if(!get_param_name) + { + throw opt_exception("symble undefined"); + } + + int (*get_num_params)() + =(int (*)())dlsym(handle,"get_num_params"); + + if(!get_num_params) + { + throw opt_exception("symble undefined"); + if(!get_num_params) + { + throw opt_exception("symble undefined"); + } } + + T (*get_default_value)(int) + =(T (*)(int))dlsym(handle,"get_default_value"); + + if(!get_default_value) + { + throw opt_exception("symble undefined"); + } + + nparams=get_num_params(); + + for(int i=0;i!=nparams;++i) + { + this->push_param_info(param_info >(get_param_name(i), + get_default_value(i))); + } + } + + ~dl_model() + { + if(handle) + { + dlclose(handle); + } + } + + void bind(const char* file_name) + { + if(handle) + { + dlclose(handle); + } + this->clear_param_info(); + handle=dlopen(file_name,RTLD_LAZY); + + if(!handle) + { + throw opt_exception("faild loading object"); + } + + calc_model=(T (*)(T,const T*))dlsym(handle,"calc_model"); + + if(!calc_model) + { + throw opt_exception("symble undefined"); + } + + const char* (*get_param_name)(int) + =(const char* (*)(int))dlsym(handle,"get_param_name"); + + if(!get_param_name) + { + throw opt_exception("symble undefined"); + } + + + int (*get_num_params)() + =(int (*)())dlsym(handle,"get_num_params"); + + if(!get_num_params) + { + throw opt_exception("symble undefined"); + } + + + T (*get_default_value)(int) + =(T (*)(int))dlsym(handle,"get_default_value"); + + + if(!get_default_value) + { + throw opt_exception("symble undefined"); + } + + + nparams=get_num_params(); + for(int i=0;i!=nparams;++i) + { + this->push_param_info(param_info >(get_param_name(i), + get_default_value(i))); + } + } + + T do_eval(const T& x,const std::vector& param) + { + if(handle==NULL) + { + throw opt_exception("dl object unloaded"); + } + return calc_model(x,&get_element(param,0)); + } + + std::string do_to_string()const + { + return "Dynamical load model\n" + "Should be loaded from an shared object file\n"; + } + }; +}; + + + +#endif +#endif +//EOF diff --git a/models/dlmodel_template.c b/models/dlmodel_template.c new file mode 100644 index 0000000..fd7aadb --- /dev/null +++ b/models/dlmodel_template.c @@ -0,0 +1,36 @@ +#include + +char p1name[2]="k"; +char p2name[2]="b"; + +int main(int argc,char* argv[]) +{} + + +int get_num_params() +{ + return 2; +} + +const char* get_param_name(int n) +{ + if(n==0) + { + return p1name; + } + return p2name; +} + +double get_default_value(int n) +{ + if(n==0) + return 1; + return 0; +} + +double calc_model(double x,double p[]) +{ + return p[0]*x+p[1]; +} + + diff --git a/models/func_model.hpp b/models/func_model.hpp new file mode 100644 index 0000000..4eda8d5 --- /dev/null +++ b/models/func_model.hpp @@ -0,0 +1,57 @@ +#ifndef FUNC_MODEL_H_ +#define FUNC_MODEL_H_ +#include +#include +#include +#include +#include +namespace opt_utilities +{ + template + class func_model + :public model,std::string> + { + private: + T (*func)(T x,const T* const& p); + int nparams; + private: + model >* do_clone()const + { + return new func_model(*this); + } + + // public: + private: + func_model() + {} + + + public: + func_model(T (*_func)(T x,const T* const& p),int n) + :func(_func),nparams(n) + { + for(int i=0;i!=n;++i) + { + std::ostringstream oss; + oss<push_param_info(param_info >(oss.str(),0)); + } + } + + + T do_eval(const T& x,const std::vector& param) + { + return func(x,&get_element(param,0)); + } + private: + std::string do_to_string()const + { + return "Wrapper for necked C function\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/gauss1d.hpp b/models/gauss1d.hpp new file mode 100644 index 0000000..958cec9 --- /dev/null +++ b/models/gauss1d.hpp @@ -0,0 +1,47 @@ +#ifndef GAUSS_MODEL_H_ +#define GAUSS_MODEL_H_ +#include +#include + +namespace opt_utilities +{ + template + class gauss1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new gauss1d(*this); + } + public: + gauss1d() + { + this->push_param_info(param_info >("N",1)); + this->push_param_info(param_info >("x0",0)); + this->push_param_info(param_info >("sigma",1)); + } + + public: + T do_eval(const T& x,const std::vector& param) + { + T N=get_element(param,0); + T x0=get_element(param,1); + T sigma=get_element(param,2); + T y=(x-x0)/sigma; + return N*exp(-y*y); + } + + private: + std::string do_to_string()const + { + return "Gaussian model\n" + "y=N*exp(-(x-x0)^2/sigma^2\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/lin1d.hpp b/models/lin1d.hpp new file mode 100644 index 0000000..b0ddd31 --- /dev/null +++ b/models/lin1d.hpp @@ -0,0 +1,42 @@ +#ifndef LINEAR_MODEL_H_ +#define LINEAR_MODEL_H_ +#include +#include + +namespace opt_utilities +{ + template + class lin1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new lin1d(*this); + } + public: + lin1d() + { + this->push_param_info(param_info >("k",1)); + this->push_param_info(param_info >("b",0)); + } + + public: + T do_eval(const T& x,const std::vector& param) + { + return x*get_element(param,0)+get_element(param,1); + } + + private: + std::string do_to_string()const + { + return "linear model\n" + "y=k*x+b\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/models.cc b/models/models.cc new file mode 100644 index 0000000..7481b88 --- /dev/null +++ b/models/models.cc @@ -0,0 +1,176 @@ +#include "models.hpp" +#include +#include "gauss1d.hpp" +#include "bl1d.hpp" +#include "nfw1d.hpp" +#include "bpl1d.hpp" +#include "beta1d.hpp" +#include "nbeta1d.hpp" +#include "dbeta1d.hpp" +#include "lin1d.hpp" +#include "pl1d.hpp" +#include "poly1d.hpp" +#include "bremss.hpp" +#include "beta2d2.hpp" +#include "beta2d.hpp" +#include "dbeta2d2.hpp" +#include "dbeta2d3.hpp" +#include "dbeta2d.hpp" +#include "dl_model.hpp" +#include +using namespace std; + + +namespace opt_utilities +{ + strmodel1d strm1d; + std::map,std::string>* > model_map; + std::map,std::vector,std::string>* > model2d_map; + std::list get_model_name_list() + { + std::list result; + for(std::map,std::string>* >::iterator i=model_map.begin(); + i!=model_map.end();++i) + { + result.push_back(i->first); + } + return result; + } + + std::list get_model2d_name_list() + { + std::list result; + for(map,std::vector,std::string>* > ::iterator i=model2d_map.begin(); + i!=model2d_map.end();++i) + { + result.push_back(i->first); + } + return result; + } + +model,std::string>& get_1dmodel_by_name(const char* name) + { + std::map,std::string >* >::iterator iter; + iter=model_map.find(name); + if(iter==model_map.end()||iter->second==0) + { + throw opt_exception("model does not exist"); + } + return *(iter->second); + } + + strmodel1d& get_strm1d() + { + return strm1d; + } + +model,std::vector,std::string>& get_2dmodel_by_name(const char* name) + { + std::map,std::vector,std::string>* >::iterator iter; + iter=model2d_map.find(name); + if(iter==model2d_map.end()||iter->second==0) + { + throw opt_exception("model does not exist"); + } + return *(iter->second); + } + + int get_n_1dmodels() + { + return model_map.size(); + } + + int get_n_2dmodels() + { + return model2d_map.size(); + } + + class model_map_keeper_class + { + private: + void init_model_map() + { + + //#define DECL_POLY(n) model_map["poly1d##n"]=new poly1d; + + + model_map["lin1d"]=new lin1d; + model_map["pl1d"]=new pl1d; + model_map["bl1d"]=new bl1d; + model_map["bpl1d"]=new bpl1d; + model_map["beta1d"]=new beta1d; + model_map["bremss"]=new bremss; + model_map["nbeta1d"]=new nbeta1d; + model_map["2beta1d"]=new dbeta1d; + model_map["nfw"]=new nfw1d; + model_map["gauss1d"]=new gauss1d; + model_map["poly1d2"]=new poly1d; + model_map["poly1d3"]=new poly1d; + model_map["poly1d4"]=new poly1d; + model_map["poly1d5"]=new poly1d; +#ifdef __linux__ + model_map["dlmodel"]=new dl_model; +#endif + //DECL_POLY(7) + } + + void release_model_map() + { + for(std::map,std::string>* >::iterator i=model_map.begin(); + i!=model_map.end();++i) + { + delete i->second; + } + } + public: + model_map_keeper_class() + { + init_model_map(); + std::cerr<<"1d models Initialized"<; + model2d_map["beta2d2"]=new beta2d2; + model2d_map["dbeta2d"]=new dbeta2d; + model2d_map["dbeta2d2"]=new dbeta2d2; + model2d_map["dbeta2d3"]=new dbeta2d3; + } + + void release_model_map() + { + for(std::map,std::vector,std::string>* >::iterator i=model2d_map.begin(); + i!=model2d_map.end();++i) + { + delete i->second; + } + } + public: + model2d_map_keeper_class() + { + init_model_map(); + std::cerr<<"2d models Initialized"< +#include +#include +#include +#include "vecn.hpp" +#include "strmodel1d.hpp" + + + +namespace opt_utilities +{ + extern std::map,std::string>* > model_map; + extern std::map,std::vector,std::string >* > model2d_map; + + extern strmodel1d strm1d; + extern std::list get_model_name_list(); + extern int get_n_1dmodels(); + // extern void init_model_map(); + // extern void release_model_map(); + + extern std::list get_model2d_name_list(); + // extern void init_model2d_map(); + // extern void release_model2d_map(); + extern int get_n_2dmodels(); + + extern model,std::string >& get_1dmodel_by_name(const char*); + extern model,std::vector,std::string >& get_2dmodel_by_name(const char*); + + extern strmodel1d& get_strm1d(); +} + + +#endif diff --git a/models/mul_model.hpp b/models/mul_model.hpp new file mode 100644 index 0000000..0e64c1b --- /dev/null +++ b/models/mul_model.hpp @@ -0,0 +1,171 @@ +#ifndef MUL_MODEL_H_ +#define MUL_MODEL_H_ +#include +#include + +namespace opt_utilities +{ + template + class mul_model + :public model + { + private: + model* do_clone()const + { + return new mul_model(*this); + } + private: + mul_model() + { + } + + private: + model* pm1; + model* pm2; + + public: + mul_model(const model& m1, + const model& m2) + :pm1(m1.clone()),pm2(m2.clone()) + { + int np1=m1.get_num_params(); + int np2=m2.get_num_params(); + for(int i=0;i p(m1.get_param_info(i)); + param_info p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p1); + } + for(int i=0;i p(m2.get_param_info(i)); + param_info p2(p.get_name()+"2",p.get_default_value()); + this->push_param_info(p2); + } + } + + mul_model(const mul_model& rhs) + :pm1(NULL),pm2(NULL) + { + int np1(0),np2(0); + if(rhs.pm1) + { + pm1=rhs.pm1->clone(); + np1=rhs.pm1->get_num_params(); + for(int i=0;i p(rhs.pm1->get_param_info(i)); + param_info p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p1); + } + } + if(rhs.pm2) + { + pm2=rhs.pm2->clone(); + np2=rhs.pm2->get_num_params(); + for(int i=0;i p(rhs.pm2->get_param_info(i)); + param_info p2(p.get_name()+"2",p.get_default_value()); + this->push_param_info(p2); + } + } + } + + mul_model& operator=(const mul_model& rhs) + { + if(this==&rhs) + { + return *this; + } + if(!pm1) + { + //delete pm1; + pm1->destroy(); + } + if(!pm2) + { + //delete pm2; + pm2->destroy(); + } + int np1(0),np2(0); + if(rhs.pm1) + { + pm1=rhs.pm1->clone(); + np1=rhs.pm1->get_num_params(); + for(int i=0;i p(rhs.pm1->get_param_info(i)); + param_info p1(p.get_name()+"1",p.get_default_value()); + this->push_param_info(p1); + } + } + if(rhs.pm2) + { + pm2=rhs.pm2->clone(); + np2=rhs.pm2->get_num_params(); + for(int i=0;i p(rhs.pm2->get_param_info(i)); + param_info p2(p.get_name()+"2",p.get_default_value()); + this->push_param_info(p2); + } + } + return *this; + } + + + ~mul_model() + { + if(!pm1) + { + //delete pm1; + pm1->destroy(); + } + if(!pm2) + { + //delete pm2; + pm2->destroy(); + } + } + + public: + Ty do_eval(const Tx& x,const Tp& param) + { + if(!pm1) + { + throw opt_exception("incomplete model!"); + } + if(!pm2) + { + throw opt_exception("incomplete model!"); + } + Tp p1(pm1->get_num_params()); + Tp p2(pm2->get_num_params()); + int i=0; + int j=0; + for(i=0;iget_num_params();++i,++j) + { + set_element(p1,i,get_element(param,j)); + } + for(i=0;iget_num_params();++i,++j) + { + set_element(p2,i,get_element(param,j)); + } + return pm1->eval(x,p1)*pm2->eval(x,p2); + } + }; + + template + mul_model operator*(const model& m1, + const model& m2) + { + return mul_model(m1,m2); + } + +}; + + + +#endif +//EOF diff --git a/models/nbeta1d.hpp b/models/nbeta1d.hpp new file mode 100644 index 0000000..3806fe9 --- /dev/null +++ b/models/nbeta1d.hpp @@ -0,0 +1,49 @@ +#ifndef NBETA_MODEL_H_ +#define NBETA_MODEL_H_ +#include +#include +#include +namespace opt_utilities +{ + template + class nbeta1d + :public model ,std::string> + { + private: + model >* do_clone()const + { + return new nbeta1d(*this); + } + public: + nbeta1d() + { + this->push_param_info(param_info >("S0",1)); + this->push_param_info(param_info >("rc",10)); + this->push_param_info(param_info >("beta",2./3.)); + this->push_param_info(param_info >("bkg",0)); + } + + + T do_eval(const T& x,const std::vector& param) + { + T S0=get_element(param,0); + T r_c=get_element(param,1); + T beta=get_element(param,2); + T bkg=get_element(param,3); + + return bkg+S0*pow(1+(x*x)/(r_c*r_c),-3./2.*beta); + } + + private: + std::string do_to_string()const + { + return "density beta model\n" + "n=n0*(1+(r/rc)^2)^(-1.5*beta)\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/nfw1d.hpp b/models/nfw1d.hpp new file mode 100644 index 0000000..9c2dfd4 --- /dev/null +++ b/models/nfw1d.hpp @@ -0,0 +1,45 @@ +#ifndef NFW_MODEL_H_ +#define NFW_MODEL_H_ +#include +#include +#include +namespace opt_utilities +{ + template + class nfw1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new nfw1d(*this); + } + public: + nfw1d() + { + this->push_param_info(param_info >("rho0",1.)); + this->push_param_info(param_info >("rs",1.)); + } + + + T do_eval(const T& x,const std::vector& param) + { + T rho0=get_element(param,0); + T rs=get_element(param,1); + + + return rho0/(x/rs*(1+x/rs)*(1+x/rs)); + } + + std::string do_to_string()const + { + return "NFW model\n" + "y=rho0/(r/rs*(1+r/rs)^2\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/pl1d.hpp b/models/pl1d.hpp new file mode 100644 index 0000000..50b4c50 --- /dev/null +++ b/models/pl1d.hpp @@ -0,0 +1,43 @@ +#ifndef POWER_LAW_MODEL_H_ +#define POWER_LAW_MODEL_H_ +#include +#include + +namespace opt_utilities +{ + template + class pl1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new pl1d(*this); + } + public: + pl1d() + { + this->push_param_info(param_info >("Ampl",1)); + this->push_param_info(param_info >("gamma",1)); + } + + T do_eval(const T& x,const std::vector& param) + { + T A=get_element(param,0); + T gamma=get_element(param,1); + return A*pow(x,gamma); + } + + private: + std::string do_to_string()const + { + return "Simple power law model\n" + "y=A*x^gamma\n"; + } + }; +}; + + + +#endif +//EOF diff --git a/models/poly1d.hpp b/models/poly1d.hpp new file mode 100644 index 0000000..a8c994b --- /dev/null +++ b/models/poly1d.hpp @@ -0,0 +1,67 @@ +#ifndef POLY_MODEL_H_ +#define POLY_MODEL_H_ +#include +#include +#include +#include + +namespace opt_utilities +{ + template + class poly1d + :public model,std::string> + { + private: + model >* do_clone()const + { + return new poly1d(*this); + } + public: + poly1d() + { + assert(n>=0); + for(int i=0;i<=n;++i) + { + std::ostringstream ostr; + ostr<<"a"<push_param_info(param_info >(ostr.str().c_str(),1)); + } + + } + + public: + T do_eval(const T& x,const std::vector& param) + { + // return x*get_element(param,0)+get_element(param,1); + T result(0); + for(int i=0;i<=n;++i) + { + T xn(1); + for(int j=0;j +#include + +namespace opt_utilities +{ + template + class pow_model + :public model + { + private: + model* do_clone()const + { + return new pow_model(*this); + } + private: + pow_model() + { + } + + private: + model* pm1; + typename value_type_trait::value_type idx; + + public: + pow_model(const model& m1, + const typename value_type_trait::value_type& index) + :pm1(m1.clone()),idx(index) + { + int np1=m1.get_num_params(); + + for(int i=0;i p(m1.get_param_info(i)); + //param_info 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 p(rhs.pm1->get_param_info(i)); + param_info 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 p(rhs.pm1->get_param_info(i)); + // param_info 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 + pow_model pow(const model& m1, + const typename value_type_trait::value_type& idx) + { + return pow_model(m1,idx); + } +}; + + + +#endif +//EOF diff --git a/models/strmodel1d.cc b/models/strmodel1d.cc new file mode 100644 index 0000000..df3cd40 --- /dev/null +++ b/models/strmodel1d.cc @@ -0,0 +1,82 @@ +#include "strmodel1d.hpp" + +using namespace mu; +using namespace std; +using namespace opt_utilities; + +strmodel1d* strmodel1d::do_clone()const +{ + return new strmodel1d(*this); +} + +strmodel1d::strmodel1d() +{ + set_buildin_fun(); +} + +strmodel1d::strmodel1d(const strmodel1d& rhs) + :expr(rhs.expr), + par_names(rhs.par_names), + var_name(rhs.var_name), + par_vec(rhs.par_vec) +{ + set_buildin_fun(); + set_expr(expr,par_names,var_name); +} + +strmodel1d& strmodel1d::operator=(const strmodel1d& rhs) +{ + set_buildin_fun(); + expr=rhs.expr; + par_names=rhs.par_names; + var_name=rhs.var_name; + par_vec=rhs.par_vec; + set_expr(expr,par_names,var_name); + return *this; +} + +void strmodel1d::set_buildin_fun() +{ + mp.DefineFun("sin",sin); + mp.DefineFun("cos",cos); + mp.DefineFun("exp",exp); + mp.DefineFun("tan",tan); + mp.DefineFun("log",log); +} + + +void strmodel1d::set_expr(const string& _expr, + const std::vector& _par_names, + const std::string& _var_name) +{ + expr=_expr; + par_names=_par_names; + var_name=_var_name; + this->clear_param_info(); + par_vec.resize(par_names.size()); + mp.ClearVar(); + // mp.ClearFun(); + for(int i=0;ipush_param_info(param_info >(par_names[i],0)); + } + mp.DefineVar(var_name.c_str(),&x); + mp.SetExpr(expr.c_str()); +} + + +double strmodel1d::do_eval(const double& _x,const vector& p) +{ + for(int i=0;i +#include +#include +#include +#include +#include +#include + +class strmodel1d + :public opt_utilities::model,std::string> +{ +private: + mu::Parser mp; + strmodel1d* do_clone()const; + std::vector par_vec; + std::vector par_names; + std::string expr; + std::string var_name; + double x; + void set_buildin_fun(); +public: + double do_eval(const double& x,const std::vector& p); + strmodel1d(); + strmodel1d(const strmodel1d& rhs); + strmodel1d& operator=(const strmodel1d& rhs); + + + void set_expr(const std::string& _expr, + const std::vector& _par_names, + const std::string& _var_name); + +}; + + + +#endif +//EOF diff --git a/models/vecn.hpp b/models/vecn.hpp new file mode 100644 index 0000000..cac1436 --- /dev/null +++ b/models/vecn.hpp @@ -0,0 +1,62 @@ +#ifndef VECN_HPP +#define VECN_HPP +#include +namespace opt_utilities +{ + template + class vecn + { + public: + T data[n]; + public: + T& operator[](int i) + { + return data[i]; + } + + const T& operator[](int i)const + { + return data[i]; + } + + vecn() + { + for(int i=0;i + std::istream& operator>>(std::istream& is,vecn& p) + { + for(int i=0;i>p[i]; + // std::cout< + std::ostream& operator<<(std::ostream& os,const vecn& p) + { + os<<'['; + for(int i=0;i