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

This example shows how to model redshift-space distortions in the monopole of the two-point correlation function

// ===============================================================================================
// Example code: how to model the monopole of the two-point correlation function in redshift space
// ===============================================================================================
int main () {
try {
// --------------------------------------------------------------------------------
// ---------------- use default cosmological parameters and set sigma8 ------------
// --------------------------------------------------------------------------------
cosmology.set_sigma8(0.8);
// -----------------------------------------------------------------------------------------------------------
// ---------------- read the input catalogue (with observed coordinates: R.A., Dec, redshift) ----------------
// -----------------------------------------------------------------------------------------------------------
const std::string file_catalogue = "../input/cat.dat";
// ----------------------------------------------------------------
// ---------------- construct the random catalogue ----------------
// ----------------------------------------------------------------
const double N_R = 1.; // random/data ratio
// --------------------------------------------------------------------------------------------
// ---------------- measure the monopole of the two-point correlation function ----------------
// --------------------------------------------------------------------------------------------
// binning parameters and output data
const double rMin = 10.; // minimum separation
const double rMax = 30.; // maximum separation
const int nbins = 10; // number of bins
const double shift = 0.5; // spatial shift used to set the bin centre
const std::string dir = "../output/";
const std::string file = "xi.dat";
// measure the monopole of the two-point correlation function and estimate Poissonian errors
TwoP->write(dir, file);
// ----------------------------------------------------------------------------------------------------------------------------
// ----------------- model the monopole two-point correlation function and estimate the f*sigma8 and b*sigma8 -----------------
// ----------------------- (f*sigma8 and b*sigma8 will be degenerate, if the prior is uniform for both) -----------------------
// ----------------------------------------------------------------------------------------------------------------------------
// object used for modelling
// mean redshift of the sample
const double redshift = 1.;
// set the data used to construct the model
model_twop.set_data_model(cosmology, redshift);
// set the priors and the model
const cbl::statistics::PriorDistribution fsigma8_prior {cbl::glob::DistributionType::_Uniform_, 0., 2.}; // flat prior for the f*sigma8
const cbl::statistics::PriorDistribution bsigma8_prior {cbl::glob::DistributionType::_Uniform_, 0., 2.}; // flat prior for the b*sigma8
model_twop.set_model_Kaiser(fsigma8_prior, bsigma8_prior);
// ----------------------------------------------------------------------
// ------------- run chains and write output chain and model ------------
// ----------------------------------------------------------------------
// minimum and maxium scales used in the fit
const double xmin = 10.;
const double xmax = 40.;
model_twop.set_fit_range(xmin, xmax);
// set the likelihood type
// maximise the posterior
model_twop.maximize_posterior({1., 1.}, 10000, 1.e-5);
// run the MCMC method to sample the posterior
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
model_twop.sample_posterior(chain_size, nwalkers, seed);
// write the results on screen
const int burn_in = 100; // discard the first 100 chain steps
const int thin = 10; // take 1 step every 10
model_twop.show_results(burn_in, thin);
// store the results in file
model_twop.write_results(dir, "model_RSD", burn_in, thin);
// store the best-fit model
model_twop.write_model_from_chains(dir, "bestfit_model.dat", cbl::logarithmic_bin_vector(100, 0.1, 100.), 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_TwoPointCorrelation1D_monopole.
The class Catalogue.
Definition: Catalogue.h:654
The class Cosmology.
Definition: Cosmology.h:277
void set_sigma8(const double sigma8=-1.)
set the value of σ8
Definition: Cosmology.h:1547
The class Exception.
Definition: Exception.h:111
const char * what() const noexcept override
the error description
Definition: Exception.h:203
static std::shared_ptr< TwoPointCorrelation > Create(const TwoPType type, const catalogue::Catalogue data, const catalogue::Catalogue random, const BinType binType, const double Min, const double Max, const int nbins, const double shift, const CoordinateUnits angularUnits=CoordinateUnits::_radians_, std::function< double(double)> angularWeight=nullptr, const bool compute_extra_info=false, const double random_dilution_fraction=1.)
static factory used to construct two-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
virtual void write_model_from_chains(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const int start=0, const int thin=1)
write the model at xx computing 16th, 50th and 84th percentiles from the chains
Definition: Modelling1D.cpp:80
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 maximize_posterior(const std::vector< double > start, const unsigned int max_iter=10000, const double tol=1.e-6, const double epsilon=1.e-3, const int seed=666)
function that maximizes the posterior, finds the best-fit parameters and stores them in the model
Definition: Modelling.cpp:177
void set_model_Kaiser(const statistics::PriorDistribution fsigma8_prior={}, const statistics::PriorDistribution bsigma8_prior={})
set the parameters to model the monopole of the two-point correlation function in redshift space
void set_data_model(const cbl::cosmology::Cosmology cosmology, const double redshift, const std::string method_Pk="CAMB", const double sigmaNL_perp=0., const double sigmaNL_par=0., const bool NL=true, const double bias=1., const double pimax=40., const double r_min=1., const double r_max=350., const double k_min=1.e-4, const double k_max=100., const int step=500, const std::string output_dir=par::defaultString, const std::string output_root="test", const int norm=-1, const double aa=0., const bool GSL=true, const double prec=1.e-3, const std::string file_par=par::defaultString, const double Delta=200., const bool isDelta_critical=true, const std::vector< double > cluster_redshift={}, const std::vector< double > cluster_mass_proxy={}, const std::vector< double > cluster_mass_proxy_error={}, const std::string model_bias="Tinker", const std::string meanType="mean_bias", const int seed=666, const cbl::cosmology::Cosmology cosmology_mass={}, const std::vector< double > redshift_source={})
set the data used to construct generic models of the two-point correlation function
The class PriorDistribution.
@ _createRandom_box_
random catalogue with cubic geometry (or parallelepiped) in comoving coordinates
@ _Uniform_
Identity function.
@ _monopole_
the angle-averaged two-point correlation function, i.e. the monopole, ξ(r)
@ _Poisson_
Poissonian error.
@ _Gaussian_Error_
Gaussian likelihood error.
@ _observed_
observed coordinates (R.A., Dec, redshift)
std::vector< T > logarithmic_bin_vector(const size_t nn, const T min, const T max)
fill a std::vector with logarithmically spaced values
Definition: Kernel.h:1621
@ _linear_
linear binning