BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
MinimizerTestPlan.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Fit/TestEngine/MinimizerTestPlan.h
6 //! @brief Defines class MinimizerTestPlan
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 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_FIT_TESTENGINE_MINIMIZERTESTPLAN_H
21 #define BORNAGAIN_FIT_TESTENGINE_MINIMIZERTESTPLAN_H
22 
23 #include "Fit/Param/Parameter.h"
24 #include <utility>
25 #include <vector>
26 
27 //! Defines initial settings of single fit parameter and the final value which has to be found
28 //! in the course of the fit.
29 
31  const mumufit::Parameter parameter; //!< initial parameter settings
32  const double expected_value; //!< expected value to find in the fit
33  const double tolerance{0.01}; //!< tolerance on found value wrt expected value
34 };
35 
36 namespace mumufit {
37 
38 class Parameter;
39 class Parameters;
40 class Minimizer;
41 
42 } // namespace mumufit
43 
44 //! Defines objective function to fit, expected minimum, initial fit parameters and
45 //! expected values of fit parameters at minimum.
46 
48 public:
49  MinimizerTestPlan() = default;
50  explicit MinimizerTestPlan(std::vector<ParameterReference> parameter_references)
51  : m_parameter_references(std::move(parameter_references))
52  {
53  }
54 
55  virtual ~MinimizerTestPlan();
56 
57  void addParameter(const mumufit::Parameter& param, double expected_value,
58  double tolerance = 0.01);
59 
60  //! Runs minimization and check minimization result.
61  virtual bool checkMinimizer(mumufit::Minimizer& minimizer) const = 0;
62 
63 protected:
65  std::vector<double> expectedValues() const;
66  bool valuesAsExpected(const std::vector<double>& values) const;
67 
68  std::vector<ParameterReference> m_parameter_references; //! initial/expected parameter values
69 };
70 
71 #endif // BORNAGAIN_FIT_TESTENGINE_MINIMIZERTESTPLAN_H
72 #endif // USER_API
Defines class Parameter.
Defines objective function to fit, expected minimum, initial fit parameters and expected values of fi...
std::vector< double > expectedValues() const
Return vector of expected parameter values.
std::vector< ParameterReference > m_parameter_references
bool valuesAsExpected(const std::vector< double > &values) const
Returns true if given values coincide with expected fit parameter values.
mumufit::Parameters parameters() const
Returns fit parameters which will be used as initial one for the minimization.
virtual bool checkMinimizer(mumufit::Minimizer &minimizer) const =0
Runs minimization and check minimization result.
virtual ~MinimizerTestPlan()
MinimizerTestPlan(std::vector< ParameterReference > parameter_references)
void addParameter(const mumufit::Parameter &param, double expected_value, double tolerance=0.01)
MinimizerTestPlan()=default
A main class to run fitting.
Definition: Minimizer.h:37
A fittable parameter with value, error, step, and limits.
Definition: Parameter.h:26
A collection of fit parameters.
Definition: Parameters.h:26
The multi-library, multi-algorithm fit wrapper library.
Defines initial settings of single fit parameter and the final value which has to be found in the cou...
const mumufit::Parameter parameter
initial parameter settings
const double tolerance
tolerance on found value wrt expected value
const double expected_value
expected value to find in the fit