GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModelDataMultiplicative.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelDataMultiplicative.cpp - Multiplicative data model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2025 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GModelDataMultiplicative.cpp
23 * @brief Multiplicative data model class implementation
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include "GException.hpp"
32#include "GTools.hpp"
33#include "GRan.hpp"
35#include "GModelRegistry.hpp"
36#include "GObservation.hpp"
37#include "GMatrixSparse.hpp"
38
39/* __ Constants __________________________________________________________ */
40
41/* __ Globals ____________________________________________________________ */
43const GModelRegistry g_data_registry(&g_data_multi_seed);
44
45/* __ Method name definitions ____________________________________________ */
46#define G_EVAL "GModelDataMultiplicative::eval(GObservation&, "\
47 "GMatrixSparse*)"
48#define G_NPRED "GModelDataMultiplicative::npred(GEnergy&, GTime&, "\
49 "GObservation&)"
50#define G_MC "GModelDataMultiplicative::mc(GObservation&, GRan&)"
51#define G_READ "GModelDataMultiplicative::read(GXmlElement&)"
52#define G_WRITE "GModelDataMultiplicative::write(GXmlElement&)"
53#define G_COMPONENT_INDEX "GModelDataMultiplicative::component(int&)"
54#define G_COMPONENT_NAME "GModelDataMultiplicative::component(std::string&)"
55#define G_APPEND "GModelDataMultiplicative::append(GModelData&, "\
56 "std::string&)"
57
58/* __ Macros _____________________________________________________________ */
59
60/* __ Coding definitions _________________________________________________ */
61
62/* __ Debug definitions __________________________________________________ */
63
64
65/*==========================================================================
66 = =
67 = Constructors/destructors =
68 = =
69 ==========================================================================*/
70
71/***********************************************************************//**
72 * @brief Void constructor
73 ***************************************************************************/
75{
76 // Initialise private members for clean destruction
78
79 // Return
80 return;
81}
82
83
84/***********************************************************************//**
85 * @brief XML constructor
86 *
87 * @param[in] xml XML element containing data model information.
88 *
89 * Constructs a multiplicative data model by extracting information from an
90 * XML element. See the read() method for more information about the expected
91 * structure of the XML element.
92 ***************************************************************************/
95{
96 // Initialise members
98
99 // Read information from XML element
100 read(xml);
101
102 // Return
103 return;
104}
105
106
107/***********************************************************************//**
108 * @brief Copy constructor
109 *
110 * @param[in] model Multiplicative data model.
111 ***************************************************************************/
113 GModelData(model)
114{
115 // Initialise members
116 init_members();
117
118 // Copy members
119 copy_members(model);
120
121 // Return
122 return;
123}
124
125
126/***********************************************************************//**
127 * @brief Destructor
128 ***************************************************************************/
130{
131 // Free members
132 free_members();
133
134 // Return
135 return;
136}
137
138
139/*==========================================================================
140 = =
141 = Operators =
142 = =
143 ==========================================================================*/
144
145/***********************************************************************//**
146 * @brief Assignment operator
147 *
148 * @param[in] model Multiplicative data model.
149 * @return Multiplicative data model.
150 ***************************************************************************/
152{
153 // Execute only if object is not identical
154 if (this != &model) {
155
156 // Copy base class members
157 this->GModelData::operator=(model);
158
159 // Free members
160 free_members();
161
162 // Initialise members
163 init_members();
164
165 // Copy members
166 copy_members(model);
167
168 } // endif: object was not identical
169
170 // Return
171 return *this;
172}
173
174
175/*==========================================================================
176 = =
177 = Public methods =
178 = =
179 ==========================================================================*/
180
181/***********************************************************************//**
182 * @brief Clear multiplicative data model
183 ***************************************************************************/
185{
186 // Free class members (base and derived classes, derived class first)
187 free_members();
189
190 // Initialise members
192 init_members();
193
194 // Return
195 return;
196}
197
198
199/***********************************************************************//**
200 * @brief Clone multiplicative data model
201 *
202 * @return Pointer to deep copy of multiplicative data model.
203 ***************************************************************************/
205{
206 // Clone multiplicative data model
207 return new GModelDataMultiplicative(*this);
208}
209
210
211/***********************************************************************//**
212 * @brief Return if model is constant
213 *
214 * @return True if model is constant.
215 ***************************************************************************/
217{
218 // Initialise constancy
219 bool constant = true;
220
221 // If one of the components is not constant than signal non constancy
222 for (int i = 0; i < m_models.size(); ++i) {
223 if (m_models[i]->is_constant() == false) {
224 constant = false;
225 break;
226 }
227 }
228
229 // Return constancy
230 return constant;
231}
232
233
234/***********************************************************************//**
235 * @brief Return model values and gradients
236 *
237 * @param[in] event Event.
238 * @param[in] obs Observation.
239 * @param[in] gradients Compute gradients?
240 * @return Model value.
241 *
242 * Evaluates
243 *
244 * \f[
245 * \prod_{i=0}^{N} {M_{\rm i}}(\rm event, \rm obs)
246 * \f]
247 *
248 * where \f${M_{\rm i}}\f$ is the i-th model component.
249 *
250 * If the @p gradients flag is true the method will also compute the partial
251 * derivatives of each parameter of eachmodel component with respect to the
252 * parameters using
253 *
254 * \f[
255 * \frac{\delta S}{\delta P_{\rm ij}}\prod_{\rm k\neq \rm i}^{n} M_{\rm k}
256 * \f]
257 *
258 * where \f${P_{\rm ij}}\f$ is the j-th parameter of the i-th multiplicative
259 * component, while \f${M_{\rm k}}\f$ is the k-th model component and n the
260 * number of model components.
261 ***************************************************************************/
263 const GObservation& obs,
264 const bool& gradients) const
265{
266 // Initialise result
267 double value = 0.0;
268
269 // Check for available model components
270 if (m_models.size() > 0) {
271
272 // Set first model component
273 value = m_models[0]->eval(event, obs, gradients);
274
275 // Loop over model components
276 for (int i = 1; i < m_models.size(); ++i) {
277 value *= m_models[i]->eval(event, obs, gradients);
278 }
279
280 } // endfor: loop over model components
281
282 // Modify gradients if requested
283 if (gradients) {
284
285 // Loop over model components
286 for (int i = 0; i < m_models.size(); ++i) {
287
288 // Initialise scaling factor
289 double factor = 1.0;
290
291 // Loop over other model components and compute factor
292 for (int j = 0; j < m_models.size(); ++j) {
293 if (i != j) {
294 factor *= m_models[j]->eval(event, obs, false);
295 }
296 }
297
298 // Loop over model parameters
299 for (int ipar = 0; ipar < m_models[i]->size(); ++ipar) {
300
301 // Get reference to model parameter
302 GModelPar& par = m_models[i]->operator[](ipar);
303
304 // Scale parameter gradient
305 par.gradient(par.gradient()*factor);
306
307 } // endfor: loop over model parameters
308
309 } // endfor: loop over models
310
311 } //endif: compute gradients
312
313 // Compile option: Check for NaN/Inf
314 #if defined(G_NAN_CHECK)
315 if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) {
316 std::cout << "*** ERROR: GModelDataMultiplicative::eval():";
317 std::cout << " NaN/Inf encountered";
318 std::cout << " (value=" << value;
319 std::cout << ")" << std::endl;
320 }
321 #endif
322
323 // Return
324 return value;
325}
326
327
328/***********************************************************************//**
329 * @brief Return model values and gradients
330 *
331 * @param[in] obs Observation.
332 * @param[out] gradients Pointer to matrix of gradients.
333 * @param[in] offset Column index of first matrix gradient (not used).
334 * @return Model values.
335 *
336 * @exception GException::invalid_argument
337 * Gradient matrix has wrong number of rows or columns
338 *
339 * Evaluates the model values and parameter gradients for all events in an
340 * observation. Gradients are only returned if the @p gradients pointer is
341 * not NULL.
342 *
343 * The matrix of gradients is a sparse matrix where the number of rows
344 * corresponds to the number of events and the number of columns corresponds
345 * to the number of model parameters (see GObservation::model() method).
346 *
347 * An exception is thrown if the dimension of the @p gradients matrix is not
348 * compatible with the model and the observations.
349 ***************************************************************************/
351 GMatrixSparse* gradients,
352 const int& offset) const
353{
354 // Get number of model parameters and number of events
355 int npars = size();
356 int nevents = obs.events()->size();
357
358 // Initialise gradients flag
359 bool grad = ((gradients != NULL) && (npars > 0));
360
361 // Check matrix consistency
362 if (grad) {
363 if (gradients->columns() != npars) {
364 std::string msg = "Number of "+gammalib::str(gradients->columns())+
365 " columns in gradient matrix differs from number "
366 "of "+gammalib::str(npars)+" parameters "
367 "in model. Please provide a compatible gradient "
368 "matrix.";
370 }
371 if (gradients->rows() != nevents) {
372 std::string msg = "Number of "+gammalib::str(gradients->rows())+
373 " rows in gradient matrix differs from number "
374 "of "+gammalib::str(nevents)+" events in "
375 "observation. Please provide a compatible "
376 "gradient matrix.";
378 }
379 }
380
381 // Allocate values vector
382 GVector values(nevents);
383
384 // If there are model components then set values and gradients
385 if (m_models.size() > 0) {
386
387 // Initialise value vectors
388 std::vector<GVector> component_values(m_models.size());
389
390 // Initialise gradient column offset
391 int ioffset = 0;
392
393 // Evaluate all model components
394 for (int i = 0; i < m_models.size(); ++i) {
395 component_values[i] = m_models[i]->eval(obs, gradients, ioffset);
396 ioffset += m_models[i]->size();
397 }
398
399 // Re-initialise gradient column offset
400 ioffset = 0;
401
402 // Compute values and optionally gradients
403 for (int i = 0; i < m_models.size(); ++i) {
404
405 // Set or multiply model component values
406 if (i == 0) {
407 values = component_values[i];
408 }
409 else {
410 values *= component_values[i];
411 }
412
413 // Optionally compute gradients
414 if (grad) {
415
416 // Allocate factor vector
417 GVector factor(nevents);
418
419 // Initialise factor vector
420 factor = 1.0;
421
422 // Loop over other model components and compute factor vector
423 for (int j = 0; j < m_models.size(); ++j) {
424 if (i != j) {
425 factor *= component_values[j];
426 }
427 }
428
429 // Multiply all gradient columns with factor vector
430 for (int ipar = 0; ipar < m_models[i]->size(); ++ipar) {
431 gradients->multiply_column(ipar+ioffset, factor);
432 }
433
434 // Increment gradient column offset
435 ioffset += m_models[i]->size();
436
437 } // endif: optionally compute offsets
438
439 } // endfor: loop over model components
440
441 } // endif: there were model components
442
443 // Return values
444 return values;
445}
446
447
448/***********************************************************************//**
449 * @brief Return spatially integrated data model
450 *
451 * @param[in] obsEng Measured event energy.
452 * @param[in] obsTime Measured event time.
453 * @param[in] obs Observation.
454 *
455 * @exception GException::feature_not_implemented
456 * Feature not implemented
457 *
458 * @todo Implement method.
459 ***************************************************************************/
461 const GTime& obsTime,
462 const GObservation& obs) const
463{
464 // Initialise result
465 double npred = 0.0;
466
467 // Throw exception signaling that feature is not yet implemented
469
470 // Return
471 return npred;
472}
473
474
475/***********************************************************************//**
476 * @brief Return simulated events
477 *
478 * @param[in] obs Observation.
479 * @param[in] ran Random number generator.
480 *
481 * @exception GException::feature_not_implemented
482 * Feature not implemented
483 *
484 * @todo Implement method.
485 ***************************************************************************/
487 GRan& ran) const
488{
489 // Initialise new event cube
490 GEvents* events = NULL;
491
492 // Throw exception signaling that feature is not yet implemented
494
495 // Return events
496 return events;
497}
498
499
500/***********************************************************************//**
501 * @brief Read model from XML element
502 *
503 * @param[in] xml XML element.
504 *
505 * @exception GException::invalid_value
506 * Invalid model type specified
507 * Model is not a data model
508 * Model is for an incompatible instrument
509 *
510 * Reads the multiplicative data model from an XML element. The expected
511 * XML format is
512 *
513 * <source name="Model" type="MultiplicativeData" instrument="...">
514 * <source name="Component1" type="DataSpace" instrument="...">
515 * ...
516 * </source>
517 * <source name="Component2" type="DataSpace" instrument="...">
518 * ...
519 * </source>
520 * </source>
521 ***************************************************************************/
523{
524 // Clear models and model parameters
525 m_models.clear();
526 m_pars.clear();
527
528 // Get number of model components
529 int num = xml.elements("source");
530
531 // Read model attributes
532 read_attributes(xml);
533
534 // Loop over model components
535 for (int i = 0; i < num; ++i) {
536
537 // Get model XML element
538 const GXmlElement* source = xml.element("source", i);
539
540 // Get model type
541 std::string type = source->attribute("type");
542
543 // Allocate a model registry object
544 GModelRegistry registry;
545
546 // Read model
547 GModel* ptr = registry.alloc(type);
548
549 // Check that model is known
550 if (ptr == NULL) {
551 std::string msg = "Model type \""+type+"\" unknown. The following "
552 "model types are available: "+registry.content()+
553 ". Please specify one of the available model "
554 "types.";
556 }
557
558 // Check that model is a data model
559 GModelData* model = dynamic_cast<GModelData*>(ptr);
560 if (model == NULL) {
561 std::string msg = "Model type \""+type+"\" is not a data model. "
562 "Please specify a data model.";
564 }
565
566 // Read model from XML file
567 model->read(*source);
568
569 // Check that model
570 if (model->instruments() != instruments()) {
571 std::string msg = "Model \""+model->name()+"\" is for instrument "
572 "\""+model->instruments()+"\" but model container "
573 "is for instrument \""+instruments()+"\". Please "
574 "specify a data model that is compliant with the "
575 "container instrument.";
577 }
578
579 // Append data model component to container
580 append(*model);
581
582 // Free model
583 delete ptr;
584
585 } // endfor: loop over models
586
587 // Return
588 return;
589}
590
591
592/***********************************************************************//**
593 * @brief Write model into XML element
594 *
595 * @param[in] xml XML element.
596 *
597 * Writes the multiplicative data model into an XML element.
598 ***************************************************************************/
600{
601 // Initialise pointer on source
602 GXmlElement* src = NULL;
603
604 // Search corresponding source
605 int n = xml.elements("source");
606 for (int k = 0; k < n; ++k) {
607 GXmlElement* element = xml.element("source", k);
608 if (element->attribute("name") == name()) {
609 src = element;
610 break;
611 }
612 }
613
614 // If no source with corresponding name was found then append one.
615 // Set also the type and the instrument.
616 if (src == NULL) {
617 src = xml.append("source");
618 src->attribute("name", name());
619 src->attribute("type", type());
620 if (instruments().length() > 0) {
621 src->attribute("instrument", instruments());
622 }
623 }
624
625 // Verify model type
627
628 // Loop over model components
629 for (int i = 0; i < m_models.size(); i++) {
630
631 // Create temporary copy of the data model. This is a kluge to
632 // write out the original parameters.
633 GModelData* cpy = m_models[i]->clone();
634
635 // Loop over parameters of model
636 for (int j = 0; j < cpy->size(); ++j) {
637
638 // Get model parameter and name
639 GModelPar& par = (*cpy)[j];
640 std::string parname = par.name();
641
642 // Check if name contains colon
643 if (gammalib::contains(parname, ":")) {
644
645 // Split at the colon
646 std::vector<std::string> splits = gammalib::split(parname, ":");
647
648 // Use second part of the string to recover original
649 // parameter name
650 par.name(splits[1]);
651
652 }
653
654 } // endfor: loop over parameters
655
656 // Write model component
657 cpy->write(*src);
658
659 // Remove temporary copy
660 delete cpy;
661
662 } // endfor: loop over model components
663
664 // Write model attributes
665 write_attributes(*src);
666
667 // Return
668 return;
669}
670
671
672/***********************************************************************//**
673 * @brief Append data model component
674 *
675 * @param[in] model Data model component.
676 *
677 * @exception GException::invalid_value
678 * Model with same name exists already in container
679 * Model is for incompatible instrument
680 *
681 * Appends a data model component to the multiplicative data model. If
682 * the instruments for the container was not set the instrument is copied
683 * from the model. Otherwise, the method verifies that the instrument of the
684 * model is the same as of the container.
685 ***************************************************************************/
687{
688 // Check if model with same name exists already in container
689 for (int i = 0; i < m_models.size(); i++) {
690 if (m_models[i]->name() == model.name()) {
691 std::string msg = "Attempt to append model with name \""+
692 model.name()+"\" to multiplicative data model "
693 "container, but a component with the same name "
694 "exists already in the container. Every "
695 "component in the container needs to have a "
696 "unique name.";
698 }
699 }
700
701 // Check that instruments are compliant
702 if (instruments() == "") {
703 instruments(model.instruments());
704 }
705 else if (model.instruments() != instruments()) {
706 std::string msg = "Model \""+model.name()+"\" is for instrument "
707 "\""+model.instruments()+"\" but model container "
708 "is for instrument \""+instruments()+"\". Please "
709 "specify a data model that is compliant with the "
710 "container instrument.";
712 }
713
714 // Append clone of data model to container
715 m_models.push_back(model.clone());
716
717 // Get index of data model
718 int index = m_models.size()-1;
719
720 // Get number of model parameters
721 int npars = m_models[index]->size();
722
723 // Loop over model parameters
724 for (int ipar = 0; ipar < npars; ++ipar) {
725
726 // Get model parameter
727 GModelPar* par = &(m_models[index]->operator[](ipar));
728
729 // Prepend model name to parameter name
730 par->name(model.name()+":"+par->name());
731
732 // Append model parameter with new name to internal container
733 m_pars.push_back(par);
734
735 } // endfor: loop over model parameters
736
737 // Return
738 return;
739}
740
741
742/***********************************************************************//**
743 * @brief Return data model by index
744 *
745 * @param[in] index Index of data model.
746 * @return Pointer to data model.
747 *
748 * Returns a component of the multiplicative data model by @p index.
749 ***************************************************************************/
751{
752 // Check if index is in validity range
753 if (index >= m_models.size() || index < 0) {
754 throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
755 index, m_models.size());
756 }
757
758 // Return pointer to data model
759 return m_models[index];
760}
761
762
763/***********************************************************************//**
764 * @brief Return data model by name
765 *
766 * @param[in] name Name of data model.
767 * @return Pointer to data model.
768 *
769 * @exception GException::invalid_argument
770 * Model component not found.
771 *
772 * Returns a component of the multiplicative data model by @p name.
773 ***************************************************************************/
774const GModelData* GModelDataMultiplicative::component(const std::string& name) const
775{
776 // Check if model name is found
777 int index = -1;
778 for (int i = 0; i < m_models.size(); ++i) {
779 if (m_models[i]->name() == name) {
780 index = i;
781 break;
782 }
783 }
784
785 // Check if component name was found
786 if (index == -1) {
787 std::string msg = "Model component \""+name+"\" not found. Please "
788 "specify a valid model component name.";
790 }
791
792 // Return pointer to data model
793 return m_models[index];
794}
795
796
797/***********************************************************************//**
798 * @brief Print multiplicative data model information
799 *
800 * @param[in] chatter Chattiness.
801 * @return String containing model information.
802 ***************************************************************************/
803std::string GModelDataMultiplicative::print(const GChatter& chatter) const
804{
805 // Initialise result string
806 std::string result;
807
808 // Continue only if chatter is not silent
809 if (chatter != SILENT) {
810
811 // Append header
812 result.append("=== GModelDataMultiplicative ===");
813
814 // Append information
815 result.append("\n"+gammalib::parformat("Number of components"));
816 result.append(gammalib::str(components()));
817 result.append("\n"+gammalib::parformat("Number of parameters"));
818 result.append(gammalib::str(size()));
819
820 // Print parameter information
821 for (int i = 0; i < size(); ++i) {
822 result.append("\n"+m_pars[i]->print(chatter));
823 }
824
825 } // endif: chatter was not silent
826
827 // Return result
828 return result;
829}
830
831
832/*==========================================================================
833 = =
834 = Private methods =
835 = =
836 ==========================================================================*/
837
838/***********************************************************************//**
839 * @brief Initialise class members
840 ***************************************************************************/
842{
843 // Initialise model type
844 m_type = "MultiplicativeData";
845
846 // Clear models
847 m_models.clear();
848
849 // Return
850 return;
851}
852
853
854/***********************************************************************//**
855 * @brief Copy class members
856 *
857 * @param[in] model Multiplicative data model.
858 ***************************************************************************/
860{
861 // Get number of models
862 int num = model.m_models.size();
863
864 // Copy members
865 m_type = model.m_type;
866
867 // Clone models
868 m_models.clear();
869 for (int i = 0; i < num; ++i) {
870 m_models.push_back(model.m_models[i]->clone());
871 }
872
873 // Store pointers to model parameters
874 m_pars.clear();
875 for (int i = 0; i < m_models.size(); ++i) {
876
877 // Retrieve data model
878 GModelData* model = m_models[i];
879
880 // Loop over parameters
881 for (int ipar = 0; ipar < model->size(); ++ipar) {
882
883 // Get model parameter reference
884 GModelPar& par = model->operator[](ipar);
885
886 // Append model parameter pointer to internal container
887 m_pars.push_back(&par);
888
889 }
890 }
891
892 // Return
893 return;
894}
895
896
897/***********************************************************************//**
898 * @brief Delete class members
899 ***************************************************************************/
901{
902 // Free memory
903 for (int i = 0; i < m_models.size(); ++i) {
904 if (m_models[i] != NULL) {
905 delete m_models[i];
906 }
907 }
908
909 // Clear models
910 m_models.clear();
911
912 // Return
913 return;
914}
#define G_WRITE
#define G_READ
#define G_APPEND
Exception handler interface definition.
Sparse matrix class definition.
const GModelDataMultiplicative g_data_multi_seed
#define G_COMPONENT_INDEX
#define G_COMPONENT_NAME
#define G_NPRED
Multiplicative data model class interface definition.
#define G_EVAL
Model registry class definition.
Abstract observation base class interface definition.
Random number generator class definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Abstract interface for the event classes.
Definition GEvent.hpp:71
Abstract event container class.
Definition GEvents.hpp:66
virtual int size(void) const =0
const int & rows(void) const
Return number of matrix rows.
const int & columns(void) const
Return number of matrix columns.
Sparse matrix class interface definition.
void multiply_column(const int &column, const GVector &vector)
Multiply matrix column with vector.
Multiplicative data model class.
void copy_members(const GModelDataMultiplicative &model)
Copy class members.
virtual bool is_constant(void) const
Return if model is constant.
virtual GModelDataMultiplicative & operator=(const GModelDataMultiplicative &model)
Assignment operator.
virtual ~GModelDataMultiplicative(void)
Destructor.
virtual GEvents * mc(const GObservation &obs, GRan &ran) const
Return simulated events.
GModelDataMultiplicative(void)
Void constructor.
virtual void clear(void)
Clear multiplicative data model.
virtual void write(GXmlElement &xml) const
Write model into XML element.
void init_members(void)
Initialise class members.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print multiplicative data model information.
virtual GModelDataMultiplicative * clone(void) const
Clone multiplicative data model.
virtual void read(const GXmlElement &xml)
Read model from XML element.
int components(void) const
Return number of data model components.
void append(const GModelData &model)
Append data model component.
void free_members(void)
Delete class members.
const GModelData * component(const int &index) const
Return data model by index.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Return model values and gradients.
std::vector< GModelData * > m_models
Container of data models.
virtual std::string type(void) const
Return model type.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated data model.
Abstract data model class.
virtual GModelData * clone(void) const =0
Clones object.
void init_members(void)
Initialise class members.
virtual void write(GXmlElement &xml) const =0
void free_members(void)
Delete class members.
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
virtual void read(const GXmlElement &xml)=0
Model parameter class.
Definition GModelPar.hpp:87
Interface definition for the model registry class.
GModel * alloc(const std::string &name) const
Allocate model of given name.
Abstract model class.
Definition GModel.hpp:100
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
Definition GModel.hpp:182
void write_attributes(GXmlElement &xml) const
Write model attributes.
Definition GModel.cpp:738
int size(void) const
Return number of parameters in model.
Definition GModel.hpp:237
std::string instruments(void) const
Returns instruments to which model applies.
Definition GModel.cpp:325
void read_attributes(const GXmlElement &xml)
Read model attributes.
Definition GModel.cpp:699
const std::string & name(void) const
Return parameter name.
Definition GModel.hpp:265
Abstract observation base class.
virtual GEvents * events(void)
Return events.
double gradient(void) const
Return parameter gradient.
const std::string & name(void) const
Return parameter name.
Random number generator class.
Definition GRan.hpp:44
std::string content(void) const
Return list of names in registry.
Definition GRegistry.cpp:54
Time class.
Definition GTime.hpp:55
Vector class.
Definition GVector.hpp:46
XML element node class.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
Definition GXmlNode.cpp:287
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition GXmlNode.cpp:640
virtual int elements(void) const
Return number of GXMLElement children of node.
Definition GXmlNode.cpp:586
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1162
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition GTools.hpp:186
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition GTools.hpp:203
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:508
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
Definition GTools.cpp:1361
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
Definition GTools.cpp:1002
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
Definition GTools.cpp:1838