Commit 0492179ee69ea606ace143b2a9847512b2a98005

Authored by knodlseder
1 parent a6683935

use simple model derivative computation

include/GObservation.hpp
... ... @@ -90,14 +90,16 @@ public:
90 90 const GEvents* events(void) const;
91 91 const std::string& statistics(void) const { return m_statistics; }
92 92  
  93 + // Other methods
  94 + virtual double model_grad(const GModel& model, const GEvent& event, int ipar) const;
  95 + virtual double npred_grad(const GModel& model, int ipar) const;
  96 +
93 97 protected:
94 98 // Protected methods
95 99 void init_members(void);
96 100 void copy_members(const GObservation& obs);
97 101 void free_members(void);
98 102  
99   - // Model methods
100   - virtual double model_grad(const GModel& model, const GEvent& event, int ipar) const;
101 103  
102 104 // Model gradient kernel classes
103 105 class model_func : public GFunction {
... ... @@ -119,7 +121,6 @@ protected:
119 121 };
120 122  
121 123 // Npred methods
122   - virtual double npred_grad(const GModel& model, int ipar) const;
123 124 virtual double npred_temp(const GModel& model) const;
124 125 virtual double npred_spec(const GModel& model, const GTime& obsTime) const;
125 126  
... ...
src/obs/GObservation.cpp
... ... @@ -425,6 +425,12 @@ void GObservation::free_members(void)
425 425 * @param[in] event Event.
426 426 * @param[in] ipar Parameter index for which gradient should be returned.
427 427 *
  428 + * This method uses a robust but dumb method to estimate parameter
  429 + * gradients that have not been provided by the model. We use here a dumb
  430 + * method as this method is likely used for spatial model parameters, and
  431 + * the spatial model may eventually be noisy due to numerical integration
  432 + * limits.
  433 + *
428 434 * @todo We simply remove any parameter boundaries here for the computation
429 435 * to avoid any out of boundary errors. We may have models, however,
430 436 * for which out of bound parameters lead to illegal computations, such
... ... @@ -461,13 +467,12 @@ double GObservation::model_grad(const GModel& model, const GEvent& event,
461 467 // Setup derivative function
462 468 GObservation::model_func function(this, model, event, ipar);
463 469  
464   - // Get derivative
  470 + // Get derivative. We use a fixed step size here that has been
  471 + // checked on spatial parameters of models
465 472 GDerivative derivative(&function);
466 473 double x = model[ipar].value();
467   - double dx = 0.1;
468   - derivative.eps(1.0e-4);
469   - //derivative.silent(true);
470   - grad = derivative.value(x, dx);
  474 + double dx = 0.05;
  475 + grad = derivative.difference(x, dx);
471 476  
472 477 // Restore current model parameter
473 478 (*ptr)[ipar] = current;
... ...