GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelPar Class Reference

Model parameter class. More...

#include <GModelPar.hpp>

Inheritance diagram for GModelPar:
GOptimizerPar GBase

Public Member Functions

 GModelPar (void)
 Void constructor. More...
 
 GModelPar (const std::string &name, const double &value)
 Parameter constructor. More...
 
 GModelPar (const std::string &name, const double &factor, const double &scale)
 Parameter constructor. More...
 
 GModelPar (const GModelPar &par)
 Copy constructor. More...
 
virtual ~GModelPar (void)
 Destructor. More...
 
GModelParoperator= (const GModelPar &par)
 Assignment operator. More...
 
GModelParclone (void) const
 Clone model parameter. More...
 
std::string classname (void) const
 Return class name. More...
 
void read (const GXmlElement &xml)
 Extract parameter attributes from XML element. More...
 
void write (GXmlElement &xml) const
 Set or update parameter attributes in XML element. More...
 
- Public Member Functions inherited from GOptimizerPar
 GOptimizerPar (void)
 Void constructor. More...
 
 GOptimizerPar (const std::string &name, const double &value)
 Parameter constructor. More...
 
 GOptimizerPar (const std::string &name, const double &factor, const double &scale)
 Parameter constructor. More...
 
 GOptimizerPar (const GOptimizerPar &par)
 Copy constructor. More...
 
virtual ~GOptimizerPar (void)
 Destructor. More...
 
GOptimizerParoperator= (const GOptimizerPar &par)
 Assignment operator. More...
 
double value (void) const
 Return parameter value. More...
 
double error (void) const
 Return parameter error. More...
 
double gradient (void) const
 Return parameter gradient. More...
 
double min (void) const
 Return parameter minimum boundary. More...
 
double max (void) const
 Return parameter maximum boundary. More...
 
void value (const double &value)
 Set parameter value. More...
 
void error (const double &error)
 Set parameter error. More...
 
void gradient (const double &gradient)
 Set parameter gradient. More...
 
void min (const double &min)
 Set minimum parameter boundary. More...
 
void max (const double &max)
 Set maximum parameter boundary. More...
 
void range (const double &min, const double &max)
 Set minimum and maximum parameter boundaries. More...
 
const double & factor_value (void) const
 Return parameter value factor. More...
 
const double & factor_error (void) const
 Return parameter error factor. More...
 
const double & factor_gradient (void) const
 Return parameter gradient factor. More...
 
const double & factor_min (void) const
 Return parameter minimum boundary factor. More...
 
const double & factor_max (void) const
 Return parameter maximum boundary factor. More...
 
const double & scale (void) const
 Return parameter scale. More...
 
void factor_value (const double &value)
 Set parameter value factor. More...
 
void factor_error (const double &error)
 Set parameter error factor. More...
 
void factor_gradient (const double &gradient) const
 Set parameter gradient factor. More...
 
void factor_min (const double &min)
 Set parameter minimum factor. More...
 
void factor_max (const double &max)
 Set parameter maximum factor. More...
 
void factor_range (const double &min, const double &max)
 Set parameter minimum and maximum factors. More...
 
void scale (const double &scale)
 Set scale factor. More...
 
bool has_min (void) const
 Signal if parameter has minimum boundary. More...
 
bool has_max (void) const
 Signal if parameter has maximum boundary. More...
 
bool has_range (void) const
 Signal if parameter has minimum and maximum boundaries. More...
 
void remove_min (void)
 Removes minimum boundary. More...
 
void remove_max (void)
 Removes maximum boundary. More...
 
void remove_range (void)
 Removes minimum and maximum boundary. More...
 
bool is_free (void) const
 Signal if parameter is free. More...
 
bool is_fixed (void) const
 Signal if parameter is fixed. More...
 
bool has_grad (void) const
 Signal if parameter gradient is computed analytically. More...
 
void free (void)
 Free a parameter. More...
 
