Re: Minuit2

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Tue, 16 Sep 2008 10:50:42 +0200


Hello Patrick,

  Your objective function class must derive from FCNBase. For that you need to implement (overload) the operator(). For the instantiation, you can do as you want. Either using a default constructor, (in the simplest case) or by defining a customize constructor passing some extra information, such as references to other data or objects needed to evaluate the function. In the given example, the GaussFcn function is instantiates passing the measurements data points ( x, y and error in y) which are used in the operator() to evaluate the least square sum.

  Regards

  Lorenzo

On Sep 15, 2008, at 11:47 PM, Patrick Dupre wrote:

> Hello Lorenzo,
>
>
> I your example that I already saw, the function is a Gaussian,, ie
> is ready to go, how do I instanciate my own function ? Previously, I
> overload the () operator.
>
> Thank.
>
> Regards.
>
>> Hello Patrick,
>>
>> the ModularFunctionMinimizer is an abstract class, you need to
>> instantiate a derived class, depending on the algorithm you want to
>> use.
>> FOr example for Migrad (a variable metric minimizer) you need to
>> instantiate the VarableMetricMinimizer class.
>> You can do as following:
>>
>> VaraibleMetricMinimizer minimizer;
>> FunctionMinimum min = minimizer.Minimize(*fFCN, par, stra, 0, 0.1);
>>
>> One examples is in SVN in $ROOTSYS/math/minuit2/test/MnSim/
>> DemoGaussSim.cxx
>> available also online at
>>
>> http://root.cern.ch/viewvc/trunk/math/minuit2/test/MnSim/DemoGaussSim.cxx?view=markup
>>
>> Best Regards
>> Lorenzo
>>
>> On Sep 14, 2008, at 8:16 PM, Patrick Dupre wrote:
>>
>>> Hello,
>>> I used the Minuit2 package by derivating a class from FCNBase and
>>> by overloading the operator () as it is suggested in the manual:
>>> mnusersguide.pdf
>>> I works, but to improve the control on the fit I wanted to use:
>>> ModularFunctionMinimizer
>>> So I tried to instantiate the class by:
>>> ModularFunctionMinimizer minimizer (*fFCN, par, stra, 0, 0.1) ;
>>> where:
>>> RR_Chi2 *fFCN ;
>>> and where RR_Chi2 is a class derivated from FCNBase (the one that
>>> I used before) previously instanciated (fFCN = new RR_Chi2 (x, y))
>>> I get the following compilation error:
>>> Fitter.cpp: In member function 'std::vector<std::vector<double,
>>> std::allocator<double> >, std::allocator<std::vector<double,
>>> std::allocator<double> > > > ROOT::Minuit2::Fit_RR::Fit()':
>>> Fitter.cpp:418: error: no matching function for call to
>>> 'ROOT
>>> ::Minuit2
>>> ::ModularFunctionMinimizer
>>> ::ModularFunctionMinimizer(ROOT::Minuit2::RR_Chi2&,
>>> ROOT::Minuit2::MnUserParameters&, ROOT::Minuit2::MnStrategy&, int,
>>> double)'
>>> /usr/local/include/Minuit2/ModularFunctionMinimizer.h:47: note:
>>> candidates are:
>>> ROOT::Minuit2::ModularFunctionMinimizer::ModularFunctionMinimizer()
>>> /usr/local/include/Minuit2/ModularFunctionMinimizer.h:47: note:
>>> ROOT
>>> ::Minuit2
>>> ::ModularFunctionMinimizer::ModularFunctionMinimizer(const
>>> ROOT::Minuit2::ModularFunctionMinimizer&)
>>> Fitter.cpp:418: error: cannot declare variable 'minimizer' to be
>>> of abstract type 'ROOT::Minuit2::ModularFunctionMinimizer'
>>> /usr/local/include/Minuit2/ModularFunctionMinimizer.h:47: note:
>>> because the following virtual functions are pure within
>>> 'ROOT::Minuit2::ModularFunctionMinimizer':
>>> /usr/local/include/Minuit2/ModularFunctionMinimizer.h:86: note:
>>> virtual const ROOT::Minuit2::MinimumSeedGenerator&
>>> ROOT::Minuit2::ModularFunctionMinimizer::SeedGenerator() const
>>> /usr/local/include/Minuit2/ModularFunctionMinimizer.h:87: note:
>>> virtual const ROOT::Minuit2::MinimumBuilder&
>>> ROOT::Minuit2::ModularFunctionMinimizer::Builder() const
>>> So, it looks like that I cannot instanciate a class
>>> ModularFunctionMinimizer that way.
>>> Question 1) how can I do it by keeping my previous code
>>> 2) If I have to rewrite my previous code, can I get an example ?
>>> Thank.
>>> --
>>> ---
>>> =
>>> =
>>> =
>>> =
>>> =
>>> =
>>> ====================================================================
>>> Patrick DUPRÉ | |
>>> Department of Chemistry | | Phone: (44)-
>>> (0)-1904-434384
>>> The University of York | | Fax: (44)-
>>> (0)-1904-432516
>>> Heslington | |
>>> York YO10 5DD United Kingdom | | email: pd520_at_york.ac.uk
>>> =
>>> =
>>> =
>>> =
>>> =
>>> =
>>> ====================================================================
>>
>>
>
> --
> ---
> =
> =
> =
> =
> ======================================================================
> Patrick DUPRÉ | |
> Department of Chemistry | | Phone: (44)-
> (0)-1904-434384
> The University of York | | Fax: (44)-
> (0)-1904-432516
> Heslington | |
> York YO10 5DD United Kingdom | | email: pd520_at_york.ac.uk
> =
> =
> =
> =
> ======================================================================
Received on Tue Sep 16 2008 - 10:50:47 CEST

This archive was generated by hypermail 2.2.0 : Wed Sep 17 2008 - 05:50:03 CEST