97 Log() << kINFO <<
"Preparing the Gaussian transformation..." <<
Endl;
102 if (inputSize > 200) {
103 Log() << kWARNING <<
"----------------------------------------------------------------------------"
106 <<
": More than 200 variables, I hope you have enough memory!!!!" <<
Endl;
107 Log() << kWARNING <<
"----------------------------------------------------------------------------"
124 if (!
IsCreated())
Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
136 std::vector<Float_t>
input(0);
137 std::vector<Float_t>
output(0);
139 std::vector<Char_t>
mask;
142 std::vector<Char_t>::iterator itMask =
mask.begin();
148 for (
UInt_t ivar=0; ivar<inputSize; ivar++) {
165 output.push_back( cumulant );
168 Double_t maxErfInvArgRange = 0.99999999;
193 if (!
IsCreated())
Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
205 std::vector<Float_t>
input(0);
206 std::vector<Float_t>
output(0);
208 std::vector<Char_t>
mask;
211 std::vector<Char_t>::iterator itMask =
mask.begin();
217 for (
UInt_t ivar=0; ivar<inputSize; ivar++) {
225 invCumulant =
input.at(ivar);
229 invCumulant = (
TMath::Erf(invCumulant/1.414213562)+1)/2.f;
235 Log() << kFATAL <<
"Inverse Uniform/Gauss transformation not implemented for TMVA versions before 4.1.0" <<
Endl;
237 output.push_back(invCumulant);
257 UInt_t nevt = events.size();
260 UInt_t numDist = nClasses+1;
266 std::list< TMVA::TMVAGaussPair > **listsForBinning =
new std::list<TMVA::TMVAGaussPair>* [numDist];
267 std::vector< Float_t > **vsForBinning =
new std::vector<Float_t>* [numDist];
269 listsForBinning[
i] =
new std::list<TMVA::TMVAGaussPair> [inputSize];
270 vsForBinning[
i] =
new std::vector<Float_t> [inputSize];
271 nbins[
i] =
new UInt_t[inputSize];
274 std::vector<Float_t>
input;
275 std::vector<Char_t>
mask;
286 for (
UInt_t ievt=0; ievt < nevt; ievt++) {
287 const Event* ev= events[ievt];
290 sumOfWeights[cls] += eventWeight;
291 if (minWeight[cls] > eventWeight) minWeight[cls]=eventWeight;
292 if (maxWeight[cls] < eventWeight) maxWeight[cls]=eventWeight;
293 if (numDist>1) sumOfWeights[numDist-1] += eventWeight;
296 if( hasMaskedEntries ){
297 Log() << kWARNING <<
"Incomplete event" <<
Endl;
298 std::ostringstream oss;
301 Log() << kFATAL <<
"Targets or variables masked by transformation. Apparently (a) value(s) is/are missing in this event." <<
Endl;
306 for( std::vector<Float_t>::iterator itInput =
input.begin(), itInputEnd =
input.end(); itInput != itInputEnd; ++itInput ) {
314 for (
UInt_t icl=0; icl<numDist-1; icl++){
315 minWeight[numDist-1] =
TMath::Min(minWeight[icl],minWeight[numDist-1]);
316 maxWeight[numDist-1] =
TMath::Max(maxWeight[icl],maxWeight[numDist-1]);
322 const UInt_t nbinsmax=2000;
324 for (
UInt_t icl=0; icl< numDist; icl++){
325 for (
UInt_t ivar=0; ivar<inputSize; ivar++) {
326 listsForBinning[icl][ivar].sort();
327 std::list< TMVA::TMVAGaussPair >::iterator it;
328 Float_t sumPerBin = sumOfWeights[icl]/nbinsmax;
329 sumPerBin=
TMath::Max(minWeight[icl]*nevmin,sumPerBin);
331 Float_t ev_value=listsForBinning[icl][ivar].begin()->GetValue();
334 vsForBinning[icl][ivar].push_back(ev_value-eps);
335 vsForBinning[icl][ivar].push_back(ev_value);
337 for (it=listsForBinning[icl][ivar].begin(); it != listsForBinning[icl][ivar].end(); ++it){
338 sum+= it->GetWeight();
339 if (
sum >= sumPerBin) {
340 ev_value=it->GetValue();
341 if (ev_value>lastev_value) {
342 vsForBinning[icl][ivar].push_back(ev_value);
344 lastev_value=ev_value;
348 if (
sum!=0) vsForBinning[icl][ivar].push_back(listsForBinning[icl][ivar].back().GetValue());
349 nbins[icl][ivar] = vsForBinning[icl][ivar].size();
353 delete[] sumOfWeights;
359 for (
UInt_t icls = 0; icls < numDist; icls++) {
360 for (
UInt_t ivar=0; ivar < inputSize; ivar++){
363 for (
UInt_t k =0 ; k < nbins[icls][ivar]; k++){
364 binnings[k] = vsForBinning[icls][ivar][k];
372 nbins[icls][ivar] -1,
381 delete [] listsForBinning[numDist-
i-1];
382 delete [] vsForBinning[numDist-
i-1];
383 delete [] nbins[numDist-
i-1];
385 delete [] listsForBinning;
386 delete [] vsForBinning;
390 std::vector<Int_t> ic(numDist);
391 for (
UInt_t ievt=0; ievt<nevt; ievt++) {
393 const Event* ev= events[ievt];
400 for( std::vector<Float_t>::iterator itInput =
input.begin(), itInputEnd =
input.end(); itInput != itInputEnd; ++itInput ) {
415 for (
UInt_t ivar=0; ivar<inputSize; ivar++) {
417 for (
UInt_t icls=0; icls<numDist; icls++) {
423 if (val>0)
total += val;
427 if (val>0)
sum += val;
440 Log() << kFATAL <<
"VariableGaussTransform::WriteTransformationToStream is obsolete" <<
Endl;
447 if (opt ==
"ALL" || opt ==
"PDF"){
455 if (opt ==
"ALL" || opt ==
"Dist"){
475 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
482 Log() << kFATAL <<
"Cumulative histograms for variable " << ivar <<
" don't exist, can't write it to weight file" <<
Endl;
506 void* inpnode = NULL;
512 void* varnode = NULL;
524 TString varname, histname, classname;
527 if(
gTools().HasAttr(varnode,
"Name") )
556 istr.getline(buf,512);
560 while (!(buf[0]==
'#'&& buf[1]==
'#')) {
562 while (*p==
' ' || *p==
'\t') p++;
563 if (*p==
'#' || *p==
'\0') {
564 istr.getline(buf,512);
567 std::stringstream sstr(buf);
570 if (strvar==
"CumulativeHistogram") {
572 TString devnullS(
""),hname(
"");
581 for (
Int_t ibin=0; ibin<nbins+1; ibin++) {
590 if ( histToRead !=0 )
delete histToRead;
592 histToRead =
new TH1F( hname, hname, nbins, Binnings );
597 for (
Int_t ibin=0; ibin<nbins; ibin++) {
611 if (strvar==
"Uniform") {
613 istr.getline(buf,512);
617 istr.getline(buf,512);
621 UInt_t classIdx=(classname==
"signal")?0:1;
658 if (bin >
h->GetNbinsX()) {
662 if (bin ==
h->GetNbinsX()) {
669 cumulant = y0 + (
y1-y0)*(
x-x0)/(
x1-x0);
675 if (
x >=
h->GetBinLowEdge(
h->GetNbinsX()+1)){
687 Log() << kINFO <<
"I do not know yet how to print this... look in the weight file " << cls <<
":" <<
Endl;
701 for (
UInt_t icls=0; icls<numDist; icls++) {
702 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
704 if (nbin > nBins) nBins=nbin;
711 fout <<
" int nvar;" << std::endl;
714 fout <<
" double cumulativeDist["<<nvar<<
"]["<<numDist<<
"]["<<nBins+1<<
"];"<<std::endl;
715 fout <<
" double X["<<nvar<<
"]["<<numDist<<
"]["<<nBins+1<<
"];"<<std::endl;
716 fout <<
" double xMin["<<nvar<<
"]["<<numDist<<
"];"<<std::endl;
717 fout <<
" double xMax["<<nvar<<
"]["<<numDist<<
"];"<<std::endl;
718 fout <<
" int nbins["<<nvar<<
"]["<<numDist<<
"];"<<std::endl;
722 fout <<
"#include \"math.h\"" << std::endl;
724 fout <<
"//_______________________________________________________________________" << std::endl;
725 fout <<
"inline void " << fcncName <<
"::InitTransform_"<<trCounter<<
"()" << std::endl;
726 fout <<
"{" << std::endl;
727 fout <<
" // Gauss/Uniform transformation, initialisation" << std::endl;
728 fout <<
" nvar=" << nvar <<
";" << std::endl;
729 for (
UInt_t icls=0; icls<numDist; icls++) {
730 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
732 fout <<
" nbins["<<ivar<<
"]["<<icls<<
"]="<<nbin<<
";"<<std::endl;
739 for (
UInt_t icls=0; icls<numDist; icls++) {
740 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
746 Log() << kWARNING <<
"MakeClass for the Gauss transformation works only for the transformation of variables. The transformation of targets/spectators is not implemented." <<
Endl;
748 }
catch( std::out_of_range &){
749 Log() << kWARNING <<
"MakeClass for the Gauss transformation searched for a non existing variable index (" << ivar <<
")" <<
Endl;
766 fout <<
"}" << std::endl;
768 fout <<
"//_______________________________________________________________________" << std::endl;
769 fout <<
"inline void " << fcncName <<
"::Transform_"<<trCounter<<
"( std::vector<double>& iv, int clsIn) const" << std::endl;
770 fout <<
"{" << std::endl;
771 fout <<
" // Gauss/Uniform transformation" << std::endl;
772 fout <<
" int cls=clsIn;" << std::endl;
773 fout <<
" if (cls < 0 || cls > "<<
GetNClasses()<<
") {"<< std::endl;
775 fout <<
" else cls = "<<(
fCumulativePDF[0].size()==1?0:2)<<
";"<< std::endl;
776 fout <<
" }"<< std::endl;
778 fout <<
" // copy the variables which are going to be transformed "<< std::endl;
780 fout <<
" static std::vector<double> dv; "<< std::endl;
781 fout <<
" dv.resize(nvar); "<< std::endl;
782 fout <<
" for (int ivar=0; ivar<nvar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)]; "<< std::endl;
783 fout <<
" "<< std::endl;
784 fout <<
" bool FlatNotGauss = "<< (
fFlatNotGauss?
"true":
"false") <<
"; "<< std::endl;
785 fout <<
" double cumulant; "<< std::endl;
786 fout <<
" //const int nvar = "<<nvar<<
"; "<< std::endl;
787 fout <<
" for (int ivar=0; ivar<nvar; ivar++) { "<< std::endl;
788 fout <<
" int nbin = nbins[ivar][cls]; "<< std::endl;
789 fout <<
" int ibin=0; "<< std::endl;
790 fout <<
" while (dv[ivar] > X[ivar][cls][ibin]) ibin++; "<< std::endl;
791 fout <<
" "<< std::endl;
792 fout <<
" if (ibin<0) { ibin=0;} "<< std::endl;
793 fout <<
" if (ibin>=nbin) { ibin=nbin-1;} "<< std::endl;
794 fout <<
" int nextbin = ibin; "<< std::endl;
795 fout <<
" if ((dv[ivar] > X[ivar][cls][ibin] && ibin !=nbin-1) || ibin==0) "<< std::endl;
796 fout <<
" nextbin++; "<< std::endl;
797 fout <<
" else "<< std::endl;
798 fout <<
" nextbin--; "<< std::endl;
799 fout <<
" "<< std::endl;
800 fout <<
" double dx = X[ivar][cls][ibin]- X[ivar][cls][nextbin]; "<< std::endl;
801 fout <<
" double dy = cumulativeDist[ivar][cls][ibin] - cumulativeDist[ivar][cls][nextbin]; "<< std::endl;
802 fout <<
" cumulant = cumulativeDist[ivar][cls][ibin] + (dv[ivar] - X[ivar][cls][ibin])* dy/dx;"<< std::endl;
803 fout <<
" "<< std::endl;
804 fout <<
" "<< std::endl;
805 fout <<
" if (cumulant>1.-10e-10) cumulant = 1.-10e-10; "<< std::endl;
806 fout <<
" if (cumulant<10e-10) cumulant = 10e-10; "<< std::endl;
807 fout <<
" if (FlatNotGauss) dv[ivar] = cumulant; "<< std::endl;
808 fout <<
" else { "<< std::endl;
809 fout <<
" double maxErfInvArgRange = 0.99999999; "<< std::endl;
810 fout <<
" double arg = 2.0*cumulant - 1.0; "<< std::endl;
811 fout <<
" if (arg > maxErfInvArgRange) arg= maxErfInvArgRange; "<< std::endl;
812 fout <<
" if (arg < -maxErfInvArgRange) arg=-maxErfInvArgRange; "<< std::endl;
813 fout <<
" double inverf=0., stp=1. ; "<< std::endl;
814 fout <<
" while (stp >1.e-10){; "<< std::endl;
815 fout <<
" if (erf(inverf)>arg) inverf -=stp ; "<< std::endl;
816 fout <<
" else if (erf(inverf)<=arg && erf(inverf+stp)>=arg) stp=stp/5. ; "<< std::endl;
817 fout <<
" else inverf += stp; "<< std::endl;
818 fout <<
" } ; "<< std::endl;
819 fout <<
" //dv[ivar] = 1.414213562*TMath::ErfInverse(arg); "<< std::endl;
820 fout <<
" dv[ivar] = 1.414213562* inverf; "<< std::endl;
821 fout <<
" } "<< std::endl;
822 fout <<
" } "<< std::endl;
823 fout <<
" // copy the transformed variables back "<< std::endl;
824 fout <<
" for (int ivar=0; ivar<nvar; ivar++) iv[indicesPut.at(ivar)] = dv[ivar]; "<< std::endl;
825 fout <<
"} "<< std::endl;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static unsigned int total
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char y1
#define TMVA_VERSION(a, b, c)
1-D histogram with a float per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Class that contains all the data information.
UInt_t GetNVariables() const
accessor to the number of variables
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
void Print(std::ostream &o) const
print method
PDF wrapper for histograms; uses user-defined spline interpolation.
void ReadXML(void *pdfnode)
XML file reading.
Singleton class for Global types used by TMVA.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
MsgLogger & Endl(MsgLogger &ml)
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Erf(Double_t x)
Computation of the error function erf(x).
Double_t ErfInverse(Double_t x)
Returns the inverse error function.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
static uint64_t sum(uint64_t i)