void fix (void)
 Fix a parameter. More...
 
void has_grad (const bool &grad)
 Set gradient property. More...
 
void clear (void)
 Clear parameter. More...
 
GOptimizerParclone (void) const
 Clone parameter. More...
 
std::string classname (void) const
 Return class name. More...
 
const std::string & name (void) const
 Return parameter name. More...
 
const std::string & unit (void) const
 Return parameter unit. More...
 
void name (const std::string &name)
 Set parameter name. More...
 
void unit (const std::string &unit)
 Set parameter unit. More...
 
void autoscale (void)
 Autoscale parameter. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print parameter information. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GModelPar &par)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
- Protected Member Functions inherited from GOptimizerPar
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GOptimizerPar &par)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Additional Inherited Members

- Protected Attributes inherited from GOptimizerPar
std::string m_name
 Parameter name. More...
 
std::string m_unit
 Parameter unit. More...
 
double m_factor_value
 Parameter value factor. More...
 
double m_factor_error
 Uncertainty in parameter value factor. More...
 
double m_factor_min
 Parameter minimum factor. More...
 
double m_factor_max
 Parameter maximum factor. More...
 
double m_factor_gradient
 Function gradient factor. More...
 
double m_scale
 Parameter scaling (true = factor * scale) More...
 
bool m_free
 Parameter is free. More...
 
bool m_has_min
 Parameter has minimum boundary. More...
 
bool m_has_max
 Parameter has maximum boundary. More...
 
bool m_has_grad
 Parameter has analytic gradient. More...
 

Detailed Description

Model parameter class.

This class implements a model parameter. A model parameter is a numerical value that is used to describe a model. A model parameter has the following attributes:

  • value gives the numerical value of the parameter
  • error gives the statistical uncertainty in the parameter value
  • gradient gives the gradient of a the model with respect to the parameter
  • min gives the minimum value that the parameter value can take
  • max gives the maximum value that the parameter value can take

The parameter attributes are set and retrieved using the value(), error(), gradient(), min() and max() methods, respectively. Furthermore, the range() method is used to simultaneously set the minimum and maximum value of a parameter.

The minimum and maximum values are optional, and existence of these attributes is tested using the has_min() and has_max() methods, respectively. The minimum value, maximum value are removed using the remove_min() and remove_max() methods. Simultaneous removal of minimum and maximum values is done using the remove_range() method.

Each parameter has furthermore the following properties:

  • free specifies whether the parameter should be fitted
  • grad specifies whether the parameter gradient is computed analytically (true) or numerically (false)

The parameter property free is set using the free() and fix() methods and it is retrieved using the is_free() and is_fixed() methods. The attribute grad is set and retrieved using the has has_grad() methods.

Each model parameter is factorized into a factor and a scale term. The GModelPar class stores the factors and the scale factor has data members, and the true values are computed using the following relations:

value    = m_factor_value    * m_scale
error    = m_factor_error    * m_scale
gradient = m_factor_gradient * m_scale
min      = m_factor_min      * m_scale
max      = m_factor_max      * m_scale

The factor and scale terms can be set and retrieved using the factor_value(), factor_error(), factor_gradient(), factor_min(), factor_max() and scale() methods.

Definition at line 87 of file GModelPar.hpp.

Constructor & Destructor Documentation

GModelPar::GModelPar ( void  )

Void constructor.

Definition at line 59 of file GModelPar.cpp.

References init_members().

Referenced by clone().

GModelPar::GModelPar ( const std::string &  name,
const double &  value 
)

Parameter constructor.

Parameters
[in]nameParameter name.
[in]valueParameter value.

Constructs a parameter from a parameter name and a parameter value.

The parameter is auto-scaled, which for a value that differs from zero sets the scale factor to value and the factor_value to unity. For a value of zero, the scale factor will be set to unity and the factor_value will be set to value.

Definition at line 82 of file GModelPar.cpp.

