GModelPar.hpp
6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
* GModelPar.hpp - Model parameter class *
* ----------------------------------------------------------------------- *
* copyright (C) 2009-2013 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GModelPar.hpp
* @brief Model parameter class interface definition
* @author Juergen Knoedlseder
*/
#ifndef GMODELPAR_HPP
#define GMODELPAR_HPP
/* __ Includes ___________________________________________________________ */
#include <string>
#include "GBase.hpp"
#include "GXmlElement.hpp"
/***********************************************************************//**
* @class GModelPar
*
* @brief Model parameter class
*
* This method implements a model parameter. The model parameter is
* factorised into a "value" and a "scale" factor, the real parameter value
* being the product of both. Parameter optimization is only done on the
* "value" part of the parameter. This allows scaling of the parameter to
* have a "value" around unity (which makes the optimizer routines better
* behave). Methods that work on the real value (i.e. the product of
* "value" and "scale") are prefixed with "real_".
*
* The parameter "value" can optionally by bounded by a minimum and/or
* maximum value. Note that the boundaries apply to "value".
*
* Each parameter has a name, and holds optionally information about its
* gradient (if "hasgrad" is true).
***************************************************************************/
class GModelPar : public GBase {
public:
// Constructors and destructors
GModelPar(void);
GModelPar(const std::string& name, const double& value,
const double& scale = 1.0);
GModelPar(const GModelPar& par);
virtual ~GModelPar(void);
// Operators
GModelPar& operator=(const GModelPar& par);
// Methods
void clear(void);
GModelPar* clone(void) const;
std::string name(void) const { return m_name; }
std::string unit(void) const { return m_unit; }
double real_value(void) const { return m_value*m_scale; }
double real_error(void) const { return m_error*m_scale; }
double real_gradient(void) const { return m_gradient*m_scale; }
double real_min(void) const { return m_min*m_scale; }
double real_max(void) const { return m_max*m_scale; }
double value(void) const { return m_value; }
double error(void) const { return m_error; }
double gradient(void) const { return m_gradient; }
double min(void) const { return m_min; }
double max(void) const { return m_max; }
double scale(void) const { return m_scale; }
bool isfree(void) const { return m_free; }
bool hasmin(void) const { return m_hasmin; }
bool hasmax(void) const { return m_hasmax; }
bool hasgrad(void) const { return m_hasgrad; }
void name(const std::string& name) { m_name=name; }
void unit(const std::string& unit) { m_unit=unit; }
void real_value(const double& value);
void real_error(const double& error);
void value(const double& value);
void error(const double& error) { m_error=error; }
void gradient(const double& gradient) { m_gradient=gradient; }
void min(const double& min);
void max(const double& max);
void scale(const double& scale) { m_scale=scale; }
void range(const double& min, const double& max);
void remove_min(void) { m_hasmin=false; }
void remove_max(void) { m_hasmax=false; }
void remove_range(void) { m_hasmin=false; m_hasmax=false; }
void free(void) { m_free=true; }
void fix(void) { m_free=false; }
void hasgrad(const bool& grad) { m_hasgrad=grad; }
void read(const GXmlElement& xml);
void write(GXmlElement& xml) const;
std::string print(void) const;
protected:
// Protected methods
void init_members(void);
void copy_members(const GModelPar& par);
void free_members(void);
// Proteced data members
std::string m_name; //!< Parameter name
std::string m_unit; //!< Parameter unit
double m_value; //!< Parameter value
double m_error; //!< Uncertainty in parameter value
double m_gradient; //!< Model gradient
double m_min; //!< Parameter minimum
double m_max; //!< Parameter maximum
double m_scale; //!< Parameter scale (real = m_value * m_scale)
bool m_free; //!< Parameter is free
bool m_hasmin; //!< Parameter has minimum boundary
bool m_hasmax; //!< Parameter has maximum boundary
bool m_hasgrad; //!< Parameter has analytic gradient
};
#endif /* GMODELPAR_HPP */