/* Perform a double-beta density model fitting to the surface brightness data Author: Junhua Gu Last modified: 2011.01.01 This code is distributed with no warrant */ //#define HAVE_X_ERROR #include #include #include #include #include #include #include "statistics/chisq.hpp" #include "statistics/leastsq.hpp" #include "statistics/robust_chisq.hpp" #include #include #include using namespace std; using namespace opt_utilities; //double s=5.63136645E20; const double kpc=3.086E21;//kpc in cm const double Mpc=kpc*1000; const double pi=4*atan(1); double std_norm_rand() { double u=0; double v=0; while(u<=0||v<=0) { u=rand()/(double)RAND_MAX; rand(); v=rand()/(double)RAND_MAX; } double x=std::sqrt(-log(u))*cos(2*pi*v); return x; } double shuffle_data(double xc,double xl,double xu) { if(std_norm_rand()>0) { double result=xc-std::abs(std_norm_rand()*xl); return result; } else { double result= xc+std::abs(std_norm_rand()*xu); return result; } } int main(int argc,char* argv[]) { if(argc!=3) { cerr<<"Usage:"< "< ds; ofstream ofs_result("m-t_result.qdp"); ofs_result<<"read terr 1 2"<>T>>Tl>>Tu>>M>>Ml>>Mu; if(!ifs_data.good()) { break; } line+=" "; istringstream iss(line); if(line[0]=='#') { if(!is_first_nonono) { ofs_result<<"no no no"<>T>>Tl>>Tu>>M>>Ml>>Mu; //std::cerr< data, skipped"< d(x,y,std::abs(yl),std::abs(yu), std::abs(xl),std::abs(xu)); ds.add_data(d); } double M=sxx*s1-sx*sx; double Ma=sxy*s1-sy*sx; double Mb=sxx*sy-sx*sxy; double k0=Ma/M; double b0=Mb/M; ofs_result<<"no no no"<,double,std::string> fit; fit.set_opt_method(powell_method >()); fit.set_statistic(chisq,double,std::string>()); //fit.set_statistic(robust_chisq,double,std::string>()); //fit.set_statistic(leastsq,double,std::string>()); fit.set_model(lin1d()); fit.load_data(ds); cerr<<"k0="< p=fit.get_all_params(); std::cout<<"chi="< ds1; for(size_t i=0;i(new_x,new_y, ds.get_data(i).get_y_lower_err(), ds.get_data(i).get_y_upper_err(), ds.get_data(i).get_y_lower_err(), ds.get_data(i).get_y_upper_err())); } fit.load_data(ds1); fit.fit(); double k=fit.get_param_value("k"); double b=fit.get_param_value("b"); double A=exp(b); double g=k; mean_A+=A; mean_A2+=A*A; mean_g+=g; mean_g2+=g*g; } std::cerr<