References init_members().

GModelPar::GModelPar ( const std::string &  name,
const double &  factor,
const double &  scale 
)

Parameter constructor.

Parameters
[in]nameParameter name.
[in]factorParameter value factor.
[in]scaleParameter scaling (non-zero value).
Exceptions
GException::invalid_argumentSacle factor of 0 specified.

Constructs a parameter from a parameter name, value factor and scale factor. The scale factor needs to be a non-zero value. If the scale factor is zero, an exception is thrown.

Definition at line 107 of file GModelPar.cpp.

References init_members().

GModelPar::GModelPar ( const GModelPar par)

Copy constructor.

Parameters
[in]parModel parameter.

Definition at line 126 of file GModelPar.cpp.

References copy_members(), and init_members().

GModelPar::~GModelPar ( void  )
virtual

Destructor.

Definition at line 142 of file GModelPar.cpp.

References free_members().

Member Function Documentation

std::string GModelPar::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GModelPar").

Implements GBase.

Definition at line 121 of file GModelPar.hpp.

GModelPar * GModelPar::clone ( void  ) const
virtual

Clone model parameter.

Returns
Pointer to deep copy of model parameter.

Implements GBase.

Definition at line 199 of file GModelPar.cpp.

References GModelPar().

void GModelPar::copy_members ( const GModelPar par)
protected

Copy class members.

Parameters
[in]parModel parameter.

Definition at line 413 of file GModelPar.cpp.

Referenced by GModelPar(), and operator=().

void GModelPar::free_members ( void  )
protected

Delete class members.

Definition at line 423 of file GModelPar.cpp.

Referenced by operator=(), and ~GModelPar().

void GModelPar::init_members ( void  )
protected

Initialise class members.

Definition at line 401 of file GModelPar.cpp.

Referenced by GModelPar(), and operator=().

GModelPar & GModelPar::operator= ( const GModelPar par)

Assignment operator.

Parameters
[in]parModel parameter.
Returns
Model parameter.

Definition at line 164 of file GModelPar.cpp.

References copy_members(), free_members(), init_members(), and GOptimizerPar::operator=().

void GModelPar::read ( const GXmlElement xml)

Extract parameter attributes from XML element.

Parameters
[in]xmlXML element
Exceptions
GException::invalid_valueInvalid combination of parameter attributes encountered.

Extracts the parameter attributes from an XML element of the form

<parameter name=".." value=".." error=".." scale=".." min=".." max="..' free="..">

Each of the attributes are optional, with the following scheme for assigning default values in case that the attribute was not found:

@p name sets @p m_name (defaults to "Unknown")
@p value sets @p m_factor_value (defaults to 0.0)
@p error sets @p m_factor_error (defaults to 0.0)
@p scale sets @p m_scale (defaults to 1.0)
@p min sets @p m_factor_min (will remove_min() if not found)
@p max sets @p m_factor_max (will remove_max() if not found)
@p free sets @p m_free (papameter will be fixed if not found)

Definition at line 229 of file GModelPar.cpp.

References GXmlElement::attribute(), GOptimizerPar::fix(), GOptimizerPar::free(), G_READ, GOptimizerPar::m_factor_error, GOptimizerPar::m_factor_max, GOptimizerPar::m_factor_min, GOptimizerPar::m_factor_value, GOptimizerPar::m_has_max, GOptimizerPar::m_has_min, GOptimizerPar::m_name, GOptimizerPar::m_scale, GXmlElement::print(), GOptimizerPar::remove_max(), GOptimizerPar::remove_min(), gammalib::str(), gammalib::todouble(), and gammalib::tolower().

