CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
cbl::statistics::Chi2 Class Reference

The class Chi2. More...

#include "Headers/Chi2.h"

Inheritance diagram for cbl::statistics::Chi2:
Collaboration diagram for cbl::statistics::Chi2:

Public Member Functions

double operator() (std::vector< double > &pp) const
 evaluate the \(\chi^2\) More...
 
void minimize (const std::vector< double > start, const std::vector< std::vector< double >> parameter_limits, const unsigned int max_iter=10000, const double tol=1.e-6, const double epsilon=1.e-3)
 function that minimizes the \(\chi^2\), finds the best-fit parameters and stores them in model parameters More...
 
Constructors/destructors
 Chi2 ()
 default constructor
 
 Chi2 (const std::shared_ptr< data::Data > data, const std::shared_ptr< Model > model, const bool use_covariance=false, const std::vector< size_t > x_index={0, 2}, const int w_index=-1)
 constructor More...
 
 ~Chi2 ()=default
 default destructor
 
- Public Member Functions inherited from cbl::statistics::Likelihood
std::shared_ptr< ModelParametersparameters () const
 return the likelihood parameters More...
 
double operator() (std::vector< double > &pp) const
 evaluate the likelihood More...
 
double log (std::vector< double > &parameter) const
 evaluate the logarithm of the likelihood for the input parameters More...
 
void set_data (std::shared_ptr< data::Data > data)
 set the data for the likelihood analysis More...
 
void set_model (std::shared_ptr< Model > model=NULL, const std::shared_ptr< ModelParameters > model_parameters=NULL)
 set the model for the likelihood analysis More...
 
void unset_grid ()
 set the likelihood function with internal values of LikelihoodType
 
std::shared_ptr< Modelget_m_model ()
 get the values of the internal variable m_model More...
 
std::shared_ptr< ModelParametersget_model_parameters ()
 get the values of the internal variable m_model More...
 
std::shared_ptr< data::Dataget_m_data ()
 get the values of the internal variable m_data More...
 
void set_grid (const int npoints, const std::vector< std::vector< double >> parameter_limits, const std::string file, const bool read=false)
 set the likelihood function as a grid, to speed up computation: this only works for one or two free parameters More...
 
void set_function (const LikelihoodType likelihood_type, const std::vector< size_t > x_index={0, 2}, const int w_index=-1, const double prec=1.e-10, const int Nres=-1)
 set the likelihood type using the LikelihoodType object More...
 
void set_function (const LogLikelihood_function likelihood_function)
 set the likelihood function More...
 
void set_log_function (const LogLikelihood_function loglikelihood_function)
 set the natural logarithm of the likelihood function More...
 
void write_results (const std::string dir_output, const std::string file)
 write best-fit results on a file More...
 
void maximize (const std::vector< double > start, const std::vector< std::vector< double >> parameter_limits, const unsigned int max_iter=10000, const double tol=1.e-6, const double epsilon=1.e-3)
 function that maximizes the likelihood, finds the best-fit parameters and stores them in the model More...
 
void write_model (const std::string output_dir, const std::string output_file, const std::vector< double > parameters, const std::vector< double > xx={}, const std::vector< double > yy={})
 write the model at xx at bestfit More...
 
void write_model_at_bestfit (const std::string output_dir, const std::string output_file, const std::vector< double > xx={}, const std::vector< double > yy={})
 write the model at xx at bestfit More...
 
 Likelihood ()
 default constructor
 
 Likelihood (const std::shared_ptr< data::Data > data, const std::shared_ptr< Model > model, const LikelihoodType likelihood_type, const std::vector< size_t > x_index={0, 2}, const int w_index=-1, const std::shared_ptr< ModelParameters > model_parameters=NULL, const double prec=1.e-10, const int Nres=-1)
 constructor More...
 
 Likelihood (const std::shared_ptr< data::Data > data, const std::shared_ptr< Model > model, const Likelihood_function log_likelihood_function, const std::shared_ptr< ModelParameters > model_parameters=NULL)
 constructor More...
 
virtual ~Likelihood ()=default
 default destructor
 

Additional Inherited Members

- Protected Member Functions inherited from cbl::statistics::Likelihood
void m_set_grid_likelihood_1D (const int npoints, const std::vector< std::vector< double >> parameter_limits, const std::string output_file)
 set the likelihood grid and write the grid on a file More...
 
void m_set_grid_likelihood_1D (const std::string input_file)
 set the likelihood grid from file More...
 
void m_set_grid_likelihood_2D (const int npoints, const std::vector< std::vector< double >> parameter_limits, const std::string output_file)
 set the likelihood grid and write the grid on a file More...
 
void m_set_grid_likelihood_2D (const std::string input_file)
 set the likelihood grid from file More...
 
- Protected Attributes inherited from cbl::statistics::Likelihood
std::shared_ptr< data::Datam_data
 data containers
 
std::shared_ptr< Modelm_model
 model to test
 
std::shared_ptr< void > m_likelihood_inputs
 likelihood inputs
 
std::shared_ptr< ModelParametersm_model_parameters
 likelihood parameters
 
LikelihoodType m_likelihood_type = LikelihoodType::_NotSet_
 type of the likelihood
 
LogLikelihood_function m_log_likelihood_function
 log-likelihood function
 
Likelihood_function m_likelihood_function
 likelihood function
 
LogLikelihood_function m_likelihood_function_grid
 likelihood function on a grid
 
LogLikelihood_function m_log_likelihood_function_grid
 log-likelihood function on a grid
 
std::vector< size_t > m_x_index
 
int m_w_index
 the index in extra info where the bin weight is stored
 
bool m_use_grid = false
 use grid
 

Detailed Description

The class Chi2.

This class is used to handle objects of type chi2. It is used for all kind of chi2 minimization

Definition at line 55 of file Chi2.h.

Constructor & Destructor Documentation

◆ Chi2()

cbl::statistics::Chi2::Chi2 ( const std::shared_ptr< data::Data data,
const std::shared_ptr< Model model,
const bool  use_covariance = false,
const std::vector< size_t >  x_index = {0,2},
const int  w_index = -1 
)

constructor

Parameters
datapointers to the data container
modelpointers to the model
use_covarianceif true use the full data covariance matrix else use the diagonal
x_indexindex(s) of the extra info std::vector containing the point(s) where to evaluate the model
w_indexindex of the extra info std::vector containing the data point weight

Definition at line 55 of file Chi2.cpp.

Member Function Documentation

◆ minimize()

void cbl::statistics::Chi2::minimize ( const std::vector< double >  start,
const std::vector< std::vector< double >>  parameter_limits,
const unsigned int  max_iter = 10000,
const double  tol = 1.e-6,
const double  epsilon = 1.e-3 
)

function that minimizes the \(\chi^2\), finds the best-fit parameters and stores them in model parameters

Parameters
startstd::vector containing initial values for the likelihood maximization
parameter_limitslimits for the parameters
max_iterthe maximum number of iterations
tolthe tolerance in finding convergence
epsilonthe relative fraction of the interval size

Definition at line 74 of file Chi2.cpp.

◆ operator()()

double cbl::statistics::Chi2::operator() ( std::vector< double > &  pp) const

evaluate the \(\chi^2\)

Parameters
ppthe parameters
Returns
the \(\chi^2\)

Definition at line 43 of file Chi2.cpp.


The documentation for this class was generated from the following files: