#include "TFitter.h"
#include "TMVA/MinuitFitter.h"
#include "TMVA/MinuitWrapper.h"
#include "TMVA/Interval.h"
#include "TMVA/Timer.h"
ClassImp(TMVA::MinuitFitter)
TMVA::MinuitFitter::MinuitFitter( IFitterTarget& target,
const TString& name,
std::vector<TMVA::Interval*>& ranges,
const TString& theOption )
: TMVA::FitterBase( target, name, ranges, theOption ),
TMVA::IFitterTarget( )
{
DeclareOptions();
ParseOptions();
Init();
}
TMVA::MinuitFitter::~MinuitFitter( )
{
delete fMinWrap;
}
void TMVA::MinuitFitter::DeclareOptions()
{
DeclareOptionRef(fErrorLevel = 1, "ErrorLevel", "MINUIT: error level: 0.5=logL fit, 1=chi-squared fit" );
DeclareOptionRef(fPrintLevel = -1, "PrintLevel", "MINUIT: output level: -1=least, 0, +1=all garbage" );
DeclareOptionRef(fFitStrategy = 2, "FitStrategy", "MINUIT: fit strategy: 2=best" );
DeclareOptionRef(fPrintWarnings = kFALSE, "PrintWarnings", "MINUIT: suppress warnings" );
DeclareOptionRef(fUseImprove = kTRUE, "UseImprove", "MINUIT: use IMPROVE routine" );
DeclareOptionRef(fUseMinos = kTRUE, "UseMinos", "MINUIT: use MINOS routine" );
DeclareOptionRef(fBatch = kFALSE, "SetBatch", "MINUIT: use batch mode" );
DeclareOptionRef(fMaxCalls = 1000, "MaxCalls", "MINUIT: approximate maximum number of function calls" );
DeclareOptionRef(fTolerance = 0.1, "Tolerance", "MINUIT: tolerance to the function value at the minimum" );
}
void TMVA::MinuitFitter::Init()
{
Double_t args[10];
if (!fBatch) fLogger << kINFO << "<MinuitFitter> Init " << Endl;
Timer timer;
fMinWrap = new MinuitWrapper( fFitterTarget, 2*GetNpars() );
args[0] = fPrintLevel;
fMinWrap->ExecuteCommand( "SET PRINTOUT", args, 1 );
if (fBatch) fMinWrap->ExecuteCommand( "SET BAT", args, 0 );
fMinWrap->Clear();
args[0] = fErrorLevel;
fMinWrap->ExecuteCommand( "SET ERR", args, 1 );
if (!fPrintWarnings) fMinWrap->ExecuteCommand( "SET NOWARNINGS", args, 0 );
args[0] = fFitStrategy;
fMinWrap->ExecuteCommand( "SET STRATEGY", args, 1 );
}
Double_t TMVA::MinuitFitter::Run( std::vector<Double_t>& pars )
{
Double_t args[10];
if ( !fBatch ) fLogger << kINFO << "<MinuitFitter> Fitting, please be patient ... " << Endl;
if ((Int_t)pars.size() != GetNpars())
fLogger << kFATAL << "<Run> Mismatch in number of parameters: (a)"
<< GetNpars() << " != " << pars.size() << Endl;
Timer* timer = 0;
if (!fBatch) timer = new Timer();
for (Int_t ipar=0; ipar<fNpars; ipar++) {
fMinWrap->SetParameter( ipar, Form( "Par%i",ipar ),
pars[ipar], fRanges[ipar]->GetWidth()/100.0,
fRanges[ipar]->GetMin(), fRanges[ipar]->GetMax() );
if (fRanges[ipar]->GetWidth() == 0.0) fMinWrap->FixParameter( ipar );
}
args[0] = fMaxCalls;
args[1] = fTolerance;
fMinWrap->ExecuteCommand( "MIGrad", args, 2 );
if (fUseImprove) fMinWrap->ExecuteCommand( "IMProve", args, 0 );
if (fUseMinos) {
args[0] = 500;
fMinWrap->ExecuteCommand( "MINOs", args, 1 );
}
Double_t chi2;
Double_t edm;
Double_t errdef;
Int_t nvpar;
Int_t nparx;
fMinWrap->GetStats( chi2, edm, errdef, nvpar, nparx );
if (GetNpars() != nparx) {
fLogger << kFATAL << "<Run> Mismatch in number of parameters: "
<< GetNpars() << " != " << nparx << Endl;
}
for (Int_t ipar=0; ipar<GetNpars(); ipar++) {
Double_t errp, errm, errsym, globcor, currVal, currErr;
fMinWrap->GetParameter( ipar, currVal, currErr );
pars[ipar] = currVal;
fMinWrap->GetErrors( ipar, errp, errm, errsym, globcor );
}
if (!fBatch) {
fLogger << kINFO << "Elapsed time: " << timer->GetElapsedTime()
<< " " << Endl;
delete timer;
}
fMinWrap->Clear();
return chi2;
}
Double_t TMVA::MinuitFitter::EstimatorFunction( std::vector<Double_t>& pars )
{
return Run( pars );
}
Last change: Wed Jun 25 08:48:41 2008
Last generated: 2008-06-25 08:48
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.