BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Minuit2Minimizer.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/RootAdapter/Minuit2Minimizer.h
6 //! @brief Declares class Minuit2Minimizer.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_FIT_ROOTADAPTER_MINUIT2MINIMIZER_H
16 #define BORNAGAIN_FIT_ROOTADAPTER_MINUIT2MINIMIZER_H
17 
19 #include <memory>
20 
21 namespace ROOT
22 {
23 namespace Minuit2
24 {
25 class Minuit2Minimizer;
26 }
27 } // namespace ROOT
28 
29 //! Wrapper for the CERN ROOT facade of the Minuit2 minimizer.
30 //! See Minuit2 user manual https://root.cern.ch/root/htmldoc/guides/minuit2/Minuit2.pdf.
31 //! @ingroup fitting_internal
32 
34 {
35 public:
36  Minuit2Minimizer(const std::string& algorithmName = "Migrad");
38 
39  //! Sets minimization strategy (0-low, 1-medium, 2-high minimization quality).
40  //! At low quality number of function calls will be economized.
41  void setStrategy(int value);
42  int strategy() const;
43 
44  //! Sets error definition factor for parameter error calculation.
45  //! If objective function (OF) is the usual chisquare function and if the user wants the usual
46  //! one-standard-deviation errors, then the error definition should be 1.0. If OF is a
47  //! negative-log-likelihood function, then 0.5. If OF is a chisquare, but the user wants
48  //! two-standard-deviation errors, 4.0.
49  void setErrorDefinition(double value);
50  double errorDefinition() const;
51 
52  //! Sets tolerance on the function value at the minimum.
53  //! Minimization will stop when the estimated vertical distance to the minimum (EDM) is less
54  //! than 0.001*tolerance*ErrorDef. Here ErrorDef=1.0 for chi squared fit and ErrorDef=0.5
55  //! for negative log likelihood fit.
56  void setTolerance(double value);
57  double tolerance() const;
58 
59  //! Sets relative floating point arithmetic precision.
60  //! Should be adjusted when the user knows that objectiove function value is not
61  //! calculated to the nominal machine accuracy. Typical values are between 10^-5 and 10^-14.
62  void setPrecision(double value);
63  double precision() const;
64 
65  //! Sets minimizer internal print level.
66  //! Default value is 0 (silent).
67  void setPrintLevel(int value);
68  int printLevel() const;
69 
70  //! Sets maximum number of objective function calls.
71  void setMaxFunctionCalls(int value);
72  int maxFunctionCalls() const;
73 
74  std::string statusToString() const override;
75  std::map<std::string, std::string> statusMap() const override;
76 
77  bool requiresResiduals() override;
78 
79 protected:
80  void propagateOptions() override;
81  const root_minimizer_t* rootMinimizer() const override;
82 
83 private:
84  std::unique_ptr<ROOT::Minuit2::Minuit2Minimizer> m_minuit2_minimizer;
85 };
86 
87 #endif // BORNAGAIN_FIT_ROOTADAPTER_MINUIT2MINIMIZER_H
Declares class RootMinimizerAdapter.
Wrapper for the CERN ROOT facade of the Minuit2 minimizer.
void setPrecision(double value)
Sets relative floating point arithmetic precision.
double tolerance() const
void propagateOptions() override
Propagate options down to ROOT's Minuit2Minimizer.
Minuit2Minimizer(const std::string &algorithmName="Migrad")
void setMaxFunctionCalls(int value)
Sets maximum number of objective function calls.
std::unique_ptr< ROOT::Minuit2::Minuit2Minimizer > m_minuit2_minimizer
void setPrintLevel(int value)
Sets minimizer internal print level.
void setStrategy(int value)
Sets minimization strategy (0-low, 1-medium, 2-high minimization quality).
int maxFunctionCalls() const
double precision() const
const root_minimizer_t * rootMinimizer() const override
std::string statusToString() const override
Returns string representation of current minimizer status.
void setTolerance(double value)
Sets tolerance on the function value at the minimum.
void setErrorDefinition(double value)
Sets error definition factor for parameter error calculation.
std::map< std::string, std::string > statusMap() const override
Returns map of string representing different minimizer statuses.
bool requiresResiduals() override
Returns true if minimizer computations are residual-based, false otherwise.
double errorDefinition() const
Pure virtual interface that adapts the CERN ROOT minimizer to our IMinimizer.
ROOT::Math::Minimizer root_minimizer_t
std::string algorithmName() const override final
Returns name of the minimization algorithm.