From 4ea7a05ea9a7352602f1f48a860fd81c36e8bc04 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 20 Feb 2017 12:26:17 +0800 Subject: Rename mass_profile to src; Add install & uninstall to Makefile --- src/fit_wang2012_model.cpp | 195 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/fit_wang2012_model.cpp (limited to 'src/fit_wang2012_model.cpp') diff --git a/src/fit_wang2012_model.cpp b/src/fit_wang2012_model.cpp new file mode 100644 index 0000000..f15a2b1 --- /dev/null +++ b/src/fit_wang2012_model.cpp @@ -0,0 +1,195 @@ +/* + Fitting Jy Wang's temperature profile model + Author: Jingying Wang + Last modification 20120819 + +*/ + +#include "wang2012_model.hpp" +#include +#include +#include +#include "chisq.hpp" +#include +#include +#include +#include +#include +#include + +using namespace opt_utilities; +using namespace std; +const double cm=1; +const double kpc=3.08568e+21*cm; + +int main(int argc,char* argv[]) +{ + if(argc<2) + { + cerr<<"Usage:"< [param file] [cm per pixel]"<=4) + { + cm_per_pixel=atof(argv[3]); + } + + //define the fitter + fitter,double,std::string> fit; + //define the data set + default_data_set ds; + //open the data file + ifstream ifs(argv[1]); + double min_r=1e9; + //cout<<"read serr 2"<0) + { + ofs_fit_result<<"la x radius (kpc)"<>r>>re>>t>>te; + if(!ifs.good()) + { + break; + } + min_r=min(r,min_r); + data d(r,t,te,te,re,re); + //std::cerr<0) + { + ofs_fit_result< >()); + //use chi^2 statistic + chisq,double,std::string> chisq_object; + chisq_object.set_limit(); + fit.set_statistic(chisq_object); + //fit.set_statistic(chisq,double,std::string>()); + fit.set_model(wang2012_model()); + + if(argc>=3&&std::string(argv[2])!="NONE") + { + std::vector freeze_list; + ifstream ifs_param(argv[2]); + assert(ifs_param.is_open()); + for(;;) + { + string pname; + double pvalue; + double lower,upper; + char param_status; + ifs_param>>pname>>pvalue>>lower>>upper>>param_status; + if(!ifs_param.good()) + { + break; + } + if(param_status=='F') + { + freeze_list.push_back(pname); + } + if(pvalue<=lower||pvalue>=upper) + { + cerr<<"Invalid initial value, central value not enclosed by the lower and upper boundaries, adjust automatically"<,std::string> fp(freeze_list[0]); + fit.set_param_modifier(fp); + for(size_t i=1;i,std::string>&>(fit.get_param_modifier())+=freeze_param,std::string>(freeze_list[i]); + } + } + } + + for(int i=0;i<100;++i) + { + fit.fit(); + } + vector p=fit.fit(); +#if 0 + ofstream output_param; + if(argc>=3&&std::string(argv[2])!="NONE") + { + output_param.open(argv[2]); + } + else + { + output_param.open("para0.txt"); + } +#endif + //output parameters + for(size_t i=0;i=3&&std::string(argv[2])!="NONE") +#if 0 + { + output_param<0) + { + ofs_fit_result<