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

#include <GObservations.hpp>

Inheritance diagram for GObservations::likelihood:
GOptimizerFunction

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...
 
likelihoodoperator= (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 GVectorgradient (void)
 Return pointer to gradient vector. More...
 
virtual GMatrixSparsecurvature (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 GOptimizerFunctionoperator= (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...
 
GVectorm_gradient
 Pointer to gradient vector. More...
 
GMatrixSparsem_curvature
 Pointer to curvature matrix. More...
 
GObservationsm_this
 Pointer to GObservations object. More...
 

Detailed Description

Definition at line 145 of file GObservations.hpp.

Constructor & Destructor Documentation

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.

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

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

Member Function Documentation

void GObservations::likelihood::copy_members ( const likelihood fct)
protected

Copy class members.

Parameters
[in]fctOptimizer.

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.

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

std::vector< std::string > GObservations::likelihood::covariance_names ( void  ) const
protected

Return covariance matrix row and column names.

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

GMatrixSparse * GObservations::likelihood::curvature ( void  )
inlinevirtual

Return pointer to curvature matrix.

Returns
Pointer to curvature matrix.

Returns a pointer to the parameter curvature matrix.

Implements GOptimizerFunction.

Definition at line 414 of file GObservations.hpp.

void GObservations::likelihood::eval ( const GOptimizerPars pars)
virtual

Evaluate log-likelihood function.

Parameters
[in]parsOptimizer parameters.
Exceptions
GException::invalid_statisticsInvalid 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().

void GObservations::likelihood::free_members ( void  )
protected

Delete class members.

Definition at line 711 of file GObservations_likelihood.cpp.

GVector * GObservations::likelihood::gradient ( void  )
inlinevirtual

Return pointer to gradient vector.

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

Parameters
[in]parsOptimizer parameters.
Returns
Hessian matrix.

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

void GObservations::likelihood::init_members ( void  )
protected

Initialise class members.

Definition at line 667 of file GObservations_likelihood.cpp.

Referenced by likelihood().

double GObservations::likelihood::npred ( void  ) const
inline

Return total number of predicted events.

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

Parameters
[in]fctLikelihood function.
Returns
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.

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

void GObservations::likelihood::save_csv ( const GFilename filename) const
protected

Save likelihood fit results into CSV file.

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

void GObservations::likelihood::save_fits ( const GFilename filename) const
protected

Save likelihood fit results into FITS file.

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

void GObservations::likelihood::set ( GObservations obs)
inline

Set observation container.

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

double GObservations::likelihood::value ( void  ) const
inlinevirtual

Return log-likelihood value of optimizer function.

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

Member Data Documentation

GMatrixSparse* GObservations::likelihood::m_curvature
protected

Pointer to curvature matrix.

Definition at line 182 of file GObservations.hpp.

Referenced by copy_members().

GVector* GObservations::likelihood::m_gradient
protected

Pointer to gradient vector.

Definition at line 181 of file GObservations.hpp.

Referenced by copy_members().

double GObservations::likelihood::m_npred
protected

Total number of predicted events.

Definition at line 180 of file GObservations.hpp.

Referenced by copy_members().

GObservations* GObservations::likelihood::m_this
protected

Pointer to GObservations object.

Definition at line 183 of file GObservations.hpp.

Referenced by copy_members(), and likelihood().

double GObservations::likelihood::m_value
protected

Function value.

Definition at line 179 of file GObservations.hpp.

Referenced by copy_members(), and value().


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