GammaLib
2.0.0
|
Optimizer parameter container class. More...
#include <GOptimizerPars.hpp>
Public Member Functions | |
GOptimizerPars (void) | |
Void constructor. More... | |
GOptimizerPars (const int &number) | |
Parameter constructor. More... | |
GOptimizerPars (const GOptimizerPars &pars) | |
Copy constructor. More... | |
virtual | ~GOptimizerPars (void) |
Destructor. More... | |
GOptimizerPars & | operator= (const GOptimizerPars &pars) |
Assignment operator. More... | |
GOptimizerPar * | operator[] (const int &index) |
Return pointer to parameter. More... | |
const GOptimizerPar * | operator[] (const int &index) const |
Return pointer to parameter (const version) More... | |
GOptimizerPar * | operator[] (const std::string &name) |
Return pointer to parameter. More... | |
const GOptimizerPar * | operator[] (const std::string &name) const |
Return pointer to parameter (const version) More... | |
void | clear (void) |
Clear parameter container. More... | |
GOptimizerPars * | clone (void) const |
Clone parameter container. More... | |
std::string | classname (void) const |
Return class name. More... | |
GOptimizerPar * | at (const int &index) |
Return pointer to parameter. More... | |
const GOptimizerPar * | at (const int &index) const |
Return pointer to parameter (const version) More... | |
int | size (void) const |
Return number of parameters in container. More... | |
bool | is_empty (void) const |
Signals if there are no parameters in container. More... | |
int | nfree (void) const |
Return number of free parameters. More... | |
GOptimizerPar * | set (const int &index, const GOptimizerPar &par) |
Set parameter in container. More... | |
GOptimizerPar * | set (const std::string &name, const GOptimizerPar &par) |
Set parameter in container. More... | |
GOptimizerPar * | append (const GOptimizerPar &par) |
Append parameter to container. More... | |
void | attach (GOptimizerPar *par) |
Attach parameter to container. More... | |
void | attach (const int &index, GOptimizerPar *par) |
Attach parameter to container at the specified index. More... | |
void | attach (const std::string &name, GOptimizerPar *par) |
Attach parameter to container at the specified index. More... | |
GOptimizerPar * | insert (const int &index, const GOptimizerPar &par) |
Insert parameter into container. More... | |
GOptimizerPar * | insert (const std::string &name, const GOptimizerPar &par) |
Insert parameter into container. More... | |
void | remove (const int &index) |
Remove parameter from container. More... | |
void | remove (const std::string &name) |
Remove parameter from container. More... | |
void | reserve (const int &num) |
Reserves space for parameters in container. More... | |
void | extend (const GOptimizerPars &pars) |
Append parameter container. More... | |
bool | contains (const std::string &name) const |
Signals if parameter name exists. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print parameters. More... | |
Public Member Functions inherited from GContainer | |
virtual | ~GContainer (void) |
Destructor. 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 GOptimizerPars &pars) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
int | get_index (const std::string &name) const |
Return parameter index by name. More... | |
Protected Attributes | |
std::vector< GOptimizerPar * > | m_pars |
List of parameters. More... | |
std::vector< bool > | m_alloc |
Flags allocation. More... | |
Optimizer parameter container class.
This class is a container class for parameters of a function that are to be optimized. The optimizer function is defined by the abstract GOptimizerFunction class.
The class holds a flat array of pointers to optimizer parameters. The class can deal with parameters that are allocated by the class itself, or with pointers that are passed by a client and allocated/deallocated by the client.
Definition at line 51 of file GOptimizerPars.hpp.
GOptimizerPars::GOptimizerPars | ( | void | ) |
Void constructor.
Definition at line 65 of file GOptimizerPars.cpp.
References init_members().
Referenced by clone().
|
explicit |
Parameter constructor.
[in] | number | Number of parameters to allocate. |
Allocates number
parameters in the parameter container.
Definition at line 82 of file GOptimizerPars.cpp.
References init_members(), m_alloc, m_pars, and gammalib::number().
GOptimizerPars::GOptimizerPars | ( | const GOptimizerPars & | pars | ) |
Copy constructor.
[in] | pars | Optimizer parameters. |
Definition at line 103 of file GOptimizerPars.cpp.
References copy_members(), and init_members().
|
virtual |
GOptimizerPar * GOptimizerPars::append | ( | const GOptimizerPar & | par | ) |
Append parameter to container.
[in] | par | Parameter reference. |
Appends a parameter to the container. The method stores a copy of the parameter in the container, hence the client may delete the parameter after the method is called.
Definition at line 405 of file GOptimizerPars.cpp.
References GOptimizerPar::clone(), m_alloc, and m_pars.
GOptimizerPar * GOptimizerPars::at | ( | const int & | index | ) |
Return pointer to parameter.
[in] | index | Parameter index [0,...,size()-1]. |
GException::out_of_range | Extension number is out of range. |
Returns a pointer to the parameter with the specified index
.
Definition at line 264 of file GOptimizerPars.cpp.
const GOptimizerPar * GOptimizerPars::at | ( | const int & | index | ) | const |
Return pointer to parameter (const version)
[in] | index | Parameter index [0,...,size()-1]. |
GException::out_of_range | Extension number is out of range. |
Returns a pointer to the parameter with the specified index
.
Definition at line 289 of file GOptimizerPars.cpp.
void GOptimizerPars::attach | ( | GOptimizerPar * | par | ) |
Attach parameter to container.
[in] | par | Parameter pointer. |
Definition at line 424 of file GOptimizerPars.cpp.
References m_alloc, and m_pars.
Referenced by attach(), and GModels::pars().
void GOptimizerPars::attach | ( | const int & | index, |
GOptimizerPar * | par | ||
) |
Attach parameter to container at the specified index.
[in] | index | Parameter index [0,...,size()-1]. |
[in] | par | Parameter pointer. |
GException::out_of_range | Parameter index is not valid. |
Attaches parameter pointer at the specified index
.
Definition at line 448 of file GOptimizerPars.cpp.
void GOptimizerPars::attach | ( | const std::string & | name, |
GOptimizerPar * | par | ||
) |
Attach parameter to container at the specified index.
[in] | name | Parameter name. |
[in] | par | Parameter pointer. |
GException::out_of_range | Parameter index is not valid. |
Attaches parameter pointer at the specified index
.
Definition at line 482 of file GOptimizerPars.cpp.
References attach(), G_ATTACH2, and get_index().
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 110 of file GOptimizerPars.hpp.
|
virtual |
Clear parameter container.
Removes all parameters from the container.
Implements GBase.
Definition at line 229 of file GOptimizerPars.cpp.
References free_members(), and init_members().
|
virtual |
Clone parameter container.
Implements GBase.
Definition at line 247 of file GOptimizerPars.cpp.
References GOptimizerPars().
bool GOptimizerPars::contains | ( | const std::string & | name | ) | const |
Signals if parameter name exists.
[in] | name | Parameter name. |
name
exists.Searches all parameter names for a match with the specified name
. If the specified name has been found, true is returned.
Definition at line 673 of file GOptimizerPars.cpp.
References get_index().
|
protected |
Copy class members.
[in] | pars | Optimizer parameters. |
Definition at line 744 of file GOptimizerPars.cpp.
References m_alloc, m_pars, and size().
Referenced by GOptimizerPars(), and operator=().
void GOptimizerPars::extend | ( | const GOptimizerPars & | pars | ) |
Append parameter container.
[in] | pars | Parameter container. |
Append parameter container to the container. All parameters that were allocated within pars
will be clones, for the other parameters, the pointers will be copied.
Definition at line 637 of file GOptimizerPars.cpp.
References is_empty(), m_alloc, m_pars, reserve(), and size().
|
protected |
Delete class members.
Definition at line 765 of file GOptimizerPars.cpp.
References m_alloc, m_pars, and size().
Referenced by clear(), operator=(), and ~GOptimizerPars().
|
protected |
Return parameter index by name.
[in] | name | Parameter name. |
Returns parameter index based on the specified name
. If no parameter with the specified name
is found the method returns -1.
Definition at line 789 of file GOptimizerPars.cpp.
References m_pars, and size().
Referenced by attach(), contains(), insert(), operator[](), remove(), and set().
|
protected |
Initialise class members.
Definition at line 728 of file GOptimizerPars.cpp.
References m_alloc, and m_pars.
Referenced by clear(), GOptimizerPars(), and operator=().
GOptimizerPar * GOptimizerPars::insert | ( | const int & | index, |
const GOptimizerPar & | par | ||
) |
Insert parameter into container.
[in] | index | Parameter index [0,...,size()-1]. |
[in] | par | Parameter. |
GException::out_of_range | Parameter index is out of range. |
Set parameter in the container. A deep copy of the parameter will be made.
Definition at line 515 of file GOptimizerPars.cpp.
References GOptimizerPar::clone(), G_INSERT1, m_alloc, m_pars, and size().
Referenced by insert().
GOptimizerPar * GOptimizerPars::insert | ( | const std::string & | name, |
const GOptimizerPar & | par | ||
) |
Insert parameter into container.
[in] | name | Parameter name. |
[in] | par | Parameter. |
GException::invalid_argument | Specified parameter name not found in container. |
Definition at line 546 of file GOptimizerPars.cpp.
References G_INSERT2, get_index(), and insert().
|
inlinevirtual |
Signals if there are no parameters in container.
Signals if the parameters container does not contain any parameter.
Implements GContainer.
Definition at line 168 of file GOptimizerPars.hpp.
References m_pars.
Referenced by extend().
int GOptimizerPars::nfree | ( | void | ) | const |
Return number of free parameters.
Determines the number of free parameters by collecting statistics from all model parameters.
Definition at line 311 of file GOptimizerPars.cpp.
References m_pars, and size().
Referenced by GOptimizerLM::optimize().
GOptimizerPars & GOptimizerPars::operator= | ( | const GOptimizerPars & | pars | ) |
Assignment operator.
[in] | pars | Optimizer parameters. |
Definition at line 141 of file GOptimizerPars.cpp.
References copy_members(), free_members(), and init_members().
|
inline |
Return pointer to parameter.
[in] | index | Parameter index [0,...,size()-1]. |
Returns a pointer to the parameter with the specified index
.
Definition at line 125 of file GOptimizerPars.hpp.
References m_pars.
|
inline |
Return pointer to parameter (const version)
[in] | index | Parameter index [0,...,size()-1]. |
Returns a pointer to the parameter with the specified index
.
Definition at line 140 of file GOptimizerPars.hpp.
References m_pars.
GOptimizerPar * GOptimizerPars::operator[] | ( | const std::string & | name | ) |
Return pointer to parameter.
[in] | name | Parameter name. |
GException::invalid_argument | Parameter with specified name not found in container. |
Returns a pointer to the parameter with the specified name
.
Definition at line 172 of file GOptimizerPars.cpp.
References G_ACCESS, get_index(), and m_pars.
const GOptimizerPar * GOptimizerPars::operator[] | ( | const std::string & | name | ) | const |
Return pointer to parameter (const version)
[in] | name | Parameter name. |
GException::invalid_argument | Parameter with specified name not found in container. |
Returns a pointer to the parameter with the specified name
.
Definition at line 200 of file GOptimizerPars.cpp.
References G_ACCESS, get_index(), and m_pars.
Print parameters.
[in] | chatter | Chattiness. |
Prints all parameters into a string.
Implements GBase.
Definition at line 691 of file GOptimizerPars.cpp.
References m_pars, gammalib::parformat(), SILENT, size(), and gammalib::str().
|
virtual |
Remove parameter from container.
[in] | index | Parameter index [0,...,size()-1]. |
GException::out_of_range | Parameter index is out of range. |
Remove parameter of specified index
from container.
Implements GContainer.
Definition at line 575 of file GOptimizerPars.cpp.
void GOptimizerPars::remove | ( | const std::string & | name | ) |
Remove parameter from container.
[in] | name | Parameter name. |
GException::invalid_argument | Specified parameter name not found in container. |
Definition at line 607 of file GOptimizerPars.cpp.
References G_REMOVE2, and get_index().
|
inlinevirtual |
Reserves space for parameters in container.
[in] | num | Number of parameters. |
Reserves space for num
parameters in the container.
Implements GContainer.
Definition at line 182 of file GOptimizerPars.hpp.
References m_pars.
Referenced by extend().
GOptimizerPar * GOptimizerPars::set | ( | const int & | index, |
const GOptimizerPar & | par | ||
) |
Set parameter in container.
[in] | index | Parameter index [0,...,size()-1]. |
[in] | par | Parameter. |
GException::out_of_range | Parameter index is out of range. |
Set parameter in the container. A deep copy of the parameter will be made.
Definition at line 340 of file GOptimizerPars.cpp.
References GOptimizerPar::clone(), G_SET1, m_alloc, m_pars, and size().
Referenced by set().
GOptimizerPar * GOptimizerPars::set | ( | const std::string & | name, |
const GOptimizerPar & | par | ||
) |
Set parameter in container.
[in] | name | Parameter name. |
[in] | par | Parameter. |
GException::invalid_argument | Specified parameter name not found in container. |
Definition at line 377 of file GOptimizerPars.cpp.
References G_SET2, get_index(), and set().
|
inlinevirtual |
Return number of parameters in container.
Returns the number of parameters in the parameter container.
Implements GContainer.
Definition at line 154 of file GOptimizerPars.hpp.
References m_pars.
Referenced by at(), attach(), copy_members(), GOptimizerLM::errors(), GObservations::errors_hessian(), GObservations::likelihood::eval(), extend(), free_members(), get_index(), GObservations::likelihood::hessian(), insert(), nfree(), GOptimizerLM::optimize(), print(), remove(), set(), and GOptimizerLM::step_size().
|
protected |
Flags allocation.
Definition at line 100 of file GOptimizerPars.hpp.
Referenced by append(), attach(), copy_members(), extend(), free_members(), GOptimizerPars(), init_members(), insert(), remove(), and set().
|
protected |
List of parameters.
Definition at line 99 of file GOptimizerPars.hpp.
Referenced by append(), at(), attach(), copy_members(), extend(), free_members(), get_index(), GOptimizerPars(), init_members(), insert(), is_empty(), nfree(), operator[](), print(), remove(), reserve(), set(), and size().