CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Model1D.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 __MODEL1D__
34 #define __MODEL1D__
35 
36 #include "Model.h"
37 
38 
39 // ===================================================================================================
40 
41 
42 namespace cbl {
43 
51  namespace statistics {
52 
60  class Model1D : public Model {
61 
62  public:
63 
68 
75 
91  Model1D (const model_function_1D function, const size_t nparameters, std::vector<ParameterType> parameterTypes={}, std::vector<std::string> parameterNames={}, const std::shared_ptr<void> inputs=NULL) : Model(nparameters, parameterTypes, parameterNames, inputs)
92  { set_function(function); m_dimension=Dim::_1D_; }
93 
109  Model1D (const std::vector<double> (*function)(const std::vector<double> xx, std::vector<double> &val), const size_t nparameters, std::vector<ParameterType> parameterTypes={}, std::vector<std::string> parameterNames={}, const std::shared_ptr<void> inputs=NULL) : Model(nparameters, parameterTypes, parameterNames, inputs)
110  { set_function(function); m_dimension=Dim::_1D_; }
111 
117  ~Model1D () = default;
118 
120 
128  void set_function (const model_function_1D function);
129 
140  void set_function (const std::vector<double> (*function)(const std::vector<double> xx, std::vector<double> &val));
141 
151  double operator () (const double xx, std::vector<double> &parameters) const override
152  {
153  std::vector<std::vector<double>> xvec(1, std::vector<double>(1, xx));
154  return Model::operator()(xvec, parameters)[0][0];
155  }
156 
168  std::vector<double> operator () (const std::vector<double> xx, std::vector<double> &parameters) const override
169  {
170  std::vector<std::vector<double>> xvec(1, xx);
171  return Model::operator()(xvec, parameters)[0];
172  }
173 
186  void stats_from_chains (const std::vector<double> xx, std::vector<double> &median_model, std::vector<double> &low_model, std::vector<double> &up_model, const int start=0, const int thin=1) override;
187 
201  void write (const std::string output_dir, const std::string output_file, const std::vector<double> xx, const std::vector<double> parameters) override;
202 
214  void write_at_bestfit (const std::string output_dir, const std::string output_file, const std::vector<double> xx) override;
215 
229  void write_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) override;
230 
231  };
232  }
233 }
234 
235 #endif
The class Model.
The class Model1D.
Definition: Model1D.h:60
void write(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const std::vector< double > parameters) override
write the model at xx for given parameters
Definition: Model1D.cpp:86
void write_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) override
write the model at xx computing 16th, 50th and 84th percentiles from the chains.
Definition: Model1D.cpp:132
Model1D(const std::vector< double >(*function)(const std::vector< double > xx, std::vector< double > &val), const size_t nparameters, std::vector< ParameterType > parameterTypes={}, std::vector< std::string > parameterNames={}, const std::shared_ptr< void > inputs=NULL)
constructor
Definition: Model1D.h:109
Model1D()
default constructor
Definition: Model1D.h:74
void write_at_bestfit(const std::string output_dir, const std::string output_file, const std::vector< double > xx) override
write the model at xx with best-fit parameters obtained from likelihood maximization
Definition: Model1D.cpp:122
void set_function(const model_function_1D function)
set the model function
Definition: Model1D.cpp:44
double operator()(const double xx, std::vector< double > &parameters) const override
evaluate the model function at xx
Definition: Model1D.h:151
Model1D(const model_function_1D function, const size_t nparameters, std::vector< ParameterType > parameterTypes={}, std::vector< std::string > parameterNames={}, const std::shared_ptr< void > inputs=NULL)
constructor
Definition: Model1D.h:91
~Model1D()=default
default destructor
void stats_from_chains(const std::vector< double > xx, std::vector< double > &median_model, std::vector< double > &low_model, 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: Model1D.cpp:71
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< double >std::vector< double >, std::shared_ptr< void >, std::vector< double > &)> model_function_1D
1D function: the inputs are a vector of values at which the function is computed, a pointer to a set ...
Definition: Model.h:58
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
@ _1D_
1D, used e.g. for 1D pairs, in angular or comoving separations