GammaLib
2.1.0.dev
|
#include <GObservations.hpp>
Public Member Functions | |
likelihood (void) | |
Void constructor. More... | |
likelihood (GObservations *obs) | |
Observations constructor. More... | |
likelihood (const likelihood &fct) | |
Copy constructor. More... | |
~likelihood (void) | |
Destructor. More... | |
likelihood & | operator= (const likelihood &fct) |
Assignment operator. More... | |
virtual void | eval (const GOptimizerPars &pars) |
Evaluate log-likelihood function. More... | |
virtual double | value (void) const |
Return log-likelihood value of optimizer function. More... | |
virtual GVector * | gradient (void) |
Return pointer to gradient vector. More... | |
virtual GMatrixSparse * | curvature (void) |
Return pointer to curvature matrix. More... | |
void | set (GObservations *obs) |
Set observation container. More... | |
double | npred (void) const |
Return total number of predicted events. More... | |
GMatrixSparse | hessian (const GOptimizerPars &pars) |
Compute Hessian matrix. More... | |
GMatrixSparse | covariance (void) const |
Compute covariance matrix. More... | |
void | save (const GFilename &filename) const |
Save likelihood fit results into a CSV or FITS file. More... | |
Public Member Functions inherited from GOptimizerFunction | |
GOptimizerFunction (void) | |
Void constructor. More... | |
GOptimizerFunction (const GOptimizerFunction &fct) | |
Copy constructor. More... | |
virtual | ~GOptimizerFunction (void) |
Destructor. More... | |
virtual GOptimizerFunction & | operator= (const GOptimizerFunction &fct) |
Assignment operator. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const likelihood &fct) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | save_csv (const GFilename &filename) const |
Save likelihood fit results into CSV file. More... | |
void | save_fits (const GFilename &filename) const |
Save likelihood fit results into FITS file. More... | |
std::vector< std::string > | covariance_names (void) const |
Return covariance matrix row and column names. More... | |
Protected Member Functions inherited from GOptimizerFunction | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GOptimizerFunction &fct) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
Protected Attributes | |
double | m_value |
Function value. More... | |
double | m_npred |
Total number of predicted events. More... | |
GVector * | m_gradient |
Pointer to gradient vector. More... | |
GMatrixSparse * | m_curvature |
Pointer to curvature matrix. More... | |
GObservations * | m_this |
Pointer to GObservations object. More... | |
Definition at line 145 of file GObservations.hpp.
GObservations::likelihood::likelihood | ( | void | ) |
Void constructor.
Definition at line 74 of file GObservations_likelihood.cpp.
References init_members().
GObservations::likelihood::likelihood | ( | GObservations * | obs | ) |
Observations constructor.
[in] | obs | Observations container pointer. |
Constructs optimizer from GObservations container. The method copies the pointer to the observation container in the m_this member, making the observation container accessible to the optimizer class.
Definition at line 93 of file GObservations_likelihood.cpp.
References init_members(), and m_this.
GObservations::likelihood::likelihood | ( | const likelihood & | fct | ) |
Copy constructor.
[in] | fct | Optimizer function. |
Definition at line 112 of file GObservations_likelihood.cpp.
References copy_members(), and init_members().
GObservations::likelihood::~likelihood | ( | void | ) |
Destructor.
Definition at line 129 of file GObservations_likelihood.cpp.
References GObservations::free_members().
|
protected |
Copy class members.
[in] | fct | Optimizer. |
Definition at line 686 of file GObservations_likelihood.cpp.
References m_curvature, m_gradient, m_npred, m_this, and m_value.
Referenced by likelihood().
GMatrixSparse GObservations::likelihood::covariance | ( | void | ) | const |
Compute covariance matrix.
The covariance matrix is calculated as the inverse of the curvature matrix. The method retrieves the model scaling factors from the models that are stored with the observations and multiplies the covariance matrix with the scaling factors of the model parameters. Hence the covariance matrix is covariance with respect to the true model values.
If the curvature matrix does not exist, an empty covariance matrix is returned.
Definition at line 600 of file GObservations_likelihood.cpp.
References GMatrixBase::columns(), GMatrixSparse::invert(), and GMatrixBase::rows().
|
protected |
Return covariance matrix row and column names.
Returns the row and column names of the covariance matrix.
Definition at line 839 of file GObservations_likelihood.cpp.
|
inlinevirtual |
Return pointer to curvature matrix.
Returns a pointer to the parameter curvature matrix.
Implements GOptimizerFunction.
Definition at line 414 of file GObservations.hpp.
|
virtual |
Evaluate log-likelihood function.
[in] | pars | Optimizer parameters. |
GException::invalid_statistics | Invalid optimization statistics encountered. |
This method evaluates the -(log-likelihood) function for parameter optimization. It handles both binned and unbinned data and supportes Poisson and Gaussian statistics. Note that different statistics and different analysis methods (binned/unbinned) may be combined.
Implements GOptimizerFunction.
Definition at line 195 of file GObservations_likelihood.cpp.
References GOptimizerPar::factor_gradient(), GOptimizerPars::size(), GMatrixSparse::stack_destroy(), and GMatrixSparse::stack_init().
Referenced by GObservations::eval().
|
protected |
Delete class members.
Definition at line 711 of file GObservations_likelihood.cpp.
|
inlinevirtual |
Return pointer to gradient vector.
Returns a pointer to the parameter gradient vector.
Implements GOptimizerFunction.
Definition at line 400 of file GObservations.hpp.
GMatrixSparse GObservations::likelihood::hessian | ( | const GOptimizerPars & | pars | ) |
Compute Hessian matrix.
[in] | pars | Optimizer parameters. |
Definition at line 370 of file GObservations_likelihood.cpp.
References abs(), GObservations::eval(), GOptimizerPar::factor_value(), GOptimizerPar::is_fixed(), max(), min(), GOptimizerPars::size(), and sqrt().
Referenced by GObservations::errors_hessian().
|
protected |
Initialise class members.
Definition at line 667 of file GObservations_likelihood.cpp.
Referenced by likelihood().
|
inline |
Return total number of predicted events.
Returns the total number of events that is predicted by the models after they have been fitted to the data.
Definition at line 386 of file GObservations.hpp.
Referenced by GObservations::npred().
GObservations::likelihood & GObservations::likelihood::operator= | ( | const likelihood & | fct | ) |
Assignment operator.
[in] | fct | Likelihood function. |
Definition at line 151 of file GObservations_likelihood.cpp.
References GObservations::copy_members(), GObservations::free_members(), GObservations::init_members(), and GOptimizerFunction::operator=().
void GObservations::likelihood::save | ( | const GFilename & | filename | ) | const |
Save likelihood fit results into a CSV or FITS file.
[in] | filename | CSV or FITS filename. |
Saves the likelihood fit results into a CSV or FITS file. The result format depends on the filename extension. If the extension is .fits
or .fit
the file is written into a FITS file, otherwise it is written into a CSV file.
Definition at line 639 of file GObservations_likelihood.cpp.
References GFilename::type().
|
protected |
Save likelihood fit results into CSV file.
[in] | filename | CSV filename. |
Saves the likelihood fit results into a CSV file. For the moment the method only writes the covariance matrix.
Definition at line 734 of file GObservations_likelihood.cpp.
References GCsv::real(), GCsv::save(), GObservations::size(), and GCsv::string().
|
protected |
Save likelihood fit results into FITS file.
[in] | filename | FITS filename. |
Saves the likelihood fit results into a FITS file. For the moment the method only writes the covariance matrix.
Definition at line 776 of file GObservations_likelihood.cpp.
References GFitsTable::append(), GFits::append(), GFits::close(), GFitsTableCol::dim(), GFitsHDU::extname(), GFits::saveto(), and GObservations::size().
|
inline |
Set observation container.
[in] | obs | Pointer to observation container. |
Sets the pointer to the observation container for which the optimizer class should be used.
Definition at line 429 of file GObservations.hpp.
Referenced by GObservations::copy_members(), and GObservations::init_members().
|
inlinevirtual |
Return log-likelihood value of optimizer function.
Returns the log-likelihood value of optimizer function.
Implements GOptimizerFunction.
Definition at line 371 of file GObservations.hpp.
References m_value.
Referenced by GObservations::logL().
|
protected |
Pointer to curvature matrix.
Definition at line 182 of file GObservations.hpp.
Referenced by copy_members().
|
protected |
Pointer to gradient vector.
Definition at line 181 of file GObservations.hpp.
Referenced by copy_members().
|
protected |
Total number of predicted events.
Definition at line 180 of file GObservations.hpp.
Referenced by copy_members().
|
protected |
Pointer to GObservations object.
Definition at line 183 of file GObservations.hpp.
Referenced by copy_members(), and likelihood().
|
protected |
Function value.
Definition at line 179 of file GObservations.hpp.
Referenced by copy_members(), and value().