Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:11

0001 // @(#)root/minuit2:$Id$
0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei, E.G.P. Bos   2003-2017
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_Minuit2_FCNGradientBase
0011 #define ROOT_Minuit2_FCNGradientBase
0012 
0013 #include "Minuit2/FCNBase.h"
0014 
0015 #include <vector>
0016 
0017 namespace ROOT {
0018 
0019 namespace Minuit2 {
0020 
0021 //________________________________________________________________________
0022 /** Extension of the FCNBase for providing the analytical Gradient of the
0023     function. The user-Gradient is checked at the beginning of the
0024     minimization against the Minuit internal numerical Gradient in order to
0025     spot problems in the analytical Gradient calculation. This can be turned
0026     off by overriding CheckGradient() to make it return "false".
0027     The size of the output Gradient vector must be equal to the size of the
0028     input Parameter vector.
0029     Minuit does a check of the user Gradient at the beginning, if this is not
0030     wanted the method "CheckGradient()" has to be overridden to return
0031     "false".
0032  */
0033 
0034 enum class GradientParameterSpace {
0035   External, Internal
0036 };
0037 
0038 class FCNGradientBase : public FCNBase {
0039 
0040 public:
0041    ~FCNGradientBase() override {}
0042 
0043    virtual std::vector<double> Gradient(const std::vector<double> &) const = 0;
0044    virtual std::vector<double> GradientWithPrevResult(const std::vector<double> &parameters, double * /*previous_grad*/,
0045                                                       double * /*previous_g2*/, double * /*previous_gstep*/) const
0046    {
0047       return Gradient(parameters);
0048    };
0049 
0050    virtual bool CheckGradient() const { return true; }
0051 
0052    virtual GradientParameterSpace gradParameterSpace() const {
0053       return GradientParameterSpace::External;
0054    };
0055 
0056    /// return second derivatives (diagonal of the Hessian matrix)
0057    virtual std::vector<double> G2(const std::vector<double> &) const { return std::vector<double>();}
0058 
0059    /// return Hessian
0060    virtual std::vector<double> Hessian(const std::vector<double> &) const { return std::vector<double>();}
0061 
0062    virtual bool HasHessian() const { return false; }
0063 
0064    virtual bool HasG2() const { return false; }
0065 
0066 
0067 };
0068 
0069 } // namespace Minuit2
0070 
0071 } // namespace ROOT
0072 
0073 #endif // ROOT_Minuit2_FCNGradientBase