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//#define G_PREPEND_MODEL_NAME //!< Prepend model name of parameter names
62
63/* __ Debug definitions __________________________________________________ */
64
65
66/*==========================================================================
67 = =
68 = Constructors/destructors =
69 = =
70 ==========================================================================*/
71
72/***********************************************************************//**
73 * @brief Void constructor
74 ***************************************************************************/
76{
77 // Initialise private members for clean destruction
79
80 // Return
81 return;
82}
83
84
85/***********************************************************************//**
86 * @brief XML constructor
87 *
88 * @param[in] xml XML element containing data model information.
89 *
90 * Constructs a multiplicative data model by extracting information from an
91 * XML element. See the read() method for more information about the expected
92 * structure of the XML element.
93 ***************************************************************************/
96{
97 // Initialise members
99
100 // Read information from XML element
101 read(xml);
102
103 // Return
104 return;
105}
106
107
108/***********************************************************************//**
109 * @brief Copy constructor
110 *
111 * @param[in] model Multiplicative data model.
112 ***************************************************************************/
114 GModelData(model)
115{
116 // Initialise members
117 init_members();
118
119 // Copy members
120 copy_members(model);
121
122 // Return
123 return;
124}
125
126
127/***********************************************************************//**
128 * @brief Destructor
129 ***************************************************************************/
131{
132 // Free members
133 free_members();
134
135 // Return
136 return;
137}
138
139
140/*==========================================================================
141 = =
142 = Operators =
143 = =
144 ==========================================================================*/
145
146/***********************************************************************//**
147 * @brief Assignment operator
148 *
149 * @param[in] model Multiplicative data model.
150 * @return Multiplicative data model.
151 ***************************************************************************/
153{
154 // Execute only if object is not identical
155 if (this != &model) {
156
157 // Copy base class members
158 this->GModelData::operator=(model);
159
160 // Free members
161 free_members();
162
163 // Initialise members
164 init_members();
165
166 // Copy members
167 copy_members(model);
168
169 } // endif: object was not identical
170
171 // Return
172 return *this;
173}
174
175
176/*==========================================================================
177 = =
178 = Public methods =
179 = =
180 ==========================================================================*/
181
182/***********************************************************************//**
183 * @brief Clear multiplicative data model
184 ***************************************************************************/
186{
187 // Free class members (base and derived classes, derived class first)
188 free_members();
190
191 // Initialise members
193 init_members();
194
195 // Return
196 return;
197}
198
199
200/***********************************************************************//**
201 * @brief Clone multiplicative data model
202 *
203 * @return Pointer to deep copy of multiplicative data model.
204 ***************************************************************************/
206{
207 // Clone multiplicative data model
208 return new GModelDataMultiplicative(*this);
209}
210
211
212/***********************************************************************//**
213 * @brief Return if model is constant
214 *
215 * @return True if model is constant.
216 ***************************************************************************/
218{
219 // Initialise constancy
220 bool constant = true;
221
222 // If one of the components is not constant than signal non constancy
223 for (int i = 0; i < m_models.size(); ++i) {
224 if (m_models[i]->is_constant() == false) {
225 constant = false;
226 break;
227 }
228 }
229
230 // Return constancy
231 return constant;
232}
233
234
235/***********************************************************************//**
236 * @brief Return model values and gradients
237 *
238 * @param[in] event Event.
239 * @param[in] obs Observation.
240 * @param[in] gradients Compute gradients?
241 * @return Model value.
242 *
243 * Evaluates
244 *
245 * \f[
246 * \prod_{i=0}^{N} {M_{\rm i}}(\rm event, \rm obs)
247 * \f]
248 *
249 * where \f${M_{\rm i}}\f$ is the i-th model component.
250 *
251 * If the @p gradients flag is true the method will also compute the partial
252 * derivatives of each parameter of eachmodel component with respect to the
253 * parameters using
254 *
255 * \f[
256 * \frac{\delta S}{\delta P_{\rm ij}}\prod_{\rm k\neq \rm i}^{n} M_{\rm k}
257 * \f]
258 *
259 * where \f${P_{\rm ij}}\f$ is the j-th parameter of the i-th multiplicative
260 * component, while \f${M_{\rm k}}\f$ is the k-th model component and n the
261 * number of model components.
262 ***************************************************************************/
264 const GObservation& obs,
265 const bool& gradients) const
266{
267 // Initialise result
268 double value = 0.0;
269
270 // Check for available model components
271 if (m_models.size() > 0) {
272
273 // Set first model component
274 value = m_models[0]->eval(event, obs, gradients);
275
276 // Loop over model components
277 for (int i = 1; i < m_models.size(); ++i) {
278 value *= m_models[i]->eval(event, obs, gradients);
279 }
280
281 } // endfor: loop over model components
282
283 // Modify gradients if requested
284 if (gradients) {
285
286 // Loop over model components
287 for (int i = 0; i < m_models.size(); ++i) {
288
289 // Initialise scaling factor
290 double factor = 1.0;
291
292 // Loop over other model components and compute factor
293 for (int j = 0; j < m_models.size(); ++j) {
294 if (i != j) {
295 factor *= m_models[j]->eval(event, obs, false);
296 }
297 }
298
299 // Loop over model parameters
300 for (int ipar = 0; ipar < m_models[i]->size(); ++ipar) {
301
302 // Get reference to model parameter
303 GModelPar& par = m_models[i]->operator[](ipar);
304
305 // Scale parameter gradient
306 par.gradient(par.gradient()*factor);
307
308 } // endfor: loop over model parameters
309
310 } // endfor: loop over models
311
312 } //endif: compute gradients
313
314 // Compile option: Check for NaN/Inf
315 #if defined(G_NAN_CHECK)
316 if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) {
317 std::cout << "*** ERROR: GModelDataMultiplicative::eval():";
318 std::cout << " NaN/Inf encountered";
319 std::cout << " (value=" << value;
320 std::cout << ")" << std::endl;
321 }
322 #endif
323
324 // Return
325 return value;
326}
327
328
329/***********************************************************************//**
330 * @brief Return model values and gradients
331 *
332 * @param[in] obs Observation.
333 * @param[out] gradients Pointer to matrix of gradients.
334 * @param[in] offset Column index of first matrix gradient (not used).
335 * @return Model values.
336 *
337 * @exception GException::invalid_argument
338 * Gradient matrix has wrong number of rows or columns
339 *
340 * Evaluates the model values and parameter gradients for all events in an
341 * observation. Gradients are only returned if the @p gradients pointer is
342 * not NULL.
343 *
344 * The matrix of gradients is a sparse matrix where the number of rows
345 * corresponds to the number of events and the number of columns corresponds
346 * to the number of model parameters (see GObservation::model() method).
347 *
348 * An exception is thrown if the dimension of the @p gradients matrix is not
349 * compatible with the model and the observations.
350 ***************************************************************************/
352 GMatrixSparse* gradients,
353 const int& offset) const
354{
355 // Get number of model parameters and number of events
356 int npars = size();
357 int nevents = obs.events()->size();
358
359 // Initialise gradients flag
360 bool grad = ((gradients != NULL) && (npars > 0));
361
362 // Check matrix consistency
363 if (grad) {
364 if (gradients->columns() != npars) {
365 std::string msg = "Number of "+gammalib::str(gradients->columns())+
366 " columns in gradient matrix differs from number "
367 "of "+gammalib::str(npars)+" parameters "
368 "in model. Please provide a compatible gradient "
369 "matrix.";
371 }
372 if (gradients->rows() != nevents) {
373 std::string msg = "Number of "+gammalib::str(gradients->rows())+
374 " rows in gradient matrix differs from number "
375 "of "+gammalib::str(nevents)+" events in "
376 "observation. Please provide a compatible "
377 "gradient matrix.";
379 }
380 }
381
382 // Allocate values vector
383 GVector values(nevents);
384
385 // If there are model components then set values and gradients
386 if (m_models.size() > 0) {
387
388 // Initialise value vectors
389 std::vector<GVector> component_values(m_models.size());
390
391 // Initialise gradient column offset
392 int ioffset = 0;
393
394 // Evaluate all model components
395 for (int i = 0; i < m_models.size(); ++i) {
396
397 // Compute vector of values and optionally matrix of gradients
398 component_values[i] = m_models[i]->eval(obs, gradients, ioffset);
399
400 // Signal all parameters that will have analytical gradients. These
401 // are all parameters that are free and for which the model provides
402 // analytical gradients.
403 if (grad) {
404 for (int ipar = 0; ipar < m_models[i]->size(); ++ipar) {
405 const GModelPar& par = (*this)[ipar+ioffset];
406 if (par.is_free() && par.has_grad()) {
407 obs.computed_gradient(*this, par);
408 }
409 }
410 } // endif: gradients were requested
411
412 // Update gradient matrix column offset
413 ioffset += m_models[i]->size();
414
415 } // endfor: looped over all model component
416
417 // Re-initialise gradient column offset
418 ioffset = 0;
419
420 // Compute values and optionally gradients
421 for (int i = 0; i < m_models.size(); ++i) {
422
423 // Set or multiply model component values
424 if (i == 0) {
425 values = component_values[i];
426 }
427 else {
428 values *= component_values[i];
429 }
430
431 // Optionally compute gradients
432 if (grad) {
433
434 // Allocate factor vector
435 GVector factor(nevents);
436
437 // Initialise factor vector
438 factor = 1.0;
439
440 // Loop over other model components and compute factor vector
441 for (int j = 0; j < m_models.size(); ++j) {
442 if (i != j) {
443 factor *= component_values[j];
444 }
445 }
446
447 // Multiply all gradient columns with factor vector
448 for (int ipar = 0; ipar < m_models[i]->size(); ++ipar) {
449 gradients->multiply_column(ipar+ioffset, factor);
450 }
451
452 // Increment gradient column offset
453 ioffset += m_models[i]->size();
454
455 } // endif: optionally compute offsets
456
457 } // endfor: loop over model components
458
459 } // endif: there were model components
460
461 // Return values
462 return values;
463}
464
465
466/***********************************************************************//**
467 * @brief Return spatially integrated data model
468 *
469 * @param[in] obsEng Measured event energy.
470 * @param[in] obsTime Measured event time.
471 * @param[in] obs Observation.
472 *
473 * @exception GException::feature_not_implemented
474 * Feature not implemented
475 *
476 * @todo Implement method.
477 ***************************************************************************/
479 const GTime& obsTime,
480 const GObservation& obs) const
481{
482 // Initialise result
483 double npred = 0.0;
484
485 // Throw exception signaling that feature is not yet implemented
487
488 // Return
489 return npred;
490}
491
492
493/***********************************************************************//**
494 * @brief Return simulated events
495 *
496 * @param[in] obs Observation.
497 * @param[in] ran Random number generator.
498 *
499 * @exception GException::feature_not_implemented
500 * Feature not implemented
501 *
502 * @todo Implement method.
503 ***************************************************************************/
505 GRan& ran) const
506{
507 // Initialise new event cube
508 GEvents* events = NULL;
509
510 // Throw exception signaling that feature is not yet implemented
512
513 // Return events
514 return events;
515}
516
517
518/***********************************************************************//**
519 * @brief Read model from XML element
520 *
521 * @param[in] xml XML element.
522 *
523 * @exception GException::invalid_value
524 * Invalid model type specified
525 * Model is not a data model
526 * Model is for an incompatible instrument
527 *
528 * Reads the multiplicative data model from an XML element. The expected
529 * XML format is
530 *
531 * <source name="Model" type="MultiplicativeData" instrument="...">
532 * <source name="Component1" type="DataSpace" instrument="...">
533 * ...
534 * </source>
535 * <source name="Component2" type="DataSpace" instrument="...">
536 * ...
537 * </source>
538 * </source>
539 ***************************************************************************/
541{
542 // Clear models and model parameters
543 m_models.clear();
544 m_pars.clear();
545
546 // Get number of model components
547 int num = xml.elements("source");
548
549 // Read model attributes
550 read_attributes(xml);
551
552 // Loop over model components
553 for (int i = 0; i < num; ++i) {
554
555 // Get model XML element
556 const GXmlElement* source = xml.element("source", i);
557
558 // Get model type
559 std::string type = source->attribute("type");
560
561 // Allocate a model registry object
562 GModelRegistry registry;
563
564 // Read model
565 GModel* ptr = registry.alloc(type);
566
567 // Check that model is known
568 if (ptr == NULL) {
569 std::string msg = "Model type \""+type+"\" unknown. The following "
570 "model types are available: "+registry.content()+
571 ". Please specify one of the available model "
572 "types.";
574 }
575
576 // Check that model is a data model
577 GModelData* model = dynamic_cast<GModelData*>(ptr);
578 if (model == NULL) {
579 std::string msg = "Model type \""+type+"\" is not a data model. "
580 "Please specify a data model.";
582 }
583
584 // Read model from XML file
585 model->read(*source);
586
587 // Check that model
588 if (model->instruments() != instruments()) {
589 std::string msg = "Model \""+model->name()+"\" is for instrument "
590 "\""+model->instruments()+"\" but model container "
591 "is for instrument \""+instruments()+"\". Please "
592 "specify a data model that is compliant with the "
593 "container instrument.";
595 }
596
597 // Append data model component to container
598 append(*model);
599
600 // Free model
601 delete ptr;
602
603 } // endfor: loop over models
604
605 // Return
606 return;
607}
608
609
610/***********************************************************************//**
611 * @brief Write model into XML element
612 *
613 * @param[in] xml XML element.
614 *
615 * Writes the multiplicative data model into an XML element.
616 ***************************************************************************/
618{
619 // Initialise pointer on source
620 GXmlElement* src = NULL;
621
622 // Search corresponding source
623 int n = xml.elements("source");
624 for (int k = 0; k < n; ++k) {
625 GXmlElement* element = xml.element("source", k);
626 if (element->attribute("name") == name()) {
627 src = element;
628 break;
629 }
630 }
631
632 // If no source with corresponding name was found then append one.
633 // Set also the type and the instrument.
634 if (src == NULL) {
635 src = xml.append("source");
636 src->attribute("name", name());
637 src->attribute("type", type());
638 if (instruments().length() > 0) {
639 src->attribute("instrument", instruments());
640 }
641 }
642
643 // Verify model type
645
646 // Loop over model components
647 for (int i = 0; i < m_models.size(); i++) {
648
649 #if defined(G_PREPEND_MODEL_NAME)
650 // Create temporary copy of the data model. This is a kluge to
651 // write out the original parameters.
652 GModelData* cpy = m_models[i]->clone();
653
654 // Loop over parameters of model
655 for (int j = 0; j < cpy->size(); ++j) {
656
657 // Get model parameter and name
658 GModelPar& par = (*cpy)[j];
659 std::string parname = par.name();
660
661 // Check if name contains colon
662 if (gammalib::contains(parname, ":")) {
663
664 // Split at the colon
665 std::vector<std::string> splits = gammalib::split(parname, ":");
666
667 // Use second part of the string to recover original
668 // parameter name
669 par.name(splits[1]);
670
671 }
672
673 } // endfor: loop over parameters
674
675 // Write model component
676 cpy->write(*src);
677
678 // Remove temporary copy
679 delete cpy;
680 #else
681 // Write model component
682 m_models[i]->write(*src);
683 #endif
684
685 } // endfor: loop over model components
686
687 // Write model attributes
688 write_attributes(*src);
689
690 // Return
691 return;
692}
693
694
695/***********************************************************************//**
696 * @brief Append data model component
697 *
698 * @param[in] model Data model component.
699 *
700 * @exception GException::invalid_value
701 * Model with same name exists already in container
702 * Model is for incompatible instrument
703 *
704 * Appends a data model component to the multiplicative data model. If
705 * the instruments for the container was not set the instrument is copied
706 * from the model. Otherwise, the method verifies that the instrument of the
707 * model is the same as of the container.
708 ***************************************************************************/
710{
711 // Check if model with same name exists already in container
712 for (int i = 0; i < m_models.size(); i++) {
713 if (m_models[i]->name() == model.name()) {
714 std::string msg = "Attempt to append model with name \""+
715 model.name()+"\" to multiplicative data model "
716 "container, but a component with the same name "
717 "exists already in the container. Every "
718 "component in the container needs to have a "
719 "unique name.";
721 }
722 }
723
724 // Check that instruments are compliant
725 if (instruments() == "") {
726 instruments(model.instruments());
727 }
728 else if (model.instruments() != instruments()) {
729 std::string msg = "Model \""+model.name()+"\" is for instrument "
730 "\""+model.instruments()+"\" but model container "
731 "is for instrument \""+instruments()+"\". Please "
732 "specify a data model that is compliant with the "
733 "container instrument.";
735 }
736
737 // Append clone of data model to container
738 m_models.push_back(model.clone());
739
740 // Get index of data model
741 int index = m_models.size()-1;
742
743 // Get number of model parameters
744 int npars = m_models[index]->size();
745
746 // Loop over model parameters
747 for (int ipar = 0; ipar < npars; ++ipar) {
748
749 // Get model parameter
750 GModelPar* par = &(m_models[index]->operator[](ipar));
751
752 // Prepend model name to parameter name
753 #if defined(G_PREPEND_MODEL_NAME)
754 par->name(model.name()+":"+par->name());
755 #endif
756
757 // Append model parameter with new name to internal container
758 m_pars.push_back(par);
759
760 } // endfor: loop over model parameters
761
762 // Return
763 return;
764}
765
766
767/***********************************************************************//**
768 * @brief Return data model by index
769 *
770 * @param[in] index Index of data model.
771 * @return Pointer to data model.
772 *
773 * Returns a component of the multiplicative data model by @p index.
774 ***************************************************************************/
776{
777 // Check if index is in validity range
778 if (index >= m_models.size() || index < 0) {
779 throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
780 index, m_models.size());
781 }
782
783 // Return pointer to data model
784 return m_models[index];
785}
786
787
788/***********************************************************************//**
789 * @brief Return data model by name
790 *
791 * @param[in] name Name of data model.
792 * @return Pointer to data model.
793 *
794 * @exception GException::invalid_argument
795 * Model component not found.
796 *
797 * Returns a component of the multiplicative data model by @p name.
798 ***************************************************************************/
799const GModelData* GModelDataMultiplicative::component(const std::string& name) const
800{
801 // Check if model name is found
802 int index = -1;
803 for (int i = 0; i < m_models.size(); ++i) {
804 if (m_models[i]->name() == name) {
805 index = i;
806 break;
807 }
808 }
809
810 // Check if component name was found
811 if (index == -1) {
812 std::string msg = "Model component \""+name+"\" not found. Please "
813 "specify a valid model component name.";
815 }
816
817 // Return pointer to data model
818 return m_models[index];
819}
820
821
822/***********************************************************************//**
823 * @brief Print multiplicative data model information
824 *
825 * @param[in] chatter Chattiness.
826 * @return String containing model information.
827 ***************************************************************************/
828std::string GModelDataMultiplicative::print(const GChatter& chatter) const
829{
830 // Initialise result string
831 std::string result;
832
833 // Continue only if chatter is not silent
834 if (chatter != SILENT) {
835
836 // Append header
837 result.append("=== GModelDataMultiplicative ===");
838
839 // Append information
840 result.append("\n"+gammalib::parformat("Number of components"));
841 result.append(gammalib::str(components()));
842 result.append("\n"+gammalib::parformat("Number of parameters"));
843 result.append(gammalib::str(size()));
844
845 // Print parameter information
846 for (int i = 0; i < size(); ++i) {
847 result.append("\n"+m_pars[i]->print(chatter));
848 }
849
850 } // endif: chatter was not silent
851
852 // Return result
853 return result;
854}
855
856
857/*==========================================================================
858 = =
859 = Private methods =
860 = =
861 ==========================================================================*/
862
863/***********************************************************************//**
864 * @brief Initialise class members
865 ***************************************************************************/
867{
868 // Initialise model type
869 m_type = "MultiplicativeData";
870
871 // Clear models
872 m_models.clear();
873
874 // Return
875 return;
876}
877
878
879/***********************************************************************//**
880 * @brief Copy class members
881 *
882 * @param[in] model Multiplicative data model.
883 ***************************************************************************/
885{
886 // Get number of models
887 int num = model.m_models.size();
888
889 // Copy members
890 m_type = model.m_type;
891
892 // Clone models
893 m_models.clear();
894 for (int i = 0; i < num; ++i) {
895 m_models.push_back(model.m_models[i]->clone());
896 }
897
898 // Store pointers to model parameters
899 m_pars.clear();
900 for (int i = 0; i < m_models.size(); ++i) {
901
902 // Retrieve data model
903 GModelData* model = m_models[i];
904
905 // Loop over parameters
906 for (int ipar = 0; ipar < model->size(); ++ipar) {
907
908 // Get model parameter reference
909 GModelPar& par = model->operator[](ipar);
910
911 // Append model parameter pointer to internal container
912 m_pars.push_back(&par);
913
914 }
915 }
916
917 // Return
918 return;
919}
920
921
922/***********************************************************************//**
923 * @brief Delete class members
924 ***************************************************************************/
926{
927 // Free memory
928 for (int i = 0; i < m_models.size(); ++i) {
929 if (m_models[i] != NULL) {
930 delete m_models[i];
931 }
932 }
933
934 // Clear models
935 m_models.clear();
936
937 // Return
938 return;
939}
#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.
void computed_gradient(const GModel &model, const GModelPar &par) const
Signals that an analytical gradient was computed for a model parameter.
bool is_free(void) const
Signal if parameter is free.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
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