Referenced by GModelSpatialRadialProfileGauss::read(), GModelSpatialRadialProfileDMBurkert::read(), GModelSpatialRadialProfileDMEinasto::read(), GModelSpatialRadialProfileDMZhao::read(), GCTAModelSpatialGradient::read(), GCOMModelDRBFitting::read(), GModelTemporalConst::read(), GModelSpatialDiffuseConst::read(), GModelSpatialRadialDisk::read(), GModelSpatialRadialGauss::read(), GModelSpatialPointSource::read(), GCTAModelRadialGauss::read(), GModelSpatialEllipticalDisk::read(), GCTAModelRadialPolynom::read(), GModelSpatialEllipticalGauss::read(), GCTAModelRadialProfile::read(), GModelSpatialDiffuseMap::read(), GModelTemporalLightCurve::read(), GCTAModelSpatialLookup::read(), GModelSpectralConst::read(), GModelSpatialRadial::read(), GModelSpatialElliptical::read(), GModelSpatialRadialShell::read(), GModelSpectralFunc::read(), GModelSpatialDiffuseCube::read(), GModelSpectralGauss::read(), GModelSpectralPlaw::read(), GModelSpectralExpPlaw::read(), GModelSpectralLogParabola::read(), GModelSpectralBrokenPlaw::read(), GModelSpectralExpInvPlaw::read(), GModelSpectralSuperExpPlaw::read(), GModelTemporalPhaseCurve::read(), GModelSpectralPlawPhotonFlux::read(), GModelSpectralPlawEnergyFlux::read(), GModelSpectralNodes::read(), GModelSpectralSmoothBrokenPlaw::read(), and GModel::read_scales().

void GModelPar::write ( GXmlElement xml) const

Set or update parameter attributes in XML element.

Parameters
[in]xmlXML element.

Sets or updates the parameter attributes in an XML element of the form

<parameter name=".." value=".." error=".." scale=".." min=".." max="..' free="..">

The following attributes will be set:

@p name
@p value
@p error (only in case that the parameter is free)
@p scale
@p min (only in case that a minimum exists)
@p max (only in case that a maximum exists)
@p free

Definition at line 353 of file GModelPar.cpp.

References GXmlElement::attribute(), GOptimizerPar::has_max(), GOptimizerPar::has_min(), GOptimizerPar::is_free(), GOptimizerPar::m_factor_error, GOptimizerPar::m_factor_max, GOptimizerPar::m_factor_min, GOptimizerPar::m_factor_value, GOptimizerPar::m_name, GOptimizerPar::m_scale, and gammalib::str().

Referenced by GModelSpatialRadialProfileGauss::write(), GModelSpatialRadialProfileDMBurkert::write(), GModelSpatialRadialProfileDMEinasto::write(), GModelSpatialRadialProfileDMZhao::write(), GCTAModelSpatialGradient::write(), GCOMModelDRBFitting::write(), GModelTemporalConst::write(), GModelSpatialDiffuseConst::write(), GModelSpatialRadialDisk::write(), GModelSpatialPointSource::write(), GModelSpatialRadialGauss::write(), GCTAModelRadialGauss::write(), GModelSpatialEllipticalDisk::write(), GModelSpatialEllipticalGauss::write(), GCTAModelRadialProfile::write(), GModelSpatialDiffuseMap::write(), GModelTemporalLightCurve::write(), GCTAModelSpatialLookup::write(), GModelSpectralConst::write(), GModelSpatialRadial::write(), GModelSpatialElliptical::write(), GModelSpatialRadialShell::write(), GModelSpectralFunc::write(), GModelSpectralGauss::write(), GModelSpatialDiffuseCube::write(), GModelSpectralPlaw::write(), GModelSpectralExpPlaw::write(), GModelSpectralLogParabola::write(), GModelSpectralBrokenPlaw::write(), GModelSpectralExpInvPlaw::write(), GModelSpectralSuperExpPlaw::write(), GModelTemporalPhaseCurve::write(), GModelSpectralPlawPhotonFlux::write(), GModelSpectralPlawEnergyFlux::write(), GModelSpectralNodes::write(), and GModelSpectralSmoothBrokenPlaw::write().


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