CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
LikelihoodFunction.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 
34 #ifndef __LIKELFUN__
35 #define __LIKELFUN__
36 
37 #include "Model2D.h"
38 
39 
40 // ===================================================================================================
41 
42 
43 namespace cbl {
44 
45  namespace statistics {
46 
51  enum class LikelihoodType {
52 
54  _NotSet_,
55 
58 
61 
64 
67 
68  };
69 
75  inline std::vector<std::string> LikelihoodTypeNames () {return {"NotSet", "Gaussian_Error", "Gaussian_ColikelihoodTypeiance", "Poissonian", "UserDefined"}; }
76 
84  inline LikelihoodType LikelihoodTypeCast (const int likelihoodTypeIndex) {return castFromValue<LikelihoodType>(likelihoodTypeIndex);}
85 
93  inline LikelihoodType LikelihoodTypeCast (const std::string likelihoodTypeName) {return castFromName<LikelihoodType>(likelihoodTypeName, LikelihoodTypeNames());}
94 
102  inline std::vector<LikelihoodType> LikelihoodTypeCast (const std::vector<int> likelihoodTypeIndeces) {return castFromValues<LikelihoodType>(likelihoodTypeIndeces);}
103 
111  inline std::vector<LikelihoodType> LikelihoodTypeCast (const std::vector<std::string> likelihoodTypeNames) {return castFromNames<LikelihoodType>(likelihoodTypeNames, LikelihoodTypeNames());}
112 
121  {
123  std::shared_ptr<data::Data> data;
124 
126  std::shared_ptr<Model> model;
127 
129  std::vector<double> xx;
130 
132  std::vector<double> yy;
133 
135  std::vector<double> weights1D;
136 
138  std::vector<std::vector<double>> weights2D;
139 
141  std::shared_ptr<glob::FuncGrid> interp_function1D;
142 
144  std::shared_ptr<glob::FuncGrid2D> interp_function2D;
145 
154  STR_likelihood_inputs (const std::shared_ptr<data::Data> input_data, const std::shared_ptr<Model> input_model, const std::vector<size_t> input_x_index={0, 2}, const int input_w_index=-1);
155 
156  };
157 
167  double LogLikelihood_1D_interpolated (std::vector<double> &likelihood_parameter, const std::shared_ptr<void> input);
168 
178  double LogLikelihood_2D_interpolated (std::vector<double> &likelihood_parameter, const std::shared_ptr<void> input);
179 
192  double LogLikelihood_Gaussian_1D_error (std::vector<double> &likelihood_parameter, const std::shared_ptr<void> input);
193 
203  double LogLikelihood_Gaussian_1D_covariance (std::vector<double> &likelihood_parameter, const std::shared_ptr<void> input);
204 
218  double LogLikelihood_Gaussian_2D_error (std::vector<double> &likelihood_parameter, const std::shared_ptr<void> input);
219 
233  double LogLikelihood_Poissonian_1D_ (std::vector<double> &likelihood_parameter, const std::shared_ptr<void> input);
234 
247  double LogLikelihood_Poissonian_2D_ (std::vector<double> &likelihood_parameter, const std::shared_ptr<void> input);
248 
255  typedef std::function<double (std::vector<double> &, const std::shared_ptr<void>)> LogLikelihood_function;
256 
263  typedef std::function<double (std::vector<double> &, const std::shared_ptr<void>)> Likelihood_function;
264  }
265 }
266 
267 #endif
The class Model2D.
double LogLikelihood_Gaussian_1D_covariance(std::vector< double > &likelihood_parameter, const std::shared_ptr< void > input)
function to compute the gaussian loglikelihood
double LogLikelihood_Gaussian_1D_error(std::vector< double > &likelihood_parameter, const std::shared_ptr< void > input)
function to compute the Gaussian log-likelihood
double LogLikelihood_Poissonian_1D_(std::vector< double > &likelihood_parameter, const std::shared_ptr< void > input)
function to compute the poissonian loglikelihood
LikelihoodType
the type of likelihood function
@ _Gaussian_Covariance_
Gaussian likelihood covariance.
@ _Poissonian_
Poissonian likelihood.
@ _Gaussian_Error_
Gaussian likelihood error.
@ _UserDefined_
Likelihood function defined by the user.
std::function< double(std::vector< double > &, const std::shared_ptr< void >)> LogLikelihood_function
definition of a function for computation of the LogLikelihood
LikelihoodType LikelihoodTypeCast(const int likelihoodTypeIndex)
cast an enum of type LikelihoodType from its index
std::vector< std::string > LikelihoodTypeNames()
return a vector containing the LikelihoodType names
double LogLikelihood_1D_interpolated(std::vector< double > &likelihood_parameter, const std::shared_ptr< void > input)
function to compute the loglikelihood on a grid
std::function< double(std::vector< double > &, const std::shared_ptr< void >)> Likelihood_function
definition of a function for computation of the Likelihood
double LogLikelihood_Poissonian_2D_(std::vector< double > &likelihood_parameter, const std::shared_ptr< void > input)
function to compute the poissonian loglikelihood
double LogLikelihood_2D_interpolated(std::vector< double > &likelihood_parameter, const std::shared_ptr< void > input)
function to compute the loglikelihood on a grid
double LogLikelihood_Gaussian_2D_error(std::vector< double > &likelihood_parameter, const std::shared_ptr< void > input)
function to compute the gaussian loglikelihood model with one parameter
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
the struct STR_likelihood_inputs
std::shared_ptr< data::Data > data
data containers
std::vector< double > xx
x position where the model is computed
std::shared_ptr< glob::FuncGrid > interp_function1D
interpolated likelihood function - 1D
std::vector< double > weights1D
weight for the bin - 1D
std::shared_ptr< glob::FuncGrid2D > interp_function2D
interpolated likelihood function - 2D
STR_likelihood_inputs(const std::shared_ptr< data::Data > input_data, const std::shared_ptr< Model > input_model, const std::vector< size_t > input_x_index={0, 2}, const int input_w_index=-1)
constructor
std::vector< double > yy
y position where the model is computed
std::vector< std::vector< double > > weights2D
weight for the bin - 2D
std::shared_ptr< Model > model
model to test