46 m_function = [
this,
function](vector<vector<double>> xx, shared_ptr<void> inputs, vector<double> ¶meters)
48 return function(xx[0], xx[1], inputs, parameters);
56 void cbl::statistics::Model2D::stats_from_chains (
const vector<double> xx,
const vector<double> yy, vector<vector<double>> &median_model, vector<vector<double>> &low_model, vector<vector<double>> &up_model,
const int start,
const int thin)
58 Model::stats_from_chains({xx, yy}, median_model, low_model, up_model, start, thin);
65 void cbl::statistics::Model2D::write (
const string output_dir,
const string output_file,
const vector<double> xx,
const vector<double> yy,
const vector<double> parameters)
67 vector<double> pp = parameters;
68 vector<vector<double>> model = this->operator()(xx, yy, pp);
70 const string mkdir =
"mkdir -p "+output_dir;
71 if (system(mkdir.c_str())) {}
73 const string file = output_dir+output_file;
75 ofstream fout(file.c_str());
checkIO(fout, file);
77 fout <<
"### [1] x # [2] y # [3] model(x,y) ###" << endl;
79 for (
size_t i=0; i<xx.size(); i++)
80 for (
size_t j=0; j<yy.size(); j++)
81 fout << setprecision(5) << setw(10) << right << xx[i] <<
" "
82 << setprecision(5) << setw(10) << right << yy[j] <<
" "
83 << setprecision(5) << setw(10) << right << model[i][j] << endl;
85 fout.clear(); fout.close();
coutCBL <<
"I wrote the file: " << file << endl << endl;
94 vector<double> bf = m_parameters->bestfit_value();
95 write(output_dir, output_file, xx, yy, bf);
104 vector<vector<double>> median_model, low_model, up_model;
105 stats_from_chains(xx, yy, median_model, low_model, up_model, start, thin);
107 const string mkdir =
"mkdir -p "+output_dir;
108 if (system(mkdir.c_str())) {}
110 const string file = output_dir+output_file;
112 ofstream fout(file.c_str());
checkIO(fout, file);
114 fout <<
"### [1] x # [2] y # [3] median model(x,y) # [4] 16% percentile model(x,y) # [5] 84% percentile ###" << endl;
116 for (
size_t i=0; i<xx.size(); i++)
117 for (
size_t j=0; j<yy.size(); j++)
118 fout << setprecision(5) << setw(10) << right << xx[i] <<
" "
119 << setprecision(5) << setw(10) << right << yy[j] <<
" "
120 << setprecision(5) << setw(10) << right << median_model[i][j] <<
" "
121 << setprecision(5) << setw(10) << right << low_model[i][j] <<
" "
122 << setprecision(5) << setw(10) << right << up_model[i][j] << endl;
124 fout.clear(); fout.close();
coutCBL <<
"I wrote the file: " << file << endl;
#define coutCBL
CBL print message.
void write_from_chains(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const std::vector< double > yy, const int start=0, const int thin=1) override
write the model at xx, yy computing 16th, 50th and 84th percentiles from the chains.
void stats_from_chains(const std::vector< double > xx, const std::vector< double > yy, std::vector< std::vector< double >> &median_model, std::vector< std::vector< double >> &low_model, std::vector< std::vector< double >> &up_model, const int start=0, const int thin=1) override
compute the median and percentiles of the model from MCMC chains
void set_function(const model_function_2D function)
set the model function
void write_at_bestfit(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const std::vector< double > yy) override
write the model at xx, yy with best-fit parameters obtained from likelihood maximization
void write(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const std::vector< double > yy, const std::vector< double > parameters) override
write the model at xx, yy for given parameters
std::function< std::vector< std::vector< double > >std::vector< double >, std::vector< double >, std::shared_ptr< void >, std::vector< double > &)> model_function_2D
2D function: the inputs are the values at which the function is computed, a pointer to a set of data ...
The global namespace of the CosmoBolognaLib
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened