#include "TMVA/MCFitter.h"
#include "TMVA/GeneticRange.h"
#include "TMVA/Interval.h"
#include "TMVA/Timer.h"
#include "TRandom3.h"
ClassImp(TMVA::MCFitter)
TMVA::MCFitter::MCFitter( IFitterTarget& target,
const TString& name,
const std::vector<Interval*>& ranges,
const TString& theOption )
: TMVA::FitterBase( target, name, ranges, theOption ),
fSamples( 0 ),
fSigma ( 1 ),
fSeed ( 0 )
{
DeclareOptions();
ParseOptions();
}
void TMVA::MCFitter::DeclareOptions()
{
DeclareOptionRef( fSamples = 100000, "SampleSize", "Number of Monte Carlo events in toy sample" );
DeclareOptionRef( fSigma = -1.0, "Sigma",
"If > 0: new points are generated according to Gauss around best value and with \"Sigma\" in units of interval length" );
DeclareOptionRef( fSeed = 100, "Seed", "Seed for the random generator (0 takes random seeds)" );
}
void TMVA::MCFitter::SetParameters( Int_t samples )
{
fSamples = samples;
}
Double_t TMVA::MCFitter::Run( std::vector<Double_t>& pars )
{
fLogger << kINFO << "<MCFitter> Sampling, please be patient ..." << Endl;
if ((Int_t)pars.size() != GetNpars())
fLogger << kFATAL << "<Run> Mismatch in number of parameters: "
<< GetNpars() << " != " << pars.size() << Endl;
Timer timer( fSamples, GetName() );
std::vector<Double_t> parameters;
std::vector<Double_t> bestParameters;
TRandom *rnd = new TRandom3( fSeed );
rnd->Uniform(0.,1.);
std::vector<TMVA::GeneticRange*> rndRanges;
std::vector< TMVA::Interval* >::const_iterator rIt;
Double_t val;
for (rIt = fRanges.begin(); rIt<fRanges.end(); rIt++) {
rndRanges.push_back( new TMVA::GeneticRange( rnd, (*rIt) ) );
val = rndRanges.back()->Random();
parameters.push_back( val );
bestParameters.push_back( val );
}
std::vector<Double_t>::iterator parIt;
std::vector<Double_t>::iterator parBestIt;
Double_t estimator = 0;
Double_t bestFit = 0;
for (Int_t sample = 0; sample < fSamples; sample++) {
parIt = parameters.begin();
if (fSigma > 0.0) {
parBestIt = bestParameters.begin();
for (std::vector<TMVA::GeneticRange*>::iterator rndIt = rndRanges.begin(); rndIt<rndRanges.end(); rndIt++) {
(*parIt) = (*rndIt)->Random( kTRUE, fSigma, (*parBestIt) );
parIt++;
parBestIt++;
}
}
else {
for (std::vector<TMVA::GeneticRange*>::iterator rndIt = rndRanges.begin(); rndIt<rndRanges.end(); rndIt++) {
(*parIt) = (*rndIt)->Random();
parIt++;
}
}
estimator = EstimatorFunction( parameters );
if (estimator < bestFit || sample==0) {
bestFit = estimator;
bestParameters.swap( parameters );
}
if ((fSamples<100) || sample%Int_t(fSamples/100.0) == 0) timer.DrawProgressBar( sample );
}
pars.swap( bestParameters );
fLogger << kINFO << "Elapsed time: " << timer.GetElapsedTime()
<< " " << Endl;
return bestFit;
}
Last change: Sat Nov 1 10:21:36 2008
Last generated: 2008-11-01 10:21
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.