GammaLib 2.1.0.dev
|
Multiplicative data model class. More...
#include <GModelDataMultiplicative.hpp>
Public Member Functions | |
GModelDataMultiplicative (void) | |
Void constructor. | |
GModelDataMultiplicative (const GXmlElement &xml) | |
XML constructor. | |
GModelDataMultiplicative (const GModelDataMultiplicative &model) | |
Copy constructor. | |
virtual | ~GModelDataMultiplicative (void) |
Destructor. | |
virtual GModelDataMultiplicative & | operator= (const GModelDataMultiplicative &model) |
Assignment operator. | |
virtual void | clear (void) |
Clear multiplicative data model. | |
virtual GModelDataMultiplicative * | clone (void) const |
Clone multiplicative data model. | |
virtual std::string | classname (void) const |
Return class name. | |
virtual std::string | type (void) const |
Return model type. | |
virtual bool | is_constant (void) const |
Return if model is constant. | |
virtual double | eval (const GEvent &event, const GObservation &obs, const bool &gradients=false) const |
Return model values and gradients. | |
virtual double | npred (const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const |
Return spatially integrated data model. | |
virtual GEvents * | mc (const GObservation &obs, GRan &ran) const |
Return simulated events. | |
virtual void | read (const GXmlElement &xml) |
Read model from XML element. | |
virtual void | write (GXmlElement &xml) const |
Write model into XML element. | |
virtual std::string | print (const GChatter &chatter=NORMAL) const |
Print multiplicative data model information. | |
virtual GVector | eval (const GObservation &obs, GMatrixSparse *gradients=NULL, const int &offset=0) const |
Return model values and gradients. | |
void | append (const GModelData &model) |
Append data model component. | |
int | components (void) const |
Return number of data model components. | |
const GModelData * | component (const int &index) const |
Return data model by index. | |
const GModelData * | component (const std::string &name) const |
Return data model by name. | |
Public Member Functions inherited from GModelData | |
GModelData (void) | |
Void constructor. | |
GModelData (const GXmlElement &xml) | |
XML constructor. | |
GModelData (const GModelData &model) | |
Copy constructor. | |
virtual | ~GModelData (void) |
Destructor. | |
virtual GModelData & | operator= (const GModelData &model) |
Assignment operator. | |
Public Member Functions inherited from GModel | |
GModel (void) | |
Void constructor. | |
GModel (const GXmlElement &xml) | |
XML constructor. | |
GModel (const GModel &model) | |
Copy constructor. | |
virtual | ~GModel (void) |
Destructor. | |
virtual GModel & | operator= (const GModel &model) |
Assignment operator. | |
virtual GModelPar & | operator[] (const int &index) |
Returns reference to model parameter by index. | |
virtual const GModelPar & | operator[] (const int &index) const |
Returns reference to model parameter by index (const version) | |
virtual GModelPar & | operator[] (const std::string &name) |
Returns reference to model parameter by name. | |
virtual const GModelPar & | operator[] (const std::string &name) const |
Returns reference to model parameter by name const version) | |
virtual void | setup (const GObservation &obs) const |
Setup model for a given observation. | |
int | size (void) const |
Return number of parameters in model. | |
int | scales (void) const |
Return number of scale parameters in model. | |
GModelPar & | at (const int &index) |
Returns reference to model parameter by index. | |
const GModelPar & | at (const int &index) const |
Returns reference to model parameter by index (const version) | |
bool | has_par (const std::string &name) const |
Checks if parameter name exists. | |
bool | has_scales (void) const |
Signals that model has scales. | |
const std::string & | name (void) const |
Return parameter name. | |
void | name (const std::string &name) |
Set parameter name. | |
const double & | ts (void) const |
Return Test Statistic value. | |
void | ts (const double &ts) |
Set Test Statistic value. | |
const bool & | tscalc (void) const |
Return Test Statistic computation flag. | |
void | tscalc (const bool &tscalc) |
Set Test Statistic computation flag. | |
const bool & | has_ts (void) const |
Signals that model has Test Statistics value. | |
std::string | instruments (void) const |
Returns instruments to which model applies. | |
void | instruments (const std::string &instruments) |
Set instruments to which model applies. | |
GModelPar & | scale (const int &index) |
Returns reference to scale parameter by index. | |
const GModelPar & | scale (const int &index) const |
Returns reference to scale parameter by index (const version) | |
GModelPar | scale (const std::string &instrument) const |
Returns model scale factor for a given instrument. | |
void | scale (const GModelPar &par) |
Set model scale factor for a given instrument. | |
std::string | ids (void) const |
Returns observation identifiers to which model applies. | |
void | ids (const std::string &ids) |
Set observation identifiers to which model applies. | |
bool | is_valid (const std::string &instruments, const std::string &ids) const |
Verifies if model is valid for a given instrument and identifier. | |
const GModelAssociations & | associations (void) const |
Return model associations. | |
void | associations (const GModelAssociations &associations) |
Set model associations. | |
const bool & | has_eval_indices (void) const |
Signals that parameter indices updated by eval() method were set. | |
const std::vector< int > & | eval_indices (void) const |
Return vector of parameter indices updated by eval() method. | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. | |
void | copy_members (const GModelDataMultiplicative &model) |
Copy class members. | |
void | free_members (void) |
Delete class members. | |
Protected Member Functions inherited from GModelData | |
void | init_members (void) |
Initialise class members. | |
void | copy_members (const GModelData &model) |
Copy class members. | |
void | free_members (void) |
Delete class members. | |
Protected Member Functions inherited from GModel | |
void | init_members (void) |
Initialise class members. | |
void | copy_members (const GModel &model) |
Copy class members. | |
void | free_members (void) |
Delete class members. | |
void | read_attributes (const GXmlElement &xml) |
Read model attributes. | |
void | write_attributes (GXmlElement &xml) const |
Write model attributes. | |
std::string | print_attributes (void) const |
Print model attributes. | |
void | read_scales (const GXmlElement &xml) |
Read instrument scales from XML element. | |
void | write_scales (GXmlElement &xml) const |
Write instrument scales into XML element. | |
Protected Attributes | |
std::string | m_type |
Model type. | |
std::vector< GModelData * > | m_models |
Container of data models. | |
Protected Attributes inherited from GModel | |
std::string | m_name |
Model name. | |
std::vector< std::string > | m_instruments |
Instruments to which model applies. | |
std::vector< GModelPar > | m_scales |
Model instrument scale factors. | |
std::vector< std::string > | m_ids |
Identifiers to which model applies. | |
std::vector< GModelPar * > | m_pars |
Pointers to all model parameters. | |
GModelAssociations | m_associations |
Model associations. | |
bool | m_has_ts |
Signals if TS is available. | |
bool | m_has_tscalc |
Signals if tscalc attribute is available. | |
bool | m_tscalc |
Signals if TS should be computed. | |
double | m_ts |
Test Statistic of the model. | |
bool | m_has_eval_inx |
std::vector< int > | m_eval_inx |
Multiplicative data model class.
This class implements a multiplicative data model. The data model components can be defined in an XML file, or added using the append() method.
Definition at line 53 of file GModelDataMultiplicative.hpp.
GModelDataMultiplicative::GModelDataMultiplicative | ( | void | ) |
Void constructor.
Definition at line 74 of file GModelDataMultiplicative.cpp.
References init_members().
Referenced by clone().
|
explicit |
XML constructor.
[in] | xml | XML element containing data model information. |
Constructs a multiplicative data model by extracting information from an XML element. See the read() method for more information about the expected structure of the XML element.
Definition at line 93 of file GModelDataMultiplicative.cpp.
References init_members(), and read().
GModelDataMultiplicative::GModelDataMultiplicative | ( | const GModelDataMultiplicative & | model | ) |
Copy constructor.
[in] | model | Multiplicative data model. |
Definition at line 112 of file GModelDataMultiplicative.cpp.
References copy_members(), and init_members().
|
virtual |
void GModelDataMultiplicative::append | ( | const GModelData & | model | ) |
Append data model component.
[in] | model | Data model component. |
GException::invalid_value | Model with same name exists already in container Model is for incompatible instrument |
Appends a data model component to the multiplicative data model. If the instruments for the container was not set the instrument is copied from the model. Otherwise, the method verifies that the instrument of the model is the same as of the container.
Definition at line 686 of file GModelDataMultiplicative.cpp.
References GModelData::clone(), G_APPEND, GModel::instruments(), m_models, GModel::m_pars, GModel::name(), and GOptimizerPar::name().
Referenced by read().
|
inlinevirtual |
Return class name.
Implements GModelData.
Definition at line 110 of file GModelDataMultiplicative.hpp.
|
virtual |
Clear multiplicative data model.
Implements GModelData.
Definition at line 184 of file GModelDataMultiplicative.cpp.
References GModelData::free_members(), free_members(), GModelData::init_members(), and init_members().
|
virtual |
Clone multiplicative data model.
Implements GModelData.
Definition at line 204 of file GModelDataMultiplicative.cpp.
References GModelDataMultiplicative().
const GModelData * GModelDataMultiplicative::component | ( | const int & | index | ) | const |
Return data model by index.
[in] | index | Index of data model. |
Returns a component of the multiplicative data model by index
.
Definition at line 750 of file GModelDataMultiplicative.cpp.
References G_COMPONENT_INDEX, and m_models.
const GModelData * GModelDataMultiplicative::component | ( | const std::string & | name | ) | const |
Return data model by name.
[in] | name | Name of data model. |
GException::invalid_argument | Model component not found. |
Returns a component of the multiplicative data model by name
.
Definition at line 774 of file GModelDataMultiplicative.cpp.
References G_COMPONENT_NAME, m_models, and GModel::name().
|
inline |
Return number of data model components.
Returns the number of data model components.
Definition at line 138 of file GModelDataMultiplicative.hpp.
References m_models.
Referenced by print().
|
protected |
Copy class members.
[in] | model | Multiplicative data model. |
Definition at line 859 of file GModelDataMultiplicative.cpp.
References m_models, GModel::m_pars, m_type, and GModel::size().
Referenced by GModelDataMultiplicative(), and operator=().
|
virtual |
Return model values and gradients.
[in] | event | Event. |
[in] | obs | Observation. |
[in] | gradients | Compute gradients? |
Evaluates
\[ \prod_{i=0}^{N} {M_{\rm i}}(\rm event, \rm obs) \]
where \({M_{\rm i}}\) is the i-th model component.
If the gradients
flag is true the method will also compute the partial derivatives of each parameter of eachmodel component with respect to the parameters using
\[ \frac{\delta S}{\delta P_{\rm ij}}\prod_{\rm k\neq \rm i}^{n} M_{\rm k} \]
where \({P_{\rm ij}}\) is the j-th parameter of the i-th multiplicative component, while \({M_{\rm k}}\) is the k-th model component and n the number of model components.
Implements GModelData.
Definition at line 262 of file GModelDataMultiplicative.cpp.
References GOptimizerPar::gradient(), gammalib::is_infinite(), gammalib::is_notanumber(), and m_models.
|
virtual |
Return model values and gradients.
[in] | obs | Observation. |
[out] | gradients | Pointer to matrix of gradients. |
[in] | offset | Column index of first matrix gradient (not used). |
GException::invalid_argument | Gradient matrix has wrong number of rows or columns |
Evaluates the model values and parameter gradients for all events in an observation. Gradients are only returned if the gradients
pointer is not NULL.
The matrix of gradients is a sparse matrix where the number of rows corresponds to the number of events and the number of columns corresponds to the number of model parameters (see GObservation::model() method).
An exception is thrown if the dimension of the gradients
matrix is not compatible with the model and the observations.
Reimplemented from GModelData.
Definition at line 350 of file GModelDataMultiplicative.cpp.
References GMatrixBase::columns(), GObservation::events(), G_EVAL, m_models, GMatrixSparse::multiply_column(), GMatrixBase::rows(), GEvents::size(), GModel::size(), and gammalib::str().
|
protected |
Delete class members.
Definition at line 900 of file GModelDataMultiplicative.cpp.
References m_models.
Referenced by clear(), operator=(), and ~GModelDataMultiplicative().
|
protected |
Initialise class members.
Definition at line 841 of file GModelDataMultiplicative.cpp.
References m_models, and m_type.
Referenced by clear(), GModelDataMultiplicative(), GModelDataMultiplicative(), GModelDataMultiplicative(), and operator=().
|
virtual |
Return if model is constant.
Implements GModelData.
Definition at line 216 of file GModelDataMultiplicative.cpp.
References is_constant(), and m_models.
Referenced by is_constant().
|
virtual |
Return simulated events.
[in] | obs | Observation. |
[in] | ran | Random number generator. |
GException::feature_not_implemented | Feature not implemented |
Implements GModelData.
Definition at line 486 of file GModelDataMultiplicative.cpp.
References G_MC.
|
virtual |
Return spatially integrated data model.
[in] | obsEng | Measured event energy. |
[in] | obsTime | Measured event time. |
[in] | obs | Observation. |
GException::feature_not_implemented | Feature not implemented |
Implements GModelData.
Definition at line 460 of file GModelDataMultiplicative.cpp.
References G_NPRED, and npred().
Referenced by npred().
|
virtual |
Assignment operator.
[in] | model | Multiplicative data model. |
Definition at line 151 of file GModelDataMultiplicative.cpp.
References copy_members(), free_members(), init_members(), and GModelData::operator=().
Print multiplicative data model information.
[in] | chatter | Chattiness. |
Implements GModelData.
Definition at line 803 of file GModelDataMultiplicative.cpp.
References components(), GModel::m_pars, gammalib::parformat(), print(), SILENT, GModel::size(), and gammalib::str().
Referenced by print().
|
virtual |
Read model from XML element.
[in] | xml | XML element. |
GException::invalid_value | Invalid model type specified Model is not a data model Model is for an incompatible instrument |
Reads the multiplicative data model from an XML element. The expected XML format is
<source name="Model" type="MultiplicativeData" instrument="..."> <source name="Component1" type="DataSpace" instrument="..."> ... </source> <source name="Component2" type="DataSpace" instrument="..."> ... </source> </source>
Implements GModelData.
Definition at line 522 of file GModelDataMultiplicative.cpp.
References GModelRegistry::alloc(), append(), GXmlElement::attribute(), GRegistry::content(), GXmlNode::element(), GXmlNode::elements(), G_READ, GModel::instruments(), m_models, GModel::m_pars, GModel::name(), GModelData::read(), GModel::read_attributes(), and type().
Referenced by GModelDataMultiplicative().
|
inlinevirtual |
Return model type.
Returns the type of the multiplicative data model.
Implements GModelData.
Definition at line 124 of file GModelDataMultiplicative.hpp.
References m_type.
|
virtual |
Write model into XML element.
[in] | xml | XML element. |
Writes the multiplicative data model into an XML element.
Implements GModelData.
Definition at line 599 of file GModelDataMultiplicative.cpp.
References GXmlNode::append(), GXmlElement::attribute(), gammalib::contains(), GXmlNode::element(), GXmlNode::elements(), G_WRITE, GModel::instruments(), m_models, GModel::name(), GOptimizerPar::name(), GModel::size(), gammalib::split(), type(), GModelData::write(), GModel::write_attributes(), and gammalib::xml_check_type().
|
protected |
Container of data models.
Definition at line 100 of file GModelDataMultiplicative.hpp.
Referenced by append(), component(), component(), components(), copy_members(), eval(), eval(), free_members(), init_members(), is_constant(), read(), and write().
|
protected |
Model type.
Definition at line 99 of file GModelDataMultiplicative.hpp.
Referenced by copy_members(), init_members(), and type().