CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
model_3pt.cpp

This example shows how to model the reduced three-point correlation function

// ========================================================================================
// Example code: how to measure the connected and reduced three-point correlation functions
// ========================================================================================
int main () {
try {
// --------------------------------------------------------------
// ---------------- set the cosmological parameters ------------
// --------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------
// ---------------- read the input catalogue (with observed coordinates: R.A., Dec, redshift) ----------------
// -----------------------------------------------------------------------------------------------------------
std::string file_catalogue = "../input/cat.dat";
// --------------------------------------------------------------------------------------
// ---------------- construct the random catalogue (with cubic geometry) ----------------
// --------------------------------------------------------------------------------------
const double N_R = 2.; // random/data ratio
// -------------------------------------------------------------------------------
// ---------------- measure the three-point correlation functions ----------------
// -------------------------------------------------------------------------------
// binning parameters
const double side_s = 20.; // 1st side of the triangle
const double side_u = 2.; // ratio between the 1st and 2nd sides of the triangle (u*s)
const double perc = 0.0225; // tolerance
const int nbins = 5; // number of bins
// output data
const std::string dir_output = "../output/";
const std::string dir_triplets = dir_output;
const std::string dir_2pt = dir_output;
const std::string file_output = "3pt.dat";
// measure the connected and reduced three-point correlation functions and write the output
ThreeP->measure(dir_triplets, dir_2pt);
ThreeP->write(dir_output, file_output, 1);
// --------------------------------------------------------------
// ---------------- read Q dark matter (DEMNUNI) ----------------
// --------------------------------------------------------------
const std::string file_Q = "../input/zeta_lin_DM_z1.1_u2s5.00.dat";
std::ifstream fin(file_Q); cbl::checkIO(fin, file_Q);
double theta, Q, err;
std::vector<double> Q_DM;
while (fin >> theta >> Q >> err)
Q_DM.emplace_back(Q);
fin.clear(); fin.close();
// ------------------------------------------------------------------------------------------------------------
// ----------------- model the reduced three-point correlation function to estimate b1 and b2 -----------------
// ------------------------------------------------------------------------------------------------------------
// object used for modelling
// set the data used to construct the model
model_threep.set_data_model(Q_DM);
// set the priors and the model
const cbl::statistics::PriorDistribution b1_prior {cbl::glob::DistributionType::_Uniform_, 0., 5., 43142}; // flat prior for b1
const cbl::statistics::PriorDistribution b2_prior {cbl::glob::DistributionType::_Uniform_, -3., 3., 4342}; // flat prior for b2
model_threep.set_model_nonlinear_localbias(b1_prior, b2_prior);
// ----------------------------------------------------------------------
// ------------- run chains and write output chain and model ------------
// ----------------------------------------------------------------------
// minimum and maxium scales used in the fit
const double theta_min = 0.;
const double theta_max = 1.;
model_threep.set_fit_range(theta_min, theta_max);
const int chain_size = 1000; // the size the chain lenght
const int nwalkers = 10; // the number of parallel walkers in the MCMC chains
const int seed = 666; // the base seed for initialization
// set the likelihood type
// run the MCMC method to sample the posterior
model_threep.sample_posterior(chain_size, nwalkers, seed);
const int burn_in = 100; // discard the first 100 chain steps
const int thin = 10; // take 1 step every 10
// write the results on screen
model_threep.show_results(burn_in, thin, seed);
// store the results in file
model_threep.write_results(dir_output, "model_Q", burn_in, thin);
}
catch(cbl::glob::Exception &exc) { std::cerr << exc.what() << std::endl; exit(1); }
return 0;
}
int main()
main function to create the logo of the CosmoBolognaLib
Definition: Logo.cpp:41
The class Modelling_ThreePointCorrelation_comoving_reduced.
The class Catalogue.
Definition: Catalogue.h:654
The class Cosmology.
Definition: Cosmology.h:277
The class Exception.
Definition: Exception.h:111
const char * what() const noexcept override
the error description
Definition: Exception.h:203
static std::shared_ptr< ThreePointCorrelation > Create(const ThreePType type, const catalogue::Catalogue data, const catalogue::Catalogue random, const triplets::TripletType tripletType, const double side_s, const double side_u, const double perc_increase, const int nbins)
static factory used to construct three-point correlation functions of any type
void write_results(const std::string output_dir, const std::string root_file, const int start=0, const int thin=1, const int nbins=50, const bool fits=false, const bool compute_mode=false, const int ns=-1)
write the results of the MCMC sampling to file
Definition: Modelling.cpp:281
void show_results(const int start=0, const int thin=1, const int nbins=50, const bool show_mode=false, const int ns=-1)
show the results of the MCMC sampling on screen
Definition: Modelling.cpp:269
void set_likelihood(const statistics::LikelihoodType likelihood_type, const std::vector< size_t > x_index={0, 2}, const int w_index=-1, const double prec=1.e-10, const int Nres=-1)
set the likelihood function
Definition: Modelling.cpp:124
void sample_posterior(const int chain_size, const int nwalkers, const int seed=666, const double aa=2, const bool parallel=true)
sample the posterior, initializing the chains by drawing from the prior distributions
Definition: Modelling.cpp:187
void set_fit_range(const double xmin, const double xmax)
set the fit range
Definition: Modelling1D.cpp:46
void set_model_nonlinear_localbias(const statistics::PriorDistribution bias1_prior={}, const statistics::PriorDistribution bias2_prior={})
set the parameters used to model the reduced three-point correlation function in comoving coordinates
void set_data_model(const std::vector< double > Q_DM)
set the data model for the three-point correlation function
The class PriorDistribution.
@ _createRandom_box_
random catalogue with cubic geometry (or parallelepiped) in comoving coordinates
@ _Planck15_
Planck collaboration 2015, paper XIII: Table 4, TT,TE,EE+lowP+lensing.
@ _Uniform_
Identity function.
@ _comoving_reduced_
the reduced three-point correlation function in comoving coordinates
@ _Gaussian_Error_
Gaussian likelihood error.
@ _comoving_theta_
1D triplet in comoving coordinates and angular bins
@ _observed_
observed coordinates (R.A., Dec, redshift)
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened
Definition: Kernel.cpp:160