GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GOptimizerPars Class Reference

Optimizer parameter container class. More...

#include <GOptimizerPars.hpp>

Inheritance diagram for GOptimizerPars:
GContainer GBase

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...
 
GOptimizerParsoperator= (const GOptimizerPars &pars)
 Assignment operator. More...
 
GOptimizerParoperator[] (const int &index)
 Return pointer to parameter. More...
 
const GOptimizerParoperator[] (const int &index) const
 Return pointer to parameter (const version) More...
 
GOptimizerParoperator[] (const std::string &name)
 Return pointer to parameter. More...
 
const GOptimizerParoperator[] (const std::string &name) const
 Return pointer to parameter (const version) More...
 
void clear (void)
 Clear parameter container. More...
 
GOptimizerParsclone (void) const
 Clone parameter container. More...
 
std::string classname (void) const
 Return class name. More...
 
GOptimizerParat (const int &index)
 Return pointer to parameter. More...
 
const GOptimizerParat (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...
 
GOptimizerParset (const int &index, const GOptimizerPar &par)
 Set parameter in container. More...
 
GOptimizerParset (const std::string &name, const GOptimizerPar &par)
 Set parameter in container. More...
 
GOptimizerParappend (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...
 
GOptimizerParinsert (const int &index, const GOptimizerPar &par)
 Insert parameter into container. More...
 
GOptimizerParinsert (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

GOptimizerPars::GOptimizerPars ( void  )

Void constructor.

Definition at line 65 of file GOptimizerPars.cpp.

References init_members().

Referenced by clone().

GOptimizerPars::GOptimizerPars ( const int &  number)
explicit

Parameter constructor.

Parameters
[in]numberNumber 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.

Parameters
[in]parsOptimizer parameters.

Definition at line 103 of file GOptimizerPars.cpp.

References copy_members(), and init_members().

GOptimizerPars::~GOptimizerPars ( void  )
virtual

Destructor.

Definition at line 119 of file GOptimizerPars.cpp.

References free_members().

Member Function Documentation

GOptimizerPar * GOptimizerPars::append ( const GOptimizerPar par)

Append parameter to container.

Parameters
[in]parParameter reference.
Returns
Pointer to appended parameter.

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.

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Pointer to parameter.
Exceptions
GException::out_of_rangeExtension number is out of range.

Returns a pointer to the parameter with the specified index.

Definition at line 264 of file GOptimizerPars.cpp.

References G_AT1, m_pars, and size().

const GOptimizerPar * GOptimizerPars::at ( const int &  index) const

Return pointer to parameter (const version)

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Pointer to parameter.
Exceptions
GException::out_of_rangeExtension number is out of range.

Returns a pointer to the parameter with the specified index.

Definition at line 289 of file GOptimizerPars.cpp.

References G_AT1, m_pars, and size().

void GOptimizerPars::attach ( GOptimizerPar par)

Attach parameter to container.

Parameters
[in]parParameter 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.

Parameters
[in]indexParameter index [0,...,size()-1].
[in]parParameter pointer.
Exceptions
GException::out_of_rangeParameter index is not valid.

Attaches parameter pointer at the specified index.

Definition at line 448 of file GOptimizerPars.cpp.

References G_ATTACH1, m_alloc, m_pars, and size().

void GOptimizerPars::attach ( const std::string &  name,
GOptimizerPar par 
)

Attach parameter to container at the specified index.

Parameters
[in]nameParameter name.
[in]parParameter pointer.
Exceptions
GException::out_of_rangeParameter 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().

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

Return class name.

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

Implements GBase.

Definition at line 110 of file GOptimizerPars.hpp.

void GOptimizerPars::clear ( void  )
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().

GOptimizerPars * GOptimizerPars::clone ( void  ) const
virtual

Clone parameter container.

Returns
Pointer to deep copy of 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.

Parameters
[in]nameParameter name.
Returns
True if parameter with specified 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().

void GOptimizerPars::copy_members ( const GOptimizerPars pars)
protected

Copy class members.

Parameters
[in]parsOptimizer 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.

Parameters
[in]parsParameter 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().

void GOptimizerPars::free_members ( void  )
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().

int GOptimizerPars::get_index ( const std::string &  name) const
protected

Return parameter index by name.

Parameters
[in]nameParameter name.
Returns
Parameter index (-1 if parameter name has not been found)

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().

void GOptimizerPars::init_members ( void  )
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.

Parameters
[in]indexParameter index [0,...,size()-1].
[in]parParameter.
Returns
Pointer to deep copy of parameter.
Exceptions
GException::out_of_rangeParameter 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.

Parameters
[in]nameParameter name.
[in]parParameter.
Returns
Pointer to deep copy of parameter.
Exceptions
GException::invalid_argumentSpecified parameter name not found in container.

Definition at line 546 of file GOptimizerPars.cpp.

References G_INSERT2, get_index(), and insert().

bool GOptimizerPars::is_empty ( void  ) const
inlinevirtual

Signals if there are no parameters in container.

Returns
True if container is empty, false otherwise.

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.

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

Parameters
[in]parsOptimizer parameters.
Returns
Optimizer parameters.

Definition at line 141 of file GOptimizerPars.cpp.

References copy_members(), free_members(), and init_members().

GOptimizerPar * GOptimizerPars::operator[] ( const int &  index)
inline

Return pointer to parameter.

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Pointer to parameter.

Returns a pointer to the parameter with the specified index.

Definition at line 125 of file GOptimizerPars.hpp.

References m_pars.

const GOptimizerPar * GOptimizerPars::operator[] ( const int &  index) const
inline

Return pointer to parameter (const version)

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Pointer to parameter.

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.

Parameters
[in]nameParameter name.
Exceptions
GException::invalid_argumentParameter 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)

Parameters
[in]nameParameter name.
Exceptions
GException::invalid_argumentParameter 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.

std::string GOptimizerPars::print ( const GChatter chatter = NORMAL) const
virtual

Print parameters.

Parameters
[in]chatterChattiness.
Returns
String containing parameter container information.

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().

void GOptimizerPars::remove ( const int &  index)
virtual

Remove parameter from container.

Parameters
[in]indexParameter index [0,...,size()-1].
Exceptions
GException::out_of_rangeParameter index is out of range.

Remove parameter of specified index from container.

Implements GContainer.

Definition at line 575 of file GOptimizerPars.cpp.

References G_REMOVE1, m_alloc, m_pars, and size().

void GOptimizerPars::remove ( const std::string &  name)

Remove parameter from container.

Parameters
[in]nameParameter name.
Exceptions
GException::invalid_argumentSpecified parameter name not found in container.

Definition at line 607 of file GOptimizerPars.cpp.

References G_REMOVE2, and get_index().

void GOptimizerPars::reserve ( const int &  num)
inlinevirtual

Reserves space for parameters in container.

Parameters
[in]numNumber 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.

Parameters
[in]indexParameter index [0,...,size()-1].
[in]parParameter.
Returns
Pointer to deep copy of parameter.
Exceptions
GException::out_of_rangeParameter 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.

Parameters
[in]nameParameter name.
[in]parParameter.
Returns
Pointer to deep copy of parameter.
Exceptions
GException::invalid_argumentSpecified parameter name not found in container.

Definition at line 377 of file GOptimizerPars.cpp.

References G_SET2, get_index(), and set().

int GOptimizerPars::size ( void  ) const
inlinevirtual

Return number of parameters in container.

Returns
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().

Member Data Documentation

std::vector<bool> GOptimizerPars::m_alloc
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().

std::vector<GOptimizerPar*> GOptimizerPars::m_pars
protected

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