CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Model2D.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2014 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 
33 #ifndef __MODEL2D__
34 #define __MODEL2D__
35 
36 #include "Model1D.h"
37 
38 
39 // ===================================================================================================
40 
41 
42 namespace cbl {
43 
51  namespace statistics {
52 
60  class Model2D : public Model {
61 
62  public:
63 
68 
75 
91  Model2D (model_function_2D function, const size_t nparameters, std::vector<ParameterType> parameterTypes={}, std::vector<std::string> parameterNames={}, std::shared_ptr<void> inputs=NULL)
92  : Model(nparameters, parameterTypes, parameterNames, inputs) { set_function(function); m_dimension=Dim::_2D_; }
93 
99  ~Model2D () = default;
100 
102 
110  void set_function (const model_function_2D function);
111 
123  double operator () (const double xx, const double yy, std::vector<double> &parameters) const override
124  {
125  std::vector<std::vector<double>> xvec(2); xvec[0] = {xx}; xvec[1] = {yy};
126  return Model::operator()(xvec, parameters)[0][0];
127  }
128 
142  std::vector<std::vector<double>> operator () (const std::vector<double> xx, const std::vector<double> yy, std::vector<double> &parameters) const override
143  {
144  std::vector<std::vector<double>> xvec = {xx, yy};
145  return Model::operator()(xvec, parameters);
146  }
147 
163  void stats_from_chains (const std::vector<double> xx, const std::vector<double> yy, std::vector<std::vector<double>> &median_model, std::vector<std::vector<double>> &low_model, std::vector<std::vector<double>> &up_model, const int start=0, const int thin=1) override;
164 
181  void write (const std::string output_dir, const std::string output_file, const std::vector<double> xx, const std::vector<double> yy, const std::vector<double> parameters) override;
182 
197  void write_at_bestfit (const std::string output_dir, const std::string output_file, const std::vector<double> xx, const std::vector<double> yy) override;
198 
215  void write_from_chains (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) override;
216 
217  };
218  }
219 }
220 
221 #endif
The class Model1D.
The class Model2D.
Definition: Model2D.h:60
double operator()(const double xx, const double yy, std::vector< double > &parameters) const override
evaluate the model function at xx, yy
Definition: Model2D.h:123
void write_from_chains(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) override
write the model at xx, yy computing 16th, 50th and 84th percentiles from the chains.
Definition: Model2D.cpp:102
Model2D(model_function_2D function, const size_t nparameters, std::vector< ParameterType > parameterTypes={}, std::vector< std::string > parameterNames={}, std::shared_ptr< void > inputs=NULL)
constructor
Definition: Model2D.h:91
void stats_from_chains(const std::vector< double > xx, const std::vector< double > yy, std::vector< std::vector< double >> &median_model, std::vector< std::vector< double >> &low_model, std::vector< std::vector< double >> &up_model, const int start=0, const int thin=1) override
compute the median and percentiles of the model from MCMC chains
Definition: Model2D.cpp:56
void set_function(const model_function_2D function)
set the model function
Definition: Model2D.cpp:44
Model2D()
default constructor
Definition: Model2D.h:74
void write_at_bestfit(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const std::vector< double > yy) override
write the model at xx, yy with best-fit parameters obtained from likelihood maximization
Definition: Model2D.cpp:92
void write(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const std::vector< double > yy, const std::vector< double > parameters) override
write the model at xx, yy for given parameters
Definition: Model2D.cpp:65
~Model2D()=default
default destructor
The class Model.
Definition: Model.h:81
std::shared_ptr< ModelParameters > parameters()
return the model parameters
Definition: Model.h:208
Dim m_dimension
the model dimension
Definition: Model.h:95
std::vector< std::vector< double > > operator()(const std::vector< std::vector< double >> xx, std::vector< double > &parameters) const
evalueate the model function at xx, for Model1D
Definition: Model.cpp:43
Model()=default
default constructor
std::shared_ptr< void > inputs()
return the model inputs
Definition: Model.h:200
std::function< std::vector< std::vector< double > >std::vector< double >, std::vector< double >, std::shared_ptr< void >, std::vector< double > &)> model_function_2D
2D function: the inputs are the values at which the function is computed, a pointer to a set of data ...
Definition: Model.h:65
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
@ _2D_
2D pair, used e.g. for 2D pairs, in Cartesian or polar coordinates