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

The class Model1D. More...

#include "Headers/Model1D.h"

Inheritance diagram for cbl::statistics::Model1D:
Collaboration diagram for cbl::statistics::Model1D:

Public Member Functions

void set_function (const model_function_1D function)
 set the model function More...
 
void set_function (const std::vector< double >(*function)(const std::vector< double > xx, std::vector< double > &val))
 set the model function More...
 
double operator() (const double xx, std::vector< double > &parameters) const override
 evaluate the model function at xx More...
 
std::vector< double > operator() (const std::vector< double > xx, std::vector< double > &parameters) const override
 evaluate the model function at xx More...
 
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 More...
 
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 More...
 
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 More...
 
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. More...
 
Constructors/destructors
 Model1D ()
 default constructor
 
 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 More...
 
 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 More...
 
 ~Model1D ()=default
 default destructor
 
- Public Member Functions inherited from cbl::statistics::Model
Dim dimension () const
 return the model dimension More...
 
void set_function (const model_function_1D function)
 set the model function, for Model1D More...
 
void set_function (const std::vector< double >(*function)(const std::vector< double > xx, std::vector< double > &val))
 set the model function, for Model1D More...
 
void set_function (const model_function_2D function)
 set the model function, for Model2D More...
 
void set_inputs (std::shared_ptr< void > inputs)
 set the model inputs More...
 
void set_parameters (const std::shared_ptr< ModelParameters > parameters)
 set the model parameters More...
 
void set_parameters (const size_t nparameters, std::vector< ParameterType > parameterTypes, std::vector< std::string > parameterNames)
 set the model parameters More...
 
std::shared_ptr< void > inputs ()
 return the model inputs More...
 
std::shared_ptr< ModelParametersparameters ()
 return the model parameters More...
 
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 More...
 
virtual double operator() (const double xx, const double yy, std::vector< double > &parameters) const
 evaluate the model function at xx, yy, for Model2D More...
 
virtual std::vector< std::vector< double > > operator() (const std::vector< double > xx, const std::vector< double > yy, std::vector< double > &parameters) const
 evaluate the model function at xx, yy, for Model2D More...
 
void stats_from_chains (const std::vector< std::vector< double >> xx, 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)
 compute the median and percentiles of the model from MCMC chains More...
 
virtual 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)
 compute the median and percentiles of the model from MCMC chains More...
 
virtual 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)
 write the model at xx, yy for given parameters More...
 
virtual void write_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, yy with best-fit parameters obtained from likelihood maximization
More...
 
virtual 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)
 write the model at xx, yy computing 16th, 50th and 84th percentiles from the chains. More...
 
 Model ()=default
 default constructor
 
 Model (const int nparameters, std::vector< ParameterType > parameterTypes, std::vector< std::string > parameterNames, const std::shared_ptr< void > inputs)
 constructor More...
 
virtual ~Model ()=default
 default destructor
 

Additional Inherited Members

- Protected Attributes inherited from cbl::statistics::Model
std::shared_ptr< void > m_inputs
 inputs of the model
 
std::shared_ptr< ModelParametersm_parameters
 parameters of the model
 
model_function_generic m_function
 the model function
 
Dim m_dimension
 the model dimension
 

Detailed Description

The class Model1D.

This class is used to define 1D models

Examples
fit.cpp.

Definition at line 60 of file Model1D.h.

Constructor & Destructor Documentation

◆ Model1D() [1/2]

cbl::statistics::Model1D::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 
)
inline

constructor

Parameters
functionmodel function
nparametersthe number of parameters
parameterTypesthe parameter types
parameterNamesthe parameter names
inputsinputs of the model

Definition at line 91 of file Model1D.h.

◆ Model1D() [2/2]

cbl::statistics::Model1D::Model1D ( const std::vector< double >(*)(const std::vector< double > xx, std::vector< double > &val)  function,
const size_t  nparameters,
std::vector< ParameterType parameterTypes = {},
std::vector< std::string >  parameterNames = {},
const std::shared_ptr< void >  inputs = NULL 
)
inline

constructor

Parameters
functionmodel function
nparametersthe number of parameters
parameterTypesthe parameter types
parameterNamesthe parameter names
inputsinputs of the model

Definition at line 109 of file Model1D.h.

Member Function Documentation

◆ operator()() [1/2]

double cbl::statistics::Model1D::operator() ( const double  xx,
std::vector< double > &  parameters 
) const
inlineoverridevirtual

evaluate the model function at xx

Parameters
xxthe positions at which the model is computed
parametersvector containing the model parameters
Returns
vector containing model values

Reimplemented from cbl::statistics::Model.

Definition at line 151 of file Model1D.h.

◆ operator()() [2/2]

std::vector<double> cbl::statistics::Model1D::operator() ( const std::vector< double >  xx,
std::vector< double > &  parameters 
) const
inlineoverridevirtual

evaluate the model function at xx

Parameters
xxvector containing the positions at which the model is computed
parametersvector containing the model parameters
Returns
vector containing model values

Reimplemented from cbl::statistics::Model.

Definition at line 168 of file Model1D.h.

◆ set_function() [1/2]

void cbl::statistics::Model1D::set_function ( const model_function_1D  function)

set the model function

Parameters
functionpointer to a model_function_1D

Definition at line 44 of file Model1D.cpp.

◆ set_function() [2/2]

void cbl::statistics::Model1D::set_function ( const std::vector< double >(*)(const std::vector< double > xx, std::vector< double > &val)  function)

set the model function

Parameters
functionpointer to a model_function_1D
Warning
function passed in this way doesn't allow for input parameters

Definition at line 57 of file Model1D.cpp.

◆ stats_from_chains()

void cbl::statistics::Model1D::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 
)
overridevirtual

compute the median and percentiles of the model from MCMC chains

Parameters
xxvector of points at which the model is computed,
median_modelthe median model
low_modelthe model at 16th percentile
up_modelthe model at 84th percentile
startthe starting position for each chain
thinthe position step

Reimplemented from cbl::statistics::Model.

Definition at line 71 of file Model1D.cpp.

◆ write()

void cbl::statistics::Model1D::write ( const std::string  output_dir,
const std::string  output_file,
const std::vector< double >  xx,
const std::vector< double >  parameters 
)
overridevirtual

write the model at xx for given parameters

Parameters
output_dirthe output directory
output_filethe output file
xxvector of points at which the model is computed,
parametersvector containing the input parameters used to compute the model; if this vector is not provided, the model will be computed using the best-fit parameters

Reimplemented from cbl::statistics::Model.

Definition at line 86 of file Model1D.cpp.

◆ write_at_bestfit()

void cbl::statistics::Model1D::write_at_bestfit ( const std::string  output_dir,
const std::string  output_file,
const std::vector< double >  xx 
)
overridevirtual

write the model at xx with best-fit parameters obtained from likelihood maximization

Parameters
output_dirthe output directory
output_filethe output file
xxvector of points at which the model is computed,

Reimplemented from cbl::statistics::Model.

Definition at line 122 of file Model1D.cpp.

◆ write_from_chains()

void cbl::statistics::Model1D::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 
)
overridevirtual

write the model at xx computing 16th, 50th and 84th percentiles from the chains.

Parameters
output_dirthe output directory
output_filethe output file
xxvector of points at which the model is computed,
startthe starting position for each chain
thinthe position step

Reimplemented from cbl::statistics::Model.

Definition at line 132 of file Model1D.cpp.


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