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

The class Model. More...

#include "Headers/Model.h"

Inheritance diagram for cbl::statistics::Model:

Public Member Functions

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, std::vector< double > &parameters) const
 evaluate the model function at xx, for Model1D More...
 
virtual std::vector< double > operator() (const std::vector< double > xx, std::vector< double > &parameters) const
 evaluate 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, std::vector< double > &median_model, std::vector< double > &low_model, 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 > parameters)
 write the model at xx for given parameters 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)
 write the model at xx with best-fit parameters obtained from likelihood maximization 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 int start=0, const int thin=1)
 write the model at xx computing 16th, 50th and 84th percentiles from the chains. 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...
 
Constructors/destructors
 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
 

Protected Attributes

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 Model.

This class is used to define models

Definition at line 81 of file Model.h.

Constructor & Destructor Documentation

◆ Model()

cbl::statistics::Model::Model ( const int  nparameters,
std::vector< ParameterType parameterTypes,
std::vector< std::string >  parameterNames,
const std::shared_ptr< void >  inputs 
)
inline

constructor

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

Definition at line 120 of file Model.h.

Member Function Documentation

◆ dimension()

Dim cbl::statistics::Model::dimension ( ) const
inline

return the model dimension

Returns
the model dimension

Definition at line 137 of file Model.h.

◆ inputs()

std::shared_ptr<void> cbl::statistics::Model::inputs ( )
inline

return the model inputs

Returns
pointer to the model inputs

Definition at line 200 of file Model.h.

◆ operator()() [1/5]

virtual double cbl::statistics::Model::operator() ( const double  xx,
const double  yy,
std::vector< double > &  parameters 
) const
inlinevirtual

evaluate the model function at xx, yy, for Model2D

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

Reimplemented in cbl::statistics::Model2D.

Definition at line 259 of file Model.h.

◆ operator()() [2/5]

virtual double cbl::statistics::Model::operator() ( const double  xx,
std::vector< double > &  parameters 
) const
inlinevirtual

evaluate the model function at xx, for Model1D

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

Reimplemented in cbl::statistics::Model1D.

Definition at line 232 of file Model.h.

◆ operator()() [3/5]

virtual std::vector<std::vector<double> > cbl::statistics::Model::operator() ( const std::vector< double >  xx,
const std::vector< double >  yy,
std::vector< double > &  parameters 
) const
inlinevirtual

evaluate the model function at xx, yy, for Model2D

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

Reimplemented in cbl::statistics::Model2D.

Definition at line 275 of file Model.h.

◆ operator()() [4/5]

virtual std::vector<double> cbl::statistics::Model::operator() ( const std::vector< double >  xx,
std::vector< double > &  parameters 
) const
inlinevirtual

evaluate the model function at xx, for Model1D

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

Reimplemented in cbl::statistics::Model1D.

Definition at line 245 of file Model.h.

◆ operator()() [5/5]

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

evalueate the model function at xx, for Model1D

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

Definition at line 43 of file Model.cpp.

◆ parameters()

std::shared_ptr<ModelParameters> cbl::statistics::Model::parameters ( )
inline

return the model parameters

Returns
pointer to an object of class ModelParameters

Definition at line 208 of file Model.h.

◆ set_function() [1/3]

void cbl::statistics::Model::set_function ( const model_function_1D  function)
inline

set the model function, for Model1D

Parameters
functionpointer to a model_function_1D

Definition at line 146 of file Model.h.

◆ set_function() [2/3]

void cbl::statistics::Model::set_function ( const model_function_2D  function)
inline

set the model function, for Model2D

Parameters
functionpointer to a model_function_2D

Definition at line 167 of file Model.h.

◆ set_function() [3/3]

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

set the model function, for Model1D

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

Definition at line 159 of file Model.h.

◆ set_inputs()

void cbl::statistics::Model::set_inputs ( std::shared_ptr< void >  inputs)
inline

set the model inputs

Parameters
inputsthe inputs of the model

Definition at line 175 of file Model.h.

◆ set_parameters() [1/2]

void cbl::statistics::Model::set_parameters ( const size_t  nparameters,
std::vector< ParameterType parameterTypes,
std::vector< std::string >  parameterNames 
)

set the model parameters

Parameters
nparametersthe number of parameters
parameterTypesthe parameter types
parameterNamesthe parameter names

Definition at line 53 of file Model.cpp.

◆ set_parameters() [2/2]

void cbl::statistics::Model::set_parameters ( const std::shared_ptr< ModelParameters parameters)
inline

set the model parameters

Parameters
parameterspointer to parameters

Definition at line 182 of file Model.h.

◆ stats_from_chains() [1/3]

virtual void cbl::statistics::Model::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 
)
inlinevirtual

compute the median and percentiles of the model from MCMC chains

Parameters
xxvector of points at which the model is computed, first axis
yyvector of points at which the model is computed, second axis
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 in cbl::statistics::Model2D.

Definition at line 321 of file Model.h.

◆ stats_from_chains() [2/3]

virtual void cbl::statistics::Model::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 
)
inlinevirtual

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 in cbl::statistics::Model1D.

Definition at line 303 of file Model.h.

◆ stats_from_chains() [3/3]

void cbl::statistics::Model::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

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

Definition at line 62 of file Model.cpp.

◆ write() [1/2]

virtual void cbl::statistics::Model::write ( const std::string  output_dir,
const std::string  output_file,
const std::vector< double >  xx,
const std::vector< double >  parameters 
)
inlinevirtual

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 in cbl::statistics::Model1D.

Definition at line 335 of file Model.h.

◆ write() [2/2]

virtual void cbl::statistics::Model::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 
)
inlinevirtual

write the model at xx, yy for given parameters

Parameters
output_dirthe output directory
output_filethe output file
xxvector of points at which the model is computed, first axis
yyvector of points at which the model is computed, second axis
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 in cbl::statistics::Model2D.

Definition at line 352 of file Model.h.

◆ write_at_bestfit() [1/2]

virtual void cbl::statistics::Model::write_at_bestfit ( const std::string  output_dir,
const std::string  output_file,
const std::vector< double >  xx 
)
inlinevirtual

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 in cbl::statistics::Model1D.

Definition at line 364 of file Model.h.

◆ write_at_bestfit() [2/2]

virtual void cbl::statistics::Model::write_at_bestfit ( const std::string  output_dir,
const std::string  output_file,
const std::vector< double >  xx,
const std::vector< double >  yy 
)
inlinevirtual

write the model at xx, yy 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, first axis
yyvector of points at which the model is computed, second axis

Reimplemented in cbl::statistics::Model2D.

Definition at line 379 of file Model.h.

◆ write_from_chains() [1/2]

virtual void cbl::statistics::Model::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 
)
inlinevirtual

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 in cbl::statistics::Model1D.

Definition at line 393 of file Model.h.

◆ write_from_chains() [2/2]

virtual void cbl::statistics::Model::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 
)
inlinevirtual

write the model at xx, yy 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, first axis
yyvector of points at which the model is computed, second axis
startthe starting position for each chain
thinthe position step

Reimplemented in cbl::statistics::Model2D.

Definition at line 410 of file Model.h.


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