1 // @(#)root/minuit2:$Id$
2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005
3 
4 /**********************************************************************
5  *                                                                    *
6  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
7  *                                                                    *
8  **********************************************************************/
9 
10 #ifndef ROOT_Minuit2_VariableMetricBuilder
11 #define ROOT_Minuit2_VariableMetricBuilder
12 
13 #include "Minuit2/MnConfig.h"
14 #include "Minuit2/MinimumBuilder.h"
15 #include "Minuit2/VariableMetricEDMEstimator.h"
16 #include "Minuit2/DavidonErrorUpdator.h"
17 #include "Minuit2/BFGSErrorUpdator.h"
18 
19 #include <vector>
20 #include <memory>
21 
22 namespace ROOT {
23 
24 namespace Minuit2 {
25 
26 /**
27    Build (find) function minimum using the Variable Metric method (MIGRAD)
28    Two possible error updators can be choosen
29     - Davidon : this is the standard formula used in Migrad
30     - BFGS this is the new formula based on BFGS algorithm
31       (see Broyden–Fletcher–Goldfarb–Shanno algorithm
32       https://en.wikipedia.org/wiki/Broyden–Fletcher–Goldfarb–Shanno_algorithm )
33  */
34 class VariableMetricBuilder : public MinimumBuilder {
35 
36 public:
37    enum ErrorUpdatorType { kDavidon, kBFGS };
38 
fEstimator(VariableMetricEDMEstimator ())39    VariableMetricBuilder(ErrorUpdatorType type = kDavidon) : fEstimator(VariableMetricEDMEstimator())
40    {
41       if (type == kBFGS)
42          fErrorUpdator = std::unique_ptr<MinimumErrorUpdator>(new BFGSErrorUpdator());
43       else
44          fErrorUpdator = std::unique_ptr<MinimumErrorUpdator>(new DavidonErrorUpdator());
45    }
46 
~VariableMetricBuilder()47    ~VariableMetricBuilder() {}
48 
49    virtual FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, const MnStrategy &,
50                                    unsigned int, double) const;
51 
52    FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, std::vector<MinimumState> &,
53                            unsigned int, double) const;
54 
Estimator()55    const VariableMetricEDMEstimator &Estimator() const { return fEstimator; }
ErrorUpdator()56    const MinimumErrorUpdator &ErrorUpdator() const { return *fErrorUpdator; }
57 
58    void AddResult(std::vector<MinimumState> &result, const MinimumState &state) const;
59 
60 private:
61    VariableMetricEDMEstimator fEstimator;
62    std::shared_ptr<MinimumErrorUpdator> fErrorUpdator;
63 };
64 
65 } // namespace Minuit2
66 
67 } // namespace ROOT
68 
69 #endif // ROOT_Minuit2_VariableMetricBuilder
70