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

This example shows how to measure and model the void size function, extracting constraints on the cosmological parameters of the model

// ==================================================================
// Example code: how to measure and model the void size function,
// extracting constraints on the cosmological parameters of the model
// ==================================================================
#include "Cosmology.h"
#include "Catalogue.h"
#include "Posterior.h"
using namespace std;
int main () {
try {
// --- set the input/output file/directories ---
const std::string dir = "../output/";
const string file_output_start = "model_starting_values.dat";
const string file_output_bestfit = "model_bestfit.dat";
// ------------------------------------------
// ----- load the input void catalogue ------
// ------------------------------------------
// ASCII void catalogue
std::string file_voids_in = "../input/cleaned_void_catalogue.out";
// std::vector containing the variable name list to read from file
// std::vector containing the columns corresponding to each attribute
std::vector<int> columns_voids = {1, 2, 3, 4};
// catalogue constructor
cbl::catalogue::Catalogue void_catalogue {cbl::catalogue::ObjectType::_Void_, cbl::CoordinateType::_comoving_, var_names_voids, columns_voids, {file_voids_in}, 0};
// ------------------------------------------------------------------
// ---------------- measure the void size function ------------------
// ------------------------------------------------------------------
// binning parameters and o
const int nbin = 8;
const double rmin = 23.5;
const double rmax = 35.5;
const double shift = 0.5;
const double vol = 480.*480.*480.; // cut borders
// measure the void number counts and compute Poisson errors
shared_ptr<cbl::measure::numbercounts::NumberCounts1D> ptr_NC = make_shared<cbl::measure::numbercounts::NumberCounts1D>(NC);
// measure the number counts and compute Poissonian errors
ptr_NC->measure(cbl::measure::ErrorType::_Poisson_, "../output/NumberCounts.out", 0, 3213);
ptr_NC->write(dir, "Size_distribution_Poisson.dat");
// ------------------------------------------------------------------
// ------------------ model the void size function ------------------
// ------------------------------------------------------------------
// --- set the model to construct the likelihood ---
// names of the cosmological model parameters
const vector<string> cosmo_parNames = {"sigma8", "Omega_matter"};
// starting values
double val_s8 = 0.809;
double val_Om = 0.2711;
// set the cosmological parameters
const double OmegaM = 0.2711;
const double Omega_b = 0.0451;
const double Omega_nu = 0.;
const double massless_neutrinos = 3.04;
const int massive_neutrinos = 0;
const double OmegaL = 0.7289;
const double Omega_radiation = 0.;
const double hh = 0.703;
const double scalar_amp = 2.194e-9;
const double scalar_pivot = 0.05;
const double n_s = 0.96;
const double w0 = -1.;
const double wa = 0.;
cbl::cosmology::Cosmology cosmology(OmegaM, Omega_b, Omega_nu, massless_neutrinos, massive_neutrinos, OmegaL, Omega_radiation, hh, scalar_amp, scalar_pivot, n_s, w0, wa);
cosmology.set_sigma8(0.809);
const double redshift = 0.00;
vector<cbl::cosmology::CosmologicalParameter> ModelCosmoPar = cbl::cosmology::CosmologicalParameterCast(cosmo_parNames);
// set the limits for the cosmological parameters
const double min_s8 = 0.6, max_s8 = 0.9;
const double min_Om = 0.1, max_Om = 0.4;
const vector<vector<double>> limits = {{min_s8, max_s8}, {min_Om, max_Om}};
// --- construct the priors ---
const vector<cbl::statistics::PriorDistribution> prior_cosmoPar = {prior_s8, prior_Om};
vector<double> size; // vector containing the void radii
for (size_t i=0; i<ptr_NC->dataset()->xx().size(); i++){
size.push_back(ptr_NC->dataset()->xx()[i]);}
// create the void size function model using the measured void number counts
// set the theoretical model and the parameter priors
double val_beff = 1.1218389; // the tracer bias
double val_slp = 0.85676; // the slope of the linear relation
double val_offs = 0.42153; // the offset of the linear relation
double del_vNL = -0.7; // the linear underdensity threshold
double del_c = cosmology.deltac(redshift); // the linear overdensity threshold
model_SF.set_data_model_SF(cosmology, size, redshift, "Vdn", val_beff, val_slp, val_offs, del_vNL, del_c);
model_SF.set_model_NumberCounts_cosmology(ModelCosmoPar, prior_cosmoPar);
// set the likelihood
// maximize the posterior
model_SF.maximize_posterior({val_s8, val_Om});
}
catch(cbl::glob::Exception &exc) {cerr << exc.what() << endl; exit(1); }
return 0;
}
The class Catalogue
The class Cosmology.
int main()
main function to create the logo of the CosmoBolognaLib
Definition: Logo.cpp:41
The class Modelling_NumberCounts1D_Size.
The class NumberCounts1D_Size.
The class Posterior.
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
double deltac(const double redshift) const
spherical collapse density threshold at a given redshift
Definition: Cosmology.cpp:1248
The class Exception.
Definition: Exception.h:111
const char * what() const noexcept override
the error description
Definition: Exception.h:203
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 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_NumberCounts_cosmology(const std::vector< cbl::cosmology::CosmologicalParameter > cosmo_params={}, const std::vector< statistics::PriorDistribution > cosmo_param_priors={})
set the cosmological parameters used to model the size function
void set_data_model_SF(const cosmology::Cosmology cosmology, const std::vector< double > radii, const double redshift, const std::string model, const double b_eff, double slope=0.854, double offset=0.420, const double deltav_NL=-0.795, const double del_c=1.69, const std::string method_Pk="EisensteinHu", const double k_Pk_ratio=-1., const bool store_output=true, const std::string output_root="test", const std::string interpType="Linear", const double k_max=100., const std::string input_file=par::defaultString, const bool is_parameter_file=true)
Member functions used to set the model parameters.
The class PriorDistribution.
@ _Z_
coordinate z
@ _Y_
coordinate y
@ _X_
coordinate x
CosmologicalParameter CosmologicalParameterCast(const int cosmologicalParameterIndex)
cast an enum of type CosmologicalParameter from its index
Definition: Cosmology.h:220
@ _Uniform_
Identity function.
@ _dn_dlnV_
, where are the bin limits
@ _Poisson_
Poissonian error.
@ _Gaussian_Error_
Gaussian likelihood error.
@ _comoving_
comoving coordinates (x, y, z)