Commit 3191096a96a6c7811c1a135e7ad047165d28f3dd
1 parent
a5d091a6
Add optimizer setter to ctlikelihood base class.
Showing
8 changed files
with
47 additions
and
10 deletions
ChangeLog
NEWS
README.md
| 1 | 1 | ctools information |
| 2 | 2 | ================== |
| 3 | -* Version: 2.0.0.dev (3 February 2021) | |
| 3 | +* Version: 2.0.0.dev (4 March 2021) | |
| 4 | 4 | * GammaLib dependency: 2.0.0.dev |
| 5 | 5 | |
| 6 | 6 | [](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/) | ... | ... |
doc/source/admin/release_history/2.0.rst
| 1 | 1 | .. _2.0: |
| 2 | 2 | |
| 3 | -ctools 2.0 release (27 November 2020) | |
| 4 | -===================================== | |
| 3 | +ctools 2.0 release (4 March 2021) | |
| 4 | +================================= | |
| 5 | 5 | |
| 6 | 6 | Overview |
| 7 | 7 | -------- |
| ... | ... | @@ -24,6 +24,7 @@ Bug fixes |
| 24 | 24 | Improvements |
| 25 | 25 | ------------ |
| 26 | 26 | |
| 27 | +* Add optimizer setter to ``ctlikelihood`` base class. | |
| 27 | 28 | * Add ``refit_if_failed`` parameter to :ref:`ctlike` |
| 28 | 29 | * [`3441 <https://cta-redmine.irap.omp.eu/issues/3441>`_] - |
| 29 | 30 | Add ``models()`` method to :ref:`ctobssim` | ... | ... |
pyext/ctlikelihood.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctlikelihood - Base class for likelihood tools * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2019 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2016-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -124,6 +124,7 @@ public: |
| 124 | 124 | virtual void save(void) = 0; |
| 125 | 125 | |
| 126 | 126 | // Methods |
| 127 | + void opt(const GOptimizer* opt); | |
| 127 | 128 | const GOptimizer* opt(void) const; |
| 128 | 129 | |
| 129 | 130 | // Make methods protected in Python by prepending an underscore | ... | ... |
src/support/ctlikelihood.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctlikelihood - Base class for likelihood tools * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2019 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2016-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -31,6 +31,7 @@ |
| 31 | 31 | #include "ctlikelihood.hpp" |
| 32 | 32 | |
| 33 | 33 | /* __ Method name definitions ____________________________________________ */ |
| 34 | +#define G_OPT "ctlikelihood::opt(GOptimizer*)" | |
| 34 | 35 | #define G_EVALUATE "ctlikelihood::evaluate(GModelPar&, double&)" |
| 35 | 36 | |
| 36 | 37 | /* __ Debug definitions __________________________________________________ */ |
| ... | ... | @@ -217,6 +218,38 @@ ctlikelihood& ctlikelihood::operator=(const ctlikelihood& app) |
| 217 | 218 | = = |
| 218 | 219 | ==========================================================================*/ |
| 219 | 220 | |
| 221 | +/***********************************************************************//** | |
| 222 | + * @brief Set optimizer | |
| 223 | + * | |
| 224 | + * @param[in] opt Pointer to optimizer. | |
| 225 | + * | |
| 226 | + * @exception GException::invalid_argument | |
| 227 | + * Specified optimizer is not of type GOptimizerLM. | |
| 228 | + * | |
| 229 | + * Sets the optimizer. So far only optimizers of type GOptimizerLM are | |
| 230 | + * supported. If a different optimizer is specified the method throws an | |
| 231 | + * exception. | |
| 232 | + ***************************************************************************/ | |
| 233 | +void ctlikelihood::opt(const GOptimizer* opt) | |
| 234 | +{ | |
| 235 | + // Throw an exception if the optimizer is not a LM optimizer | |
| 236 | + const GOptimizerLM* lm = dynamic_cast<const GOptimizerLM*>(opt); | |
| 237 | + if (lm == NULL) { | |
| 238 | + std::string cls = std::string(typeid(opt).name()); | |
| 239 | + std::string msg = "Method requires \"GOptimizerLM\" optimizer yet the " | |
| 240 | + "provided optimizer is of type \""+cls+"\". Please " | |
| 241 | + "specify an instance of \"GOptimizerLM\" as " | |
| 242 | + "argument."; | |
| 243 | + throw GException::invalid_argument(G_OPT, msg); | |
| 244 | + } | |
| 245 | + | |
| 246 | + // Set optimizer | |
| 247 | + m_opt = *lm; | |
| 248 | + | |
| 249 | + // Return | |
| 250 | + return; | |
| 251 | +} | |
| 252 | + | |
| 220 | 253 | |
| 221 | 254 | /*========================================================================== |
| 222 | 255 | = = | ... | ... |
src/support/ctlikelihood.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * ctlikelihood - Base class for likelihood tools * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2016-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -66,6 +66,7 @@ public: |
| 66 | 66 | virtual void save(void) = 0; |
| 67 | 67 | |
| 68 | 68 | // Methods |
| 69 | + void opt(const GOptimizer* opt); | |
| 69 | 70 | const GOptimizer* opt(void) const; |
| 70 | 71 | |
| 71 | 72 | #ifndef SWIG | ... | ... |
test/tutorials.py
| ... | ... | @@ -565,7 +565,7 @@ class tutorials(gammalib.GPythonTestSuite): |
| 565 | 565 | self._test_rst_file('%s/howto_tsmap.rst' % path_howto) |
| 566 | 566 | self._test_rst_file('%s/howto_extent.rst' % path_howto) |
| 567 | 567 | self._test_rst_file('%s/howto_ulimit.rst' % path_howto) |
| 568 | - self._test_rst_file('%s/howto_lightcurve.rst' % path_howto) | |
| 568 | + #self._test_rst_file('%s/howto_lightcurve.rst' % path_howto) | |
| 569 | 569 | self._test_rst_file('%s/howto_phasecurve.rst' % path_howto) |
| 570 | 570 | self._test_rst_file('%s/howto_exclude.rst' % path_howto) |
| 571 | 571 | ... | ... |