46 namespace statistics {
60 std::shared_ptr<cbl::statistics::Prior>
m_prior;
139 Posterior (
const std::vector<std::shared_ptr<PriorDistribution>> prior_distributions,
const Likelihood &likelihood,
const int seed=5341);
164 Posterior (
const std::vector<std::shared_ptr<PriorDistribution>> prior_distributions,
const std::shared_ptr<data::Data> data,
const std::shared_ptr<Model> model,
const LikelihoodType likelihood_type,
const std::vector<size_t> x_index,
const int w_index,
const int seed=5341);
180 Posterior (
const std::string file_name,
const std::string path_file,
const std::vector<int> usecols,
const std::vector<std::string> parameter_names,
const int skip_header);
214 double operator () (std::vector<double> &pp)
const;
225 std::vector<double>
weight (
const int start=0,
const int thin=1)
const;
244 double log (std::vector<double> &pp)
const;
263 double chi2 (
const std::vector<double> parameter={})
const;
274 void set_model (std::shared_ptr<Model> model=NULL,
const std::shared_ptr<ModelParameters> model_parameters=NULL);
299 void set (
const std::vector<std::shared_ptr<PriorDistribution>> prior_distributions,
const std::shared_ptr<data::Data> data,
const std::shared_ptr<Model> model,
const LikelihoodType likelihood_type,
const std::vector<size_t> x_index,
const int w_index,
const int seed);
428 void maximize (
const std::vector<double> start,
const std::vector<std::vector<double>> parameter_limits,
const unsigned int max_iter=10000,
const double tol=1.e-6,
const double epsilon=1.e-3)
429 { (void)start; (void)parameter_limits; (void)max_iter; (void)tol; (void)epsilon;
ErrorCBL(
"the method is used without parameter_ranges!",
"maximize",
"Posterior.h"); }
446 void maximize (
const std::vector<double> start,
const unsigned int max_iter=10000,
const double tol=1.e-6,
const double epsilon=1.e-4);
494 void initialize_chains (
const int chain_size,
const int n_walkers,
const double radius,
const std::vector<double> start,
const unsigned int max_iter=10000,
const double tol=1.e-6,
const double epsilon=1.e-3);
516 void initialize_chains (
const int chain_size,
const int n_walkers, std::vector<double> &value,
const double radius);
529 void initialize_chains (
const int chain_size,
const std::vector<std::vector<double>> chain_value);
547 void initialize_chains (
const int chain_size,
const int n_walkers,
const std::string input_dir,
const std::string input_file);
617 void importance_sampling (
const std::string input_dir,
const std::string input_file,
const std::vector<size_t> column={},
const int header_lines_to_skip=1,
const bool is_FITS_format=
false,
const bool apply_to_likelihood=
false,
const int n_walkers=100);
637 void read_chain (
const std::string input_dir,
const std::string input_file,
const int n_walkers,
const std::vector<size_t> column={},
const int header_lines_to_skip=1,
const bool is_FITS_format=
false);
653 void read_chain_ascii (
const std::string input_dir,
const std::string input_file,
const int n_walkers,
const std::vector<size_t> column={},
const int header_lines_to_skip=1);
666 void read_chain_fits (
const std::string input_dir,
const std::string input_file,
const int n_walkers,
const std::vector<size_t> column);
690 void write_chain (
const std::string output_dir,
const std::string output_file,
const int start=0,
const int thin=1,
const bool is_FITS_format=
false,
const int prec=5,
const int ww=14);
708 void write_chain_ascii (
const std::string output_dir,
const std::string output_file,
const int start=0,
const int thin=1,
const int prec=5,
const int ww=14);
722 void write_chain_fits (
const std::string output_dir,
const std::string output_file,
const int start=0,
const int thin=1);
775 void show_results (
const int start,
const int thin,
const int nbins=50,
const bool show_mode=
false,
const int ns=-1,
const int nb=-1);
831 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,
const int nb=-1);
849 void write_model_from_chain (
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);
Class functions used to generate random numbers.
Likelihood_function m_likelihood_function
likelihood function
std::shared_ptr< void > m_likelihood_inputs
likelihood inputs
LogLikelihood_function m_log_likelihood_function_grid
log-likelihood function on a grid
std::shared_ptr< ModelParameters > m_model_parameters
likelihood parameters
LogLikelihood_function m_likelihood_function_grid
likelihood function on a grid
LogLikelihood_function m_log_likelihood_function
log-likelihood function
LogLikelihood_function get_m_log_likelihood_function()
get the values of the internal variable m_log_likelihood_function
void set_model(std::shared_ptr< Model > model=NULL, const std::shared_ptr< ModelParameters > model_parameters=NULL)
set the model for the posterior analysis
void maximize(const std::vector< double > start, const std::vector< std::vector< double >> parameter_limits, const unsigned int max_iter=10000, const double tol=1.e-6, const double epsilon=1.e-3)
function that maximizes the posterior, finds the best-fit parameters and store them in the model
std::shared_ptr< cbl::statistics::Prior > get_m_prior()
get the values of the internal variable m_prior
void read_chain_ascii(const std::string input_dir, const std::string input_file, const int n_walkers, const std::vector< size_t > column={}, const int header_lines_to_skip=1)
read the chains from an ascii file
double operator()(std::vector< double > &pp) const
the un-normalized posterior
void initialize_chains(const int chain_size, const int n_walkers)
initialize the chains by drawing from the prior distributions
std::vector< double > weight(const int start=0, const int thin=1) const
return the internal member m_weights
std::shared_ptr< cbl::statistics::Prior > m_prior
the prior distribution
int m_seed
general seed for prior/posterior distribution and sampler
std::shared_ptr< statistics::Model > m_response_func
response function for the computation of the super-sample covariance
std::shared_ptr< cbl::random::UniformRandomNumbers_Int > m_seed_generator
seed generator
int get_Nparameters()
get the number of parameters used
void read_chain(const std::string input_dir, const std::string input_file, const int n_walkers, const std::vector< size_t > column={}, const int header_lines_to_skip=1, const bool is_FITS_format=false)
read the chains
double log(std::vector< double > &pp) const
the logarithm of the un-normalized posterior
LogLikelihood_function get_m_log_likelihood_function_grid()
get the values of the internal variable m_log_likelihood_function_grid
void importance_sampling(const std::string input_dir, const std::string input_file, const std::vector< size_t > column={}, const int header_lines_to_skip=1, const bool is_FITS_format=false, const bool apply_to_likelihood=false, const int n_walkers=100)
perform importance sampling
void m_set_seed(const int seed)
set the internal attribute m_seed and related quantities
std::vector< std::vector< double > > get_parameters()
get the values of the internal variable m_parameters
double chi2(const std::vector< double > parameter={}) const
the
std::vector< double > m_acceptance
the MCMC acceptance rate
bool get_m_use_grid()
get the value of the internal variable m_use_grid
void write_model_from_chain(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)
write the model at xx, yy computing 16th, 50th and 84th percentiles from the MCMC chains
int m_get_seed()
get the value of the internal variable m_seed
void show_results(const int start, const int thin, const int nbins=50, const bool show_mode=false, const int ns=-1, const int nb=-1)
show the results of the MCMC sampling on screen
void write_chain_ascii(const std::string output_dir, const std::string output_file, const int start=0, const int thin=1, const int prec=5, const int ww=14)
write the chains obtained after the MCMC sampling on an ascii file
int m_generate_seed()
generate a seed
void set_response_function(std::shared_ptr< statistics::Model > response)
set the response function used to compute the super-sample covariance
std::shared_ptr< void > get_m_likelihood_inputs()
get the values of the internal variable m_likelihood_inputs
std::vector< double > m_log_likelihood
the logarithm of the likelihood
Likelihood_function get_m_likelihood_function_grid()
get the values of the internal variable m_likelihood_function_grid
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, const int nb=-1)
store the results of the MCMC sampling to file
int m_Nparameters
the number of parameters
~Posterior()=default
default destructor
void write_chain_fits(const std::string output_dir, const std::string output_file, const int start=0, const int thin=1)
write the chains obtained after the MCMC sampling on a FITS file
std::shared_ptr< statistics::Model > get_response_function()
return the response function used to compute the super-sample covariance
void write_chain(const std::string output_dir, const std::string output_file, const int start=0, const int thin=1, const bool is_FITS_format=false, const int prec=5, const int ww=14)
write the chains obtained after the MCMC sampling
std::vector< double > m_weight
the chain weight
std::vector< double > get_log_posterior()
get the values of the internal variable m_log_posterior
void set(const std::vector< std::shared_ptr< PriorDistribution >> prior_distributions, const std::shared_ptr< data::Data > data, const std::shared_ptr< Model > model, const LikelihoodType likelihood_type, const std::vector< size_t > x_index, const int w_index, const int seed)
set the posterior type using the LikelihoodType object
std::vector< double > m_log_posterior
the logarithm of the posterior
std::shared_ptr< ModelParameters > parameters() const
return the posterior parameters
void m_isSet_response()
check if the response function used to compute the super-sample covariance is set
void sample_stretch_move(const double aa=2, const bool parallel=true, const std::string outputFile=par::defaultString, const int start=0, const int thin=1, const int nbins=50)
sample the posterior using the stretch-move sampler (Foreman-Mackey et al. 2012)
void write_maximization_results(const std::string output_dir, const std::string root_file)
write maximization results on a file
Likelihood_function get_m_likelihood_function()
get the values of the internal variable m_likelihood_function
void read_chain_fits(const std::string input_dir, const std::string input_file, const int n_walkers, const std::vector< size_t > column)
read the chains from an ascii file
Posterior()=default
default constructor
std::vector< std::vector< double > > m_parameters
the parameters
static const std::string defaultString
default std::string value
LikelihoodType
the type of likelihood function
std::function< double(std::vector< double > &, const std::shared_ptr< void >)> LogLikelihood_function
definition of a function for computation of the LogLikelihood
std::function< double(std::vector< double > &, const std::shared_ptr< void >)> Likelihood_function
definition of a function for computation of the Likelihood
The global namespace of the CosmoBolognaLib
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib