CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
CombinedModelling.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2021 by Federico Marulli and Giorgio Lesci *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************/
20 
34 #ifndef __COMBMODELLING__
35 #define __COMBMODELLING__
36 
37 
38 #include "CombinedPosterior.h"
39 #include "Modelling.h"
40 
41 
42 // ===================================================================================================
43 
44 
45 namespace cbl {
46 
54  namespace modelling {
55 
65  class CombinedModelling : public Modelling {
66 
67  protected:
68 
70  std::shared_ptr<statistics::CombinedPosterior> m_combined_posterior;
71 
72  public:
73 
78 
82  CombinedModelling () = default;
83 
115  CombinedModelling (std::vector<std::shared_ptr<modelling::Modelling>> modelling, std::vector<std::string> repeated_par={}, const std::vector<std::vector<std::vector<int>>> common_repeated_par={});
116 
173  CombinedModelling (std::vector<std::vector<std::shared_ptr<modelling::Modelling>>> modelling, const std::vector<std::shared_ptr<data::CovarianceMatrix>> covariance, const std::vector<cbl::statistics::LikelihoodType> likelihood_types, const std::vector<std::string> repeated_par={}, const std::vector<std::vector<std::vector<int>>> common_repeated_par={}, const std::vector<std::shared_ptr<cosmology::SuperSampleCovariance>> SSC={});
174 
178  virtual ~CombinedModelling () = default;
179 
181 
187 
219  void maximize_combined_posterior (const std::vector<double> start, const unsigned int max_iter=10000, const double tol=1.e-6, const double epsilon=1.e-3);
220 
237  void sample_combined_posterior (const int chain_size, const int nwalkers, const double aa=2, const bool parallel=true);
238 
271  void sample_combined_posterior (const int chain_size, const int nwalkers, 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, const double aa=2, const bool parallel=true);
272 
292  void sample_combined_posterior (const int chain_size, const int nwalkers, const std::string input_dir, const std::string input_file, const int seed, const double aa=2, const bool parallel=true);
293 
295 
296 
301 
358  void write_combined_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);
359 
380  void write_model_from_combined_chain (const std::string output_dir, const std::string output_file, const int start, const int thin, const std::vector<double> xx={}, const std::vector<double> yy={});
381 
383 
384  };
385  }
386 }
387 
388 #endif
The class CombinedPosterior.
The class Modelling.
The class CombinedModelling.
virtual ~CombinedModelling()=default
default destructor
void sample_combined_posterior(const int chain_size, const int nwalkers, const double aa=2, const bool parallel=true)
sample the posterior, initializing the chains by drawing from the prior distributions
std::shared_ptr< statistics::CombinedPosterior > m_combined_posterior
combined posterior
CombinedModelling()=default
default constuctor
void write_combined_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
void write_model_from_combined_chain(const std::string output_dir, const std::string output_file, const int start, const int thin, const std::vector< double > xx={}, const std::vector< double > yy={})
write the model computing 16th, 50th and 84th percentiles from the MCMC
void maximize_combined_posterior(const std::vector< double > start, const unsigned int max_iter=10000, const double tol=1.e-6, const double epsilon=1.e-3)
function that maximizes the combined posterior, finds the best-fit parameters and stores them in the ...
The class Modelling.
Definition: Modelling.h:64
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38