CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Modelling1D.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2016 by Federico Marulli and Alfonso Veropalumbo *
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 
35 #include "Modelling.h"
36 
37 using namespace std;
38 
39 using namespace cbl;
40 
41 
42 
43 // ============================================================================================
44 
45 
46 void cbl::modelling::Modelling::set_fit_range (const double xmin, const double xmax)
47 {
48  m_data_fit = m_data->cut(xmin, xmax);
49  m_fit_range = true;
50 }
51 
52 
53 // ============================================================================================
54 
55 
56 void cbl::modelling::Modelling::write_model (const std::string output_dir, const std::string output_file, const std::vector<double> xx, const std::vector<double> parameters)
57 {
58  if (m_model==NULL)
59  ErrorCBL("no model found!", "write_model", "Modelling1D.cpp");
60 
61  m_model->write(output_dir, output_file, xx, parameters);
62 }
63 
64 
65 // ============================================================================================
66 
67 
68 void cbl::modelling::Modelling::write_model_at_bestfit (const std::string output_dir, const std::string output_file, const std::vector<double> xx)
69 {
70  if (m_posterior==NULL)
71  ErrorCBL("no posterior found: run maximize_posterior() first!", "write_model_at_bestfit", "Modelling1D.cpp");
72 
73  m_posterior->write_model_at_bestfit(output_dir, output_file, xx);
74 }
75 
76 
77 // ============================================================================================
78 
79 
80 void cbl::modelling::Modelling::write_model_from_chains (const std::string output_dir, const std::string output_file, const std::vector<double> xx, const int start, const int thin)
81 {
82  if (m_posterior==NULL)
83  ErrorCBL("no posterior found: run sample_posterior() first!", "write_model_from_chains", "Modelling1D.cpp");
84 
85  m_posterior->write_model_from_chain(output_dir, output_file, xx, {}, start, thin);
86 }
The class Modelling.
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
virtual void write_model(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const std::vector< double > parameters)
write the model at xx for given parameters
Definition: Modelling1D.cpp:56
void set_fit_range(const double xmin, const double xmax)
set the fit range
Definition: Modelling1D.cpp:46
virtual void write_model_at_bestfit(const std::string output_dir, const std::string output_file, const std::vector< double > xx)
write the model at xx with best-fit parameters obtained from posterior maximization
Definition: Modelling1D.cpp:68
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
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
Definition: Kernel.h:780