42 #define G_AT "GObservations::at(int&)"
43 #define G_SET "GObservations::set(int&, GObservation&)"
44 #define G_APPEND "GObservations::append(GObservation&)"
45 #define G_INSERT "GObservations::insert(int&, GObservation&)"
46 #define G_REMOVE "GObservations::remove(int&)"
47 #define G_EXTEND "GObservations::extend(GObservations&)"
48 #define G_READ "GObservations::read(GXml&)"
49 #define G_NPRED "GObservations::npred(std::string&, std::string&)"
211 if (index < 0 || index >=
size()) {
235 if (index < 0 || index >=
size()) {
264 #if defined(G_RANGE_CHECK)
265 if (index < 0 || index >=
size()) {
274 if (inx != -1 && inx != index) {
276 "Attempt to set \""+obs.
instrument()+
"\" observation with"
277 " identifier \""+obs.
id()+
"\" in observation container at"
278 " index "+
gammalib::str(index)+
", but an observation with the"
279 " same attributes exists already at index "+
gammalib::str(inx)+
280 " in the container.\n"
281 "Every observation for a given instrument in the observation"
282 " container needs a unique identifier.";
287 if (
m_obs[index] != NULL)
delete m_obs[index];
316 "Attempt to append \""+obs.
instrument()+
"\" observation with"
317 " identifier \""+obs.
id()+
"\" to observation container, but an"
318 " observation with the same attributes exists already at"
320 "Every observation for a given instrument in the observation"
321 " container needs a unique identifier.";
329 m_obs.push_back(ptr);
355 #if defined(G_RANGE_CHECK)
363 if (index < 0 || index >=
size()) {
373 if (inx != -1 && inx != index) {
375 "Attempt to insert \""+obs.
instrument()+
"\" observation with"
376 " identifier \""+obs.
id()+
"\" in observation container before"
377 " index "+
gammalib::str(index)+
", but an observation with the"
378 " same attributes exists already at index "+
gammalib::str(inx)+
379 " in the container.\n"
380 "Every observation for a given instrument in the observation"
381 " container needs a unique identifier.";
409 #if defined(G_RANGE_CHECK)
410 if (index < 0 || index >=
size()) {
446 int num = obs.
size();
453 for (
int i = 0; i < num; ++i) {
457 int inx =
get_index(obs[i]->instrument(), obs[i]->
id());
460 "Attempt to append \""+obs[i]->instrument()+
"\""
461 " observation with identifier \""+obs[i]->id()+
"\""
462 " to observation container, but an observation with the"
463 " same attributes exists already at index "+
465 "Every observation for a given instrument in the"
466 " observation container needs a unique identifier.";
494 const std::string&
id)
const
500 return (index != -1);
595 int n = lib->
elements(
"observation");
596 for (
int i = 0; i < n; ++i) {
602 std::string name = obs->
attribute(
"name");
604 std::string instrument = obs->
attribute(
"instrument");
624 std::string msg =
"Instrument \""+instrument+
"\" unknown. The "
625 "following instruments are available: "+
626 registry.
content()+
". Please specify one of "
627 "the available instruments.";
657 if (xml.
elements(
"observation_list") == 0) {
665 for (
int i = 0; i <
size(); ++i) {
671 int n = xml.
elements(
"observation");
672 for (
int k = 0; k < n; ++k) {
685 obs = lib->
append(
"observation");
692 m_obs[i]->write(*obs);
775 int npars = pars.
size();
781 bool diag_loaded =
false;
784 for (
int i = 0; i < 2; ++i) {
790 for (
int ipar = 0; ipar < npars; ++ipar) {
793 if (x[ipar] >= 0.0) {
794 pars[ipar]->factor_error(
sqrt(x[ipar]));
797 pars[ipar]->factor_error(0.0);
808 std::cout <<
"Non-Positive definite hessian matrix encountered."
810 std::cout <<
"Load diagonal elements with 1e-10."
811 <<
" Fit errors may be inaccurate."
815 for (
int ipar = 0; ipar < npars; ++ipar) {
816 hessian(ipar,ipar) += 1.0e-10;
829 std::cout <<
"Non-Positive definite hessian matrix encountered,"
830 <<
" even after diagonal loading." << std::endl;
834 catch (std::exception &e) {
880 for (
int i = 0; i <
size(); ++i) {
881 nobserved += (*this)[i]->nobserved();
903 const std::string& instrument)
const
910 std::string msg =
"Model \""+name+
"\" not found in observation "
911 "container. Please specify a valid model name.";
920 npred = this->
npred(*model, instrument);
942 const std::string& instrument)
const
948 for (
int i = 0; i <
size(); ++i) {
952 if (!instrument.empty()) {
953 if ((*
this)[i]->instrument() != instrument) {
959 if (model.
is_valid(instrument,
"")) {
960 npred += (*this)[i]->npred(model);
998 for (
int i = 0; i <
size(); ++i) {
999 (*this)[i]->remove_response_cache(name);
1022 result.append(
"=== GObservations ===");
1039 for (
int i = 0; i <
size(); ++i) {
1040 result.append(
"\n");
1041 result.append((*
this)[i]->
print(reduced_chatter));
1094 for (
int i = 0; i < obs.
m_obs.size(); ++i) {
1118 for (
int i = 0; i <
m_obs.size(); ++i) {
1141 const std::string&
id)
const
1147 for (
int i = 0; i <
size(); ++i) {
1148 if ((
m_obs[i]->instrument() == instrument) &&
1149 (
m_obs[i]->id() == id)) {
GObservations * clone(void) const
Clone observations.
Abstract model base class interface definition.
virtual void read(const GXmlElement &xml)=0
GObservation * alloc(const std::string &name) const
Allocate observation of given name.
Sparse matrix class interface definition.
void save(const GFilename &filename) const
Save XML document into file.
virtual std::string instrument(void) const =0
XML class interface definition.
void save(const GFilename &filename) const
Save observations into XML file.
Optimizer parameter container class.
GOptimizerPars pars(void) const
Return optimizer parameter container.
GMatrixSparse hessian(const GOptimizerPars &pars)
Compute Hessian matrix.
GObservation * append(const GObservation &obs)
Append observation to container.
virtual int elements(void) const
Return number of GXMLElement children of node.
bool contains(const std::string &instrument, const std::string &id) const
Signals if observation exists.
void errors(GOptimizer &opt)
Computes parameter errors using optimizer.
void id(const std::string &id)
Set observation identifier.
Abstract optimizer abstract base class interface definition.
const GModels & models(void) const
Return model container.
bool is_valid(const std::string &instruments, const std::string &ids) const
Verifies if model is valid for a given instrument and identifier.
virtual ~GObservations(void)
Destructor.
std::string print(const GChatter &chatter=NORMAL) const
Print observation list information.
GObservation * set(const int &index, const GObservation &obs)
Set observation in container.
void clear(void)
Clear object.
std::string content(void) const
Return list of names in registry.
void copy_members(const GObservations &obs)
Copy class members.
std::vector< GObservation * > m_obs
List of observations.
void errors_hessian(void)
Computes parameter errors using hessian matrix and optimizer.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
void set(GObservations *obs)
Set observation container.
GObservations(void)
Void constructor.
GXmlElement * element(const int &index)
Return pointer to child element.
bool is_empty(void) const
Signals if there are no observations in container.
int elements(void) const
Return number of child elements in XML document root.
GModels m_models
List of models.
virtual void optimize(GOptimizerFunction &fct, GOptimizerPars &pars)=0
const GXmlAttribute * attribute(const int &index) const
Return attribute.
GObservations & operator=(const GObservations &obs)
Assignment operator.
double npred(void) const
Return total number of predicted events in models.
Interface definition for the observation registry class.
int get_index(const std::string &instrument, const std::string &id) const
Return observation index by instrument and identifier.
void read(const GXml &xml)
Read observations from XML document.
Observation registry class definition.
void init_members(void)
Initialise class members.
Abstract optimizer abstract base class.
virtual GObservation * clone(void) const =0
Clones object.
void optimize(GOptimizer &opt)
Optimize model parameters using optimizer.
Abstract observation base class.
int size(void) const
Return number of observations in container.
void eval(void)
Evaluate function.
Observation container class.
GObservation * insert(const int &index, const GObservation &obs)
Insert observation into container.
virtual void eval(const GOptimizerPars &pars)
Evaluate log-likelihood function.
virtual void errors(GOptimizerFunction &fct, GOptimizerPars &pars)=0
void name(const std::string &name)
Set observation name.
std::string url(void) const
Return Uniform Resource Locator (URL)
int nobserved(void) const
Return total number of observed events.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
void load(const GFilename &filename)
Load models from XML file.
void extend(const GObservations &obs)
Append observations from observation container.
void write(GXml &xml) const
Write observations into XML document.
bool contains(const std::string &name) const
Signals if model name exists.
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.
Sparse matrix class definition.
std::string print(const GChatter &chatter=NORMAL) const
Print models.
GVector cholesky_solver(const GVector &vector, const bool &compress=true) const
Cholesky solver.
Exception handler interface definition.
int size(void) const
Return number of parameters in container.
void load(const GFilename &filename)
Load observations from XML file.
void clear(void)
Clear observations.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void free_members(void)
Delete class members.
void remove_response_cache(void)
Remove response cache for all models.
GObservations::likelihood m_fct
Optimizer function.
Observations container class interface definition.
GMatrixSparse cholesky_decompose(const bool &compress=true) const
Return Cholesky decomposition.
GObservation * at(const int &index)
Return pointer to observation.
int size(void) const
Return number of models in container.
void remove(const int &index)
Remove observation from container.
Filename class interface definition.
GXmlNode * append(const GXmlNode &node)
Append child node to XML document root.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
void reserve(const int &num)
Reserves space for observations in container.