67 fCallerName (callerName),
83 std::vector<Ranking*>::const_iterator it =
fRanking.begin();
84 for (; it !=
fRanking.end(); it++)
delete *it;
115 <<
"\" has zero or negative RMS^2 " 116 <<
"==> set to zero. Please check the variable content" <<
Endl;
142 const Event* trEv = ev;
145 trEv = trf->Transform(trEv, (*rClsIt) );
163 const Event* trEv = ev;
164 UInt_t nvars = 0, ntgts = 0, nspcts = 0;
166 if (trf->IsCreated()) {
167 trf->CountVariableTypes( nvars, ntgts, nspcts );
168 if( !(suppressIfNoTargets && ntgts==0) )
169 trEv = trf->InverseTransform(ev, (*rClsIt) );
207 std::vector<Event*> *transformedEvents =
new std::vector<TMVA::Event*>(events.size());
208 for (
UInt_t ievt = 0; ievt<events.size(); ievt++)
209 transformedEvents->at(ievt) =
new Event(*events.at(ievt));
214 if (trf->PrepareTransformation(*transformedEvents)) {
215 for (
UInt_t ievt = 0; ievt<transformedEvents->size(); ievt++) {
216 *(*transformedEvents)[ievt] = *trf->Transform((*transformedEvents)[ievt],(*rClsIt));
229 if (!createNewVector) {
230 for (
UInt_t ievt = 0; ievt<transformedEvents->size(); ievt++)
231 delete (*transformedEvents)[ievt];
232 delete transformedEvents;
233 transformedEvents=
NULL;
236 return transformedEvents;
246 UInt_t nevts = events.size();
249 Log() <<
kFATAL <<
"No events available to find min, max, mean and rms" <<
Endl;
252 const UInt_t nvar = events[0]->GetNVariables();
253 const UInt_t ntgt = events[0]->GetNTargets();
265 varMin[cls] =
new Double_t[nvar+ntgt];
266 varMax[cls] =
new Double_t[nvar+ntgt];
267 for (
UInt_t ivar=0; ivar<nvar+ntgt; ivar++) {
268 x0[cls][ivar] = x2[cls][ivar] = 0;
269 varMin[cls][ivar] = DBL_MAX;
270 varMax[cls][ivar] = -DBL_MAX;
274 for (
UInt_t ievt=0; ievt<nevts; ievt++) {
275 const Event* ev = events[ievt];
279 sumOfWeights[cls] += weight;
280 if (fNumC > 1 ) sumOfWeights[fNumC-1] += weight;
281 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++ ){
282 UInt_t nloop = ( var_tgt==0?nvar:ntgt );
283 for (
UInt_t ivar=0; ivar<nloop; ivar++) {
286 if (x < varMin[cls][(var_tgt*nvar)+ivar]) varMin[cls][(var_tgt*nvar)+ivar]=
x;
287 if (x > varMax[cls][(var_tgt*nvar)+ivar]) varMax[cls][(var_tgt*nvar)+ivar]=
x;
289 x0[cls][(var_tgt*nvar)+ivar] += x*weight;
290 x2[cls][(var_tgt*nvar)+ivar] += x*x*weight;
293 if (x < varMin[fNumC-1][(var_tgt*nvar)+ivar]) varMin[fNumC-1][(var_tgt*nvar)+ivar]=
x;
294 if (x > varMax[fNumC-1][(var_tgt*nvar)+ivar]) varMax[fNumC-1][(var_tgt*nvar)+ivar]=
x;
296 x0[fNumC-1][(var_tgt*nvar)+ivar] += x*weight;
297 x2[fNumC-1][(var_tgt*nvar)+ivar] += x*x*weight;
305 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++ ){
306 UInt_t nloop = ( var_tgt==0?nvar:ntgt );
307 for (
UInt_t ivar=0; ivar<nloop; ivar++) {
309 Double_t mean = x0[cls][(var_tgt*nvar)+ivar]/sumOfWeights[cls];
311 AddStats(cls, (var_tgt*nvar)+ivar, mean, rms, varMin[cls][(var_tgt*nvar)+ivar], varMax[cls][(var_tgt*nvar)+ivar]);
318 UInt_t maxL = 8, maxV = 0;
319 std::vector<UInt_t> vLengths;
320 for (
UInt_t ivar=0; ivar<nvar+ntgt; ivar++) {
328 UInt_t clen = maxL + 4*maxV + 11;
334 Log() << std::setw(maxL) <<
"Variable";
335 Log() <<
" " << std::setw(maxV) <<
"Mean";
336 Log() <<
" " << std::setw(maxV) <<
"RMS";
337 Log() <<
" " << std::setw(maxV) <<
"[ Min ";
338 Log() <<
" " << std::setw(maxV) <<
" Max ]"<<
Endl;;
339 for (
UInt_t i=0; i<clen; i++)
Log() <<
"-";
344 for (
UInt_t ivar=0; ivar<nvar+ntgt; ivar++) {
355 for (
UInt_t i=0; i<clen; i++)
Log() <<
"-";
359 delete[] sumOfWeights;
363 delete [] varMin[cls];
364 delete [] varMax[cls];
381 trf->MakeFunction(fout, fncName, part, trCounter++, (*rClsIt) );
386 fout <<
" void InitTransform_"<<i+1<<
"();" << std::endl;
387 fout <<
" void Transform_"<<i+1<<
"( std::vector<double> & iv, int sigOrBgd ) const;" << std::endl;
392 fout <<
"//_______________________________________________________________________" << std::endl;
393 fout <<
"inline void " << fncName <<
"::InitTransform()" << std::endl;
394 fout <<
"{" << std::endl;
396 fout <<
" InitTransform_"<<i+1<<
"();" << std::endl;
397 fout <<
"}" << std::endl;
399 fout <<
"//_______________________________________________________________________" << std::endl;
400 fout <<
"inline void " << fncName <<
"::Transform( std::vector<double>& iv, int sigOrBgd ) const" << std::endl;
401 fout <<
"{" << std::endl;
403 fout <<
" Transform_"<<i+1<<
"( iv, sigOrBgd );" << std::endl;
405 fout <<
"}" << std::endl;
434 xtit +=
" (" +
GetName() +
")";
450 Log() <<
kDEBUG <<
"Plot event variables for ";
456 if (theDirectory == 0) {
469 std::vector<std::vector<TH1*> > hVars( ncls );
470 std::vector<std::vector<std::vector<TH2F*> > > mycorr( ncls );
471 std::vector<std::vector<std::vector<TProfile*> > > myprof( ncls );
473 for (
Int_t cls = 0; cls < ncls; cls++) {
474 hVars.at(cls).resize ( nvar+ntgt );
475 hVars.at(cls).assign ( nvar+ntgt, 0 );
476 mycorr.at(cls).resize( nvar+ntgt );
477 myprof.at(cls).resize( nvar+ntgt );
478 for (
UInt_t ivar=0; ivar < nvar+ntgt; ivar++) {
479 mycorr.at(cls).at(ivar).resize( nvar+ntgt );
480 myprof.at(cls).at(ivar).resize( nvar+ntgt );
481 mycorr.at(cls).at(ivar).assign( nvar+ntgt, 0 );
482 myprof.at(cls).at(ivar).assign( nvar+ntgt, 0 );
489 if (nvar+ntgt > (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
490 Int_t nhists = (nvar+ntgt)*(nvar+ntgt - 1)/2;
492 Log() <<
kINFO <<
"<PlotVariables> Will not produce scatter plots ==> " <<
Endl;
494 <<
"| The number of " << nvar <<
" input variables and " << ntgt <<
" target values would require " 495 << nhists <<
" two-dimensional" <<
Endl;
497 <<
"| histograms, which would occupy the computer's memory. Note that this" <<
Endl;
499 <<
"| suppression does not have any consequences for your analysis, other" <<
Endl;
501 <<
"| than not disposing of these scatter plots. You can modify the maximum" <<
Endl;
503 <<
"| number of input variables allowed to generate scatter plots in your" <<
Endl;
504 Log() <<
"| script via the command line:" <<
Endl;
506 <<
"| \"(TMVA::gConfig().GetVariablePlotting()).fMaxNumOfAllowedVariablesForScatterPlots = <some int>;\"" 516 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++) {
517 UInt_t nloops = ( var_tgt == 0? nvar:ntgt );
518 for (
UInt_t ivar=0; ivar<nloops; ivar++) {
525 for (
Int_t cls = 0; cls < ncls; cls++) {
530 className += (ntgt == 1 && var_tgt == 1 ?
"_target" :
"");
549 if (xmin >= xmax) xmax = xmin*1.1;
550 if (xmin >= xmax) xmax = xmin + 1;
552 xmax += (xmax -
xmin)/nbins1D;
560 hVars.at(cls).at((var_tgt*nvar)+ivar) =
h;
563 if (nvar+ntgt <= (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
565 for (
UInt_t v_t = 0; v_t < 2; v_t++) {
566 UInt_t nl = ( v_t==0?nvar:ntgt );
567 UInt_t start = ( v_t==0? (var_tgt==0?ivar+1:0):(var_tgt==0?nl:ivar+1) );
568 for (
UInt_t j=start; j<nl; j++) {
580 className.
Data(), transfType.
Data() ),
582 className.
Data(), transfType.
Data() ),
583 nbins2D, rxmin , rxmax,
584 nbins2D, rymin , rymax );
588 mycorr.at(cls).at((var_tgt*nvar)+ivar).at((v_t*nvar)+j) = h2;
594 Form(
"profile %s versus %s (%s)%s",
596 className.
Data(), transfType.
Data() ), nbins1D,
602 myprof.at(cls).at((var_tgt*nvar)+ivar).at((v_t*nvar)+j) = p;
610 UInt_t nevts = events.size();
613 std::vector<Double_t> xregmean ( nvar+1, 0 );
614 std::vector<Double_t> x2regmean( nvar+1, 0 );
615 std::vector<Double_t> xCregmean( nvar+1, 0 );
618 for (
UInt_t ievt=0; ievt<nevts; ievt++) {
620 const Event* ev = events[ievt];
628 xregmean[nvar] += valr;
629 x2regmean[nvar] += valr*valr;
630 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
632 xregmean[ivar] += vali;
633 x2regmean[ivar] += vali*vali;
634 xCregmean[ivar] += vali*valr;
639 for (
UInt_t var_tgt = 0; var_tgt < 2; var_tgt++) {
640 UInt_t nloops = ( var_tgt == 0? nvar:ntgt );
641 for (
UInt_t ivar=0; ivar<nloops; ivar++) {
645 hVars.at(cls).at( ( var_tgt*nvar )+ivar)->Fill( vali, weight );
648 if (nvar+ntgt <= (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
650 for (
UInt_t v_t = 0; v_t < 2; v_t++) {
651 UInt_t nl = ( v_t==0 ? nvar : ntgt );
652 UInt_t start = ( v_t==0 ? (var_tgt==0?ivar+1:0) : (var_tgt==0?nl:ivar+1) );
653 for (
UInt_t j=start; j<nl; j++) {
655 mycorr.at(cls).at( ( var_tgt*nvar )+ivar).at( ( v_t*nvar )+j)->Fill( vali, valj, weight );
656 myprof.at(cls).at( ( var_tgt*nvar )+ivar).at( ( v_t*nvar )+j)->Fill( vali, valj, weight );
666 for (
UInt_t ivar=0; ivar<=nvar; ivar++) {
667 xregmean[ivar] /= nevts;
668 x2regmean[ivar] = x2regmean[ivar]/nevts - xregmean[ivar]*xregmean[ivar];
670 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
671 xCregmean[ivar] = xCregmean[ivar]/nevts - xregmean[ivar]*xregmean[nvar];
672 xCregmean[ivar] /=
TMath::Sqrt( x2regmean[ivar]*x2regmean[nvar] );
676 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
685 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
686 TH2F*
h1 = mycorr.at(0).at( nvar ).at( ivar );
693 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
694 TH2F* h2 = mycorr.at(0).at( nvar ).at( ivar );
701 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
716 for (
UInt_t i=0; i<nvar; i++) {
729 if (theDirectory == 0) {
735 outputDir +=
"_" +
TString(trf->GetShortName());
737 TString uniqueOutputDir = outputDir;
741 uniqueOutputDir = outputDir+
Form(
"_%d",counter);
761 for (
UInt_t i=0; i<nvar+ntgt; i++) {
762 for (
Int_t cls = 0; cls < ncls; cls++) {
763 if (hVars.at(cls).at(i) != 0) {
764 hVars.at(cls).at(i)->Write();
765 hVars.at(cls).at(i)->SetDirectory(0);
766 delete hVars.at(cls).at(i);
772 if (nvar+ntgt <= (
UInt_t)
gConfig().GetVariablePlotting().fMaxNumOfAllowedVariablesForScatterPlots) {
774 localDir = localDir->
mkdir(
"CorrelationPlots" );
776 Log() <<
kDEBUG <<
"Create scatter and profile plots in target-file directory: " <<
Endl;
780 for (
UInt_t i=0; i<nvar+ntgt; i++) {
781 for (
UInt_t j=i+1; j<nvar+ntgt; j++) {
782 for (
Int_t cls = 0; cls < ncls; cls++) {
783 if (mycorr.at(cls).at(i).at(j) != 0 ) {
784 mycorr.at(cls).at(i).at(j)->Write();
785 mycorr.at(cls).at(i).at(j)->SetDirectory(0);
786 delete mycorr.at(cls).at(i).at(j);
788 if (myprof.at(cls).at(i).at(j) != 0) {
789 myprof.at(cls).at(i).at(j)->Write();
790 myprof.at(cls).at(i).at(j)->SetDirectory(0);
791 delete myprof.at(cls).at(i).at(j);
797 if (theDirectory != 0 ) theDirectory->
cd();
834 o <<
"#TR -*-*-*-*-*-*-* transformation " << i++ <<
": " << trf->
GetName() <<
" -*-*-*-*-*-*-*-" << std::endl;
835 trf->WriteTransformationToStream(o);
838 if (ci == 0 ) clsName =
"AllClasses";
840 o <<
"ReferenceClass " << clsName << std::endl;
865 Log() <<
kFATAL <<
"Read transformations not implemented" <<
Endl;
881 if (trfname ==
"Decorrelation" ) {
884 else if (trfname ==
"PCA" ) {
887 else if (trfname ==
"Gauss" ) {
890 else if (trfname ==
"Uniform" ) {
893 else if (trfname ==
"Normalize" ) {
896 else if (trfname ==
"Rearrange" ) {
899 else if (trfname !=
"None") {
902 Log() <<
kFATAL <<
"<ReadFromXML> Variable transform '" 903 << trfname <<
"' unknown." <<
Endl;
917 Log() <<
kINFO <<
"Ranking input variables (method unspecific)..." <<
Endl;
918 std::vector<Ranking*>::const_iterator it =
fRanking.begin();
919 for (; it !=
fRanking.end(); it++) (*it)->Print();
934 Log() <<
kWARNING <<
"Inconsistent variable state when reading the mean value. " <<
Endl;
937 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
Short_t Min(Short_t a, Short_t b)
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory and return a pointer to the created directory.
UInt_t GetNClasses() const
const TString & GetLabel() const
static std::string format(double x, double y, int digits, int width)
const TString & GetExpression() const
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
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)
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
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