72 fCallerName (callerName),
88 std::vector<Ranking*>::const_iterator it =
fRanking.begin();
89 for (; it !=
fRanking.end(); it++)
delete *it;
120 <<
"\" has zero or negative RMS^2 " 121 <<
"==> set to zero. Please check the variable content" <<
Endl;
147 const Event* trEv = ev;
150 trEv = trf->Transform(trEv, (*rClsIt) );
168 const Event* trEv = ev;
169 UInt_t nvars = 0, ntgts = 0, nspcts = 0;
171 if (trf->IsCreated()) {
172 trf->CountVariableTypes( nvars, ntgts, nspcts );
173 if( !(suppressIfNoTargets && ntgts==0) )
174 trEv = trf->InverseTransform(ev, (*rClsIt) );
212 std::vector<Event*> *transformedEvents =
new std::vector<TMVA::Event*>(events.size());
213 for (
UInt_t ievt = 0; ievt<events.size(); ievt++)
214 transformedEvents->at(ievt) =
new Event(*events.at(ievt));
219 if (trf->PrepareTransformation(*transformedEvents)) {
220 for (
UInt_t ievt = 0; ievt<transformedEvents->size(); ievt++) {
221 *(*transformedEvents)[ievt] = *trf->Transform((*transformedEvents)[ievt],(*rClsIt));
234 if (!createNewVector) {
235 for (
UInt_t ievt = 0; ievt<transformedEvents->size(); ievt++)
236 delete (*transformedEvents)[ievt];
237 delete transformedEvents;
238 transformedEvents=
NULL;
241 return transformedEvents;
250 UInt_t nevts = events.size();
253 Log() << kFATAL <<
"No events available to find min, max, mean and rms" <<
Endl;
256 const UInt_t nvar = events[0]->GetNVariables();
257 const UInt_t ntgt = events[0]->GetNTargets();
269 varMin[cls] =
new Double_t[nvar+ntgt];
270 varMax[cls] =
new Double_t[nvar+ntgt];
271 for (
UInt_t ivar=0; ivar<nvar+ntgt; ivar++) {
272 x0[cls][ivar] = x2[cls][ivar] = 0;
273 varMin[cls][ivar] = DBL_MAX;
274 varMax[cls][ivar] = -DBL_MAX;
278 for (
UInt_t ievt=0; ievt<nevts; ievt++) {
279 const Event* ev = events[ievt];
283 sumOfWeights[cls] += weight;
284 if (fNumC > 1 ) sumOfWeights[fNumC-1] += weight;
285 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++ ){
286 UInt_t nloop = ( var_tgt==0?nvar:ntgt );
287 for (
UInt_t ivar=0; ivar<nloop; ivar++) {
290 if (x < varMin[cls][(var_tgt*nvar)+ivar]) varMin[cls][(var_tgt*nvar)+ivar]=
x;
291 if (x > varMax[cls][(var_tgt*nvar)+ivar]) varMax[cls][(var_tgt*nvar)+ivar]=
x;
293 x0[cls][(var_tgt*nvar)+ivar] += x*weight;
294 x2[cls][(var_tgt*nvar)+ivar] += x*x*weight;
297 if (x < varMin[fNumC-1][(var_tgt*nvar)+ivar]) varMin[fNumC-1][(var_tgt*nvar)+ivar]=
x;
298 if (x > varMax[fNumC-1][(var_tgt*nvar)+ivar]) varMax[fNumC-1][(var_tgt*nvar)+ivar]=
x;
300 x0[fNumC-1][(var_tgt*nvar)+ivar] += x*weight;
301 x2[fNumC-1][(var_tgt*nvar)+ivar] += x*x*weight;
309 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++ ){
310 UInt_t nloop = ( var_tgt==0?nvar:ntgt );
311 for (
UInt_t ivar=0; ivar<nloop; ivar++) {
313 Double_t mean = x0[cls][(var_tgt*nvar)+ivar]/sumOfWeights[cls];
315 AddStats(cls, (var_tgt*nvar)+ivar, mean, rms, varMin[cls][(var_tgt*nvar)+ivar], varMax[cls][(var_tgt*nvar)+ivar]);
322 UInt_t maxL = 8, maxV = 0;
323 std::vector<UInt_t> vLengths;
324 for (
UInt_t ivar=0; ivar<nvar+ntgt; ivar++) {
332 UInt_t clen = maxL + 4*maxV + 11;
338 Log() << std::setw(maxL) <<
"Variable";
339 Log() <<
" " << std::setw(maxV) <<
"Mean";
340 Log() <<
" " << std::setw(maxV) <<
"RMS";
341 Log() <<
" " << std::setw(maxV) <<
"[ Min ";
342 Log() <<
" " << std::setw(maxV) <<
" Max ]"<<
Endl;;
343 for (
UInt_t i=0; i<clen; i++)
Log() <<
"-";
348 for (
UInt_t ivar=0; ivar<nvar+ntgt; ivar++) {
359 for (
UInt_t i=0; i<clen; i++)
Log() <<
"-";
363 delete[] sumOfWeights;
367 delete [] varMin[cls];
368 delete [] varMax[cls];
385 trf->MakeFunction(fout, fncName, part, trCounter++, (*rClsIt) );
390 fout <<
" void InitTransform_"<<i+1<<
"();" << std::endl;
391 fout <<
" void Transform_"<<i+1<<
"( std::vector<double> & iv, int sigOrBgd ) const;" << std::endl;
396 fout <<
"//_______________________________________________________________________" << std::endl;
397 fout <<
"inline void " << fncName <<
"::InitTransform()" << std::endl;
398 fout <<
"{" << std::endl;
400 fout <<
" InitTransform_"<<i+1<<
"();" << std::endl;
401 fout <<
"}" << std::endl;
403 fout <<
"//_______________________________________________________________________" << std::endl;
404 fout <<
"inline void " << fncName <<
"::Transform( std::vector<double>& iv, int sigOrBgd ) const" << std::endl;
405 fout <<
"{" << std::endl;
407 fout <<
" Transform_"<<i+1<<
"( iv, sigOrBgd );" << std::endl;
409 fout <<
"}" << std::endl;
438 xtit +=
" (" +
GetName() +
")";
454 Log() << kDEBUG <<
"Plot event variables for ";
460 if (theDirectory == 0) {
473 std::vector<std::vector<TH1*> > hVars( ncls );
474 std::vector<std::vector<std::vector<TH2F*> > > mycorr( ncls );
475 std::vector<std::vector<std::vector<TProfile*> > > myprof( ncls );
477 for (
Int_t cls = 0; cls < ncls; cls++) {
478 hVars.at(cls).resize ( nvar+ntgt );
479 hVars.at(cls).assign ( nvar+ntgt, 0 );
480 mycorr.at(cls).resize( nvar+ntgt );
481 myprof.at(cls).resize( nvar+ntgt );
482 for (
UInt_t ivar=0; ivar < nvar+ntgt; ivar++) {
483 mycorr.at(cls).at(ivar).resize( nvar+ntgt );
484 myprof.at(cls).at(ivar).resize( nvar+ntgt );
485 mycorr.at(cls).at(ivar).assign( nvar+ntgt, 0 );
486 myprof.at(cls).at(ivar).assign( nvar+ntgt, 0 );
493 if (nvar+ntgt > (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
494 Int_t nhists = (nvar+ntgt)*(nvar+ntgt - 1)/2;
496 Log() << kINFO <<
"<PlotVariables> Will not produce scatter plots ==> " <<
Endl;
498 <<
"| The number of " << nvar <<
" input variables and " << ntgt <<
" target values would require " 499 << nhists <<
" two-dimensional" <<
Endl;
501 <<
"| histograms, which would occupy the computer's memory. Note that this" <<
Endl;
503 <<
"| suppression does not have any consequences for your analysis, other" <<
Endl;
505 <<
"| than not disposing of these scatter plots. You can modify the maximum" <<
Endl;
507 <<
"| number of input variables allowed to generate scatter plots in your" <<
Endl;
508 Log() <<
"| script via the command line:" <<
Endl;
510 <<
"| \"(TMVA::gConfig().GetVariablePlotting()).fMaxNumOfAllowedVariablesForScatterPlots = <some int>;\"" 513 Log() << kINFO <<
"Some more output" <<
Endl;
520 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++) {
521 UInt_t nloops = ( var_tgt == 0? nvar:ntgt );
522 for (
UInt_t ivar=0; ivar<nloops; ivar++) {
529 for (
Int_t cls = 0; cls < ncls; cls++) {
534 className += (ntgt == 1 && var_tgt == 1 ?
"_target" :
"");
553 if (xmin >= xmax) xmax = xmin*1.1;
554 if (xmin >= xmax) xmax = xmin + 1;
556 xmax += (xmax -
xmin)/nbins1D;
564 hVars.at(cls).at((var_tgt*nvar)+ivar) =
h;
567 if (nvar+ntgt <= (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
569 for (
UInt_t v_t = 0; v_t < 2; v_t++) {
570 UInt_t nl = ( v_t==0?nvar:ntgt );
571 UInt_t start = ( v_t==0? (var_tgt==0?ivar+1:0):(var_tgt==0?nl:ivar+1) );
572 for (
UInt_t j=start; j<nl; j++) {
584 className.
Data(), transfType.
Data() ),
586 className.
Data(), transfType.
Data() ),
587 nbins2D, rxmin , rxmax,
588 nbins2D, rymin , rymax );
592 mycorr.at(cls).at((var_tgt*nvar)+ivar).at((v_t*nvar)+j) = h2;
598 Form(
"profile %s versus %s (%s)%s",
600 className.
Data(), transfType.
Data() ), nbins1D,
606 myprof.at(cls).at((var_tgt*nvar)+ivar).at((v_t*nvar)+j) = p;
614 UInt_t nevts = events.size();
617 std::vector<Double_t> xregmean ( nvar+1, 0 );
618 std::vector<Double_t> x2regmean( nvar+1, 0 );
619 std::vector<Double_t> xCregmean( nvar+1, 0 );
622 for (
UInt_t ievt=0; ievt<nevts; ievt++) {
624 const Event* ev = events[ievt];
632 xregmean[nvar] += valr;
633 x2regmean[nvar] += valr*valr;
634 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
636 xregmean[ivar] += vali;
637 x2regmean[ivar] += vali*vali;
638 xCregmean[ivar] += vali*valr;
643 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++) {
644 UInt_t nloops = ( var_tgt == 0? nvar:ntgt );
645 for (
UInt_t ivar=0; ivar<nloops; ivar++) {
649 hVars.at(cls).at( ( var_tgt*nvar )+ivar)->Fill( vali, weight );
652 if (nvar+ntgt <= (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
654 for (
UInt_t v_t = 0; v_t < 2; v_t++) {
655 UInt_t nl = ( v_t==0 ? nvar : ntgt );
656 UInt_t start = ( v_t==0 ? (var_tgt==0?ivar+1:0) : (var_tgt==0?nl:ivar+1) );
657 for (
UInt_t j=start; j<nl; j++) {
659 mycorr.at(cls).at( ( var_tgt*nvar )+ivar).at( ( v_t*nvar )+j)->Fill( vali, valj, weight );
660 myprof.at(cls).at( ( var_tgt*nvar )+ivar).at( ( v_t*nvar )+j)->Fill( vali, valj, weight );
670 for (
UInt_t ivar=0; ivar<=nvar; ivar++) {
671 xregmean[ivar] /= nevts;
672 x2regmean[ivar] = x2regmean[ivar]/nevts - xregmean[ivar]*xregmean[ivar];
674 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
675 xCregmean[ivar] = xCregmean[ivar]/nevts - xregmean[ivar]*xregmean[nvar];
676 xCregmean[ivar] /=
TMath::Sqrt( x2regmean[ivar]*x2regmean[nvar] );
680 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
689 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
690 TH2F*
h1 = mycorr.at(0).at( nvar ).at( ivar );
697 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
698 TH2F* h2 = mycorr.at(0).at( nvar ).at( ivar );
705 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
720 for (
UInt_t i=0; i<nvar; i++) {
733 if (theDirectory == 0) {
739 outputDir +=
"_" +
TString(trf->GetShortName());
741 TString uniqueOutputDir = outputDir;
745 uniqueOutputDir = outputDir+
Form(
"_%d",counter);
746 Log() << kINFO <<
"A " << o->
ClassName() <<
" with name " << o->
GetName() <<
" already exists in " 759 Log() << kVERBOSE <<
"Create and switch to directory " << localDir->
GetPath() <<
Endl;
765 for (
UInt_t i=0; i<nvar+ntgt; i++) {
766 for (
Int_t cls = 0; cls < ncls; cls++) {
767 if (hVars.at(cls).at(i) != 0) {
768 hVars.at(cls).at(i)->Write();
769 hVars.at(cls).at(i)->SetDirectory(0);
770 delete hVars.at(cls).at(i);
776 if (nvar+ntgt <= (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
778 localDir = localDir->
mkdir(
"CorrelationPlots" );
780 Log() << kDEBUG <<
"Create scatter and profile plots in target-file directory: " <<
Endl;
784 for (
UInt_t i=0; i<nvar+ntgt; i++) {
785 for (
UInt_t j=i+1; j<nvar+ntgt; j++) {
786 for (
Int_t cls = 0; cls < ncls; cls++) {
787 if (mycorr.at(cls).at(i).at(j) != 0 ) {
788 mycorr.at(cls).at(i).at(j)->Write();
789 mycorr.at(cls).at(i).at(j)->SetDirectory(0);
790 delete mycorr.at(cls).at(i).at(j);
792 if (myprof.at(cls).at(i).at(j) != 0) {
793 myprof.at(cls).at(i).at(j)->Write();
794 myprof.at(cls).at(i).at(j)->SetDirectory(0);
795 delete myprof.at(cls).at(i).at(j);
801 if (theDirectory != 0 ) theDirectory->
cd();
838 o <<
"#TR -*-*-*-*-*-*-* transformation " << i++ <<
": " << trf->
GetName() <<
" -*-*-*-*-*-*-*-" << std::endl;
839 trf->WriteTransformationToStream(o);
842 if (ci == 0 ) clsName =
"AllClasses";
844 o <<
"ReferenceClass " << clsName << std::endl;
866 Log() << kFATAL <<
"Read transformations not implemented" <<
Endl;
882 if (trfname ==
"Decorrelation" ) {
885 else if (trfname ==
"PCA" ) {
888 else if (trfname ==
"Gauss" ) {
891 else if (trfname ==
"Uniform" ) {
894 else if (trfname ==
"Normalize" ) {
897 else if (trfname ==
"Rearrange" ) {
900 else if (trfname !=
"None") {
903 Log() << kFATAL <<
"<ReadFromXML> Variable transform '" 904 << trfname <<
"' unknown." <<
Endl;
918 Log() << kINFO <<
"Ranking input variables (method unspecific)..." <<
Endl;
919 std::vector<Ranking*>::const_iterator it =
fRanking.begin();
920 for (; it !=
fRanking.end(); it++) (*it)->Print();
935 Log() << kWARNING <<
"Inconsistent variable state when reading the mean value. " <<
Endl;
938 Log() << kWARNING <<
"Inconsistent variable state when reading the mean value. Value 0 given back" <<
Endl;
954 Log() << kWARNING <<
"Inconsistent variable state when reading the RMS value. " <<
Endl;
957 Log() << kWARNING <<
"Inconsistent variable state when reading the RMS value. Value 0 given back" <<
Endl;
973 Log() << kWARNING <<
"Inconsistent variable state when reading the minimum value. " <<
Endl;
976 Log() << kWARNING <<
"Inconsistent variable state when reading the minimum value. Value 0 given back" <<
Endl;
992 Log() << kWARNING <<
"Inconsistent variable state when reading the maximum value. " <<
Endl;
995 Log() << kWARNING <<
"Inconsistent variable state when reading the maximum value. Value 0 given back" <<
Endl;
virtual const char * GetName() const
Returns name of object.
UInt_t GetNVariables() const
Int_t fMaxNumOfAllowedVariablesForScatterPlots
MsgLogger & Endl(MsgLogger &ml)
const TString & GetInternalName() const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
virtual Int_t GetEntries() const
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
virtual TObject * FindObject(const char *name) const
Find object by name in the list of memory objects.
const TString & GetUnit() const
Ranking for variables in method (implementation)
Short_t Min(Short_t a, Short_t b)
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
UInt_t GetNClasses() const
const TString & GetLabel() const
static std::string format(double x, double y, int digits, int width)
const TString & GetExpression() const
Class that contains all the information of a class.
static const double x2[5]
virtual const char * ClassName() const
Returns name of class to which the object belongs.
std::vector< std::vector< double > > Data
Class that contains all the data information.
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
Float_t GetTarget(UInt_t itgt) const
UInt_t GetNTargets() const
ClassInfo * GetClassInfo(Int_t clNum) const
tomato 2-D histogram with a float per channel (see TH1 documentation)}
char * Form(const char *fmt,...)
virtual const char * GetPath() const
Returns the full path of the directory.
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Describe directory structure in memory.
VariableInfo & GetVariableInfo(Int_t i)
ostringstream derivative to redirect and format output
Mother of all ROOT objects.
void SetSource(const std::string &source)
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
virtual void Add(TObject *obj)
Short_t Max(Short_t a, Short_t b)
TString()
TString default ctor.
Double_t Sqrt(Double_t x)
const Bool_t kIterBackward
Class for type info of MVA input variable.
virtual const char * GetName() const
Returns name of object.
virtual Int_t GetSize() const
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
VariablePlotting & GetVariablePlotting()
virtual const char * GetTitle() const
Returns title of object.
const char * Data() const