![]() |
CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
|
#include "Headers/Chi2.h"
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 | |
![]() | |
std::shared_ptr< ModelParameters > | parameters () const |
return the likelihood parameters More... | |
double | operator() (std::vector< double > &pp) const |
evaluate the likelihood More... | |
double | log (std::vector< double > ¶meter) 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< Model > | get_m_model () |
get the values of the internal variable m_model More... | |
std::shared_ptr< ModelParameters > | get_model_parameters () |
get the values of the internal variable m_model More... | |
std::shared_ptr< data::Data > | get_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 | |
![]() | |
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... | |
![]() | |
std::shared_ptr< data::Data > | m_data |
data containers | |
std::shared_ptr< Model > | m_model |
model to test | |
std::shared_ptr< void > | m_likelihood_inputs |
likelihood inputs | |
std::shared_ptr< ModelParameters > | m_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 | |
The class Chi2.
This class is used to handle objects of type chi2. It is used for all kind of chi2 minimization
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
data | pointers to the data container |
model | pointers to the model |
use_covariance | if true use the full data covariance matrix else use the diagonal |
x_index | index(s) of the extra info std::vector containing the point(s) where to evaluate the model |
w_index | index of the extra info std::vector containing the data point weight |
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
start | std::vector containing initial values for the likelihood maximization |
parameter_limits | limits for the parameters |
max_iter | the maximum number of iterations |
tol | the tolerance in finding convergence |
epsilon | the relative fraction of the interval size |
double cbl::statistics::Chi2::operator() | ( | std::vector< double > & | pp | ) | const |