Commit d6c50a7f605183133d7fbba5e321b89a09fda976
1 parent
5ce52967
Introduce member to set numerical gradient step size and set COMPTEL gradient step size to 0.05 deg.
Showing
3 changed files
with
42 additions
and
34 deletions
include/GObservation.hpp
| ... | ... | @@ -117,6 +117,7 @@ public: |
| 117 | 117 | virtual double npred_grad(const GModel& model, |
| 118 | 118 | const GModelPar& par) const; |
| 119 | 119 | virtual void remove_response_cache(const std::string& name); |
| 120 | + virtual const double& grad_step_size(void) const; | |
| 120 | 121 | |
| 121 | 122 | // Implemented methods |
| 122 | 123 | bool has_events(void) const; |
| ... | ... | @@ -218,10 +219,11 @@ protected: |
| 218 | 219 | }; |
| 219 | 220 | |
| 220 | 221 | // Protected data area |
| 221 | - std::string m_name; //!< Observation name | |
| 222 | - std::string m_id; //!< Observation identifier | |
| 223 | - std::string m_statistic; //!< Optimizer statistic | |
| 224 | - GEvents* m_events; //!< Pointer to event container | |
| 222 | + std::string m_name; //!< Observation name | |
| 223 | + std::string m_id; //!< Observation identifier | |
| 224 | + std::string m_statistic; //!< Optimizer statistic | |
| 225 | + GEvents* m_events; //!< Pointer to event container | |
| 226 | + double m_grad_step_size; //!< Gradient step size | |
| 225 | 227 | |
| 226 | 228 | // Stack of identifiers of parameters with gradients |
| 227 | 229 | mutable std::vector<std::string> m_pars_with_gradients; |
| ... | ... | @@ -320,4 +322,16 @@ const std::string& GObservation::statistic(void) const |
| 320 | 322 | return (m_statistic); |
| 321 | 323 | } |
| 322 | 324 | |
| 325 | + | |
| 326 | +/***********************************************************************//** | |
| 327 | + * @brief Return gradient step size | |
| 328 | + * | |
| 329 | + * @return Gradient step size. | |
| 330 | + ***************************************************************************/ | |
| 331 | +inline | |
| 332 | +const double& GObservation::grad_step_size(void) const | |
| 333 | +{ | |
| 334 | + return (m_grad_step_size); | |
| 335 | +} | |
| 336 | + | |
| 323 | 337 | #endif /* GOBSERVATION_HPP */ | ... | ... |
inst/com/src/GCOMObservation.cpp
| ... | ... | @@ -868,6 +868,11 @@ std::string GCOMObservation::print(const GChatter& chatter) const |
| 868 | 868 | ***************************************************************************/ |
| 869 | 869 | void GCOMObservation::init_members(void) |
| 870 | 870 | { |
| 871 | + // Initialise gradient step size to 0.05 degrees since the angular | |
| 872 | + // resolution of COMPTEL is much worse than the default step size | |
| 873 | + // value of 0.0002. | |
| 874 | + m_grad_step_size = 0.05; | |
| 875 | + | |
| 871 | 876 | // Initialise members |
| 872 | 877 | m_instrument = "COM"; |
| 873 | 878 | m_response.clear(); | ... | ... |
src/obs/GObservation.cpp
| ... | ... | @@ -875,12 +875,6 @@ double GObservation::npred(const GModel& model) const |
| 875 | 875 | * a simple method as this method is likely used for spatial model parameters, |
| 876 | 876 | * and the spatial model may eventually be noisy due to numerical integration |
| 877 | 877 | * limits. |
| 878 | - * | |
| 879 | - * The step size for the simple method has been fixed to 0.0002, which | |
| 880 | - * corresponds to about 1 arcsec for parameters that are given in degrees. | |
| 881 | - * The reasoning behind this value is that parameters that use numerical | |
| 882 | - * gradients are typically angles, such as for example the position, and | |
| 883 | - * we want to achieve arcsec precision with this method. | |
| 884 | 878 | ***************************************************************************/ |
| 885 | 879 | double GObservation::model_grad(const GModel& model, |
| 886 | 880 | const GModelPar& par, |
| ... | ... | @@ -901,10 +895,8 @@ double GObservation::model_grad(const GModel& model, |
| 901 | 895 | // Get actual parameter value |
| 902 | 896 | double x = par.factor_value(); |
| 903 | 897 | |
| 904 | - // Set fixed step size for computation of derivative. | |
| 905 | - // By default, the step size is fixed to 0.0002. | |
| 906 | - const double step_size = 0.0002; // ~1 arcsec | |
| 907 | - double h = step_size; | |
| 898 | + // Set step size for computation of derivative. | |
| 899 | + double h = m_grad_step_size; | |
| 908 | 900 | |
| 909 | 901 | // Re-adjust the step-size h in case that the initial step size is |
| 910 | 902 | // larger than the allowed parameter range |
| ... | ... | @@ -965,12 +957,6 @@ double GObservation::model_grad(const GModel& model, |
| 965 | 957 | * a simple method as this method is likely used for spatial model parameters, |
| 966 | 958 | * and the spatial model may eventually be noisy due to numerical integration |
| 967 | 959 | * limits. |
| 968 | - * | |
| 969 | - * The step size for the simple method has been fixed to 0.0002, which | |
| 970 | - * corresponds to about 1 arcsec for parameters that are given in degrees. | |
| 971 | - * The reasoning behind this value is that parameters that use numerical | |
| 972 | - * gradients are typically angles, such as for example the position, and | |
| 973 | - * we want to achieve arcsec precision with this method. | |
| 974 | 960 | ***************************************************************************/ |
| 975 | 961 | GVector GObservation::model_grad(const GModel& model, |
| 976 | 962 | const GModelPar& par) const |
| ... | ... | @@ -990,10 +976,8 @@ GVector GObservation::model_grad(const GModel& model, |
| 990 | 976 | // Get actual parameter value |
| 991 | 977 | double x = par.factor_value(); |
| 992 | 978 | |
| 993 | - // Set fixed step size for computation of derivative. | |
| 994 | - // By default, the step size is fixed to 0.0002. | |
| 995 | - const double step_size = 0.0002; // ~1 arcsec | |
| 996 | - double h = step_size; | |
| 979 | + // Set step size for computation of derivative. | |
| 980 | + double h = m_grad_step_size; | |
| 997 | 981 | |
| 998 | 982 | // Re-adjust the step-size h in case that the initial step size is |
| 999 | 983 | // larger than the allowed parameter range |
| ... | ... | @@ -1114,8 +1098,6 @@ GVector GObservation::model_grad(const GModel& model, |
| 1114 | 1098 | * a simple method as this method is likely used for spatial model parameters, |
| 1115 | 1099 | * and the spatial model may eventually be noisy due to numerical integration |
| 1116 | 1100 | * limits. |
| 1117 | - * | |
| 1118 | - * The step size for the simple method has been fixed to 0.0002. | |
| 1119 | 1101 | ***************************************************************************/ |
| 1120 | 1102 | double GObservation::npred_grad(const GModel& model, const GModelPar& par) const |
| 1121 | 1103 | { |
| ... | ... | @@ -1134,9 +1116,8 @@ double GObservation::npred_grad(const GModel& model, const GModelPar& par) const |
| 1134 | 1116 | // Get actual parameter value |
| 1135 | 1117 | double x = par.factor_value(); |
| 1136 | 1118 | |
| 1137 | - // Set fixed step size to 0.0002 for computation of derivative. | |
| 1138 | - const double step_size = 0.0002; | |
| 1139 | - double h = step_size; | |
| 1119 | + // Set step size for computation of derivative. | |
| 1120 | + double h = m_grad_step_size; | |
| 1140 | 1121 | |
| 1141 | 1122 | // Re-adjust the step-size h in case that the initial step size is |
| 1142 | 1123 | // larger than the allowed parameter range |
| ... | ... | @@ -1285,14 +1266,21 @@ void GObservation::computed_gradient(const GModel& model, const GModelPar& par) |
| 1285 | 1266 | |
| 1286 | 1267 | /***********************************************************************//** |
| 1287 | 1268 | * @brief Initialise class members |
| 1269 | + * | |
| 1270 | + * The step size for gradient computation is fixed by default to 0.0002 | |
| 1271 | + * degrees, which corresponds to about 1 arcsec for parameters that are | |
| 1272 | + * given in degrees. The reasoning behind this value is that parameters that | |
| 1273 | + * use numerical gradients are typically angles, such as for example the | |
| 1274 | + * position, and we want to achieve arcsec precision with this method. | |
| 1288 | 1275 | ***************************************************************************/ |
| 1289 | 1276 | void GObservation::init_members(void) |
| 1290 | 1277 | { |
| 1291 | 1278 | // Initialise members |
| 1292 | 1279 | m_name.clear(); |
| 1293 | 1280 | m_id.clear(); |
| 1294 | - m_statistic = "cstat"; | |
| 1295 | - m_events = NULL; | |
| 1281 | + m_statistic = "cstat"; | |
| 1282 | + m_events = NULL; | |
| 1283 | + m_grad_step_size = 0.0002; | |
| 1296 | 1284 | |
| 1297 | 1285 | // Initialise stack of identifiers of parameters with gradients |
| 1298 | 1286 | m_pars_with_gradients.clear(); |
| ... | ... | @@ -1312,9 +1300,10 @@ void GObservation::init_members(void) |
| 1312 | 1300 | void GObservation::copy_members(const GObservation& obs) |
| 1313 | 1301 | { |
| 1314 | 1302 | // Copy members |
| 1315 | - m_name = obs.m_name; | |
| 1316 | - m_id = obs.m_id; | |
| 1317 | - m_statistic = obs.m_statistic; | |
| 1303 | + m_name = obs.m_name; | |
| 1304 | + m_id = obs.m_id; | |
| 1305 | + m_statistic = obs.m_statistic; | |
| 1306 | + m_grad_step_size = obs.m_grad_step_size; | |
| 1318 | 1307 | |
| 1319 | 1308 | // Copy stack of identifiers of parameters with gradients |
| 1320 | 1309 | m_pars_with_gradients = obs.m_pars_with_gradients; | ... | ... |