73 UInt_t inputSize = fGet.size();
74 Int_t numC = GetNClasses()+1;
75 if (GetNClasses() <= 1 ) numC = 1;
79 for (
Int_t i=0; i<numC; i++) {
80 fMin.at(i).resize(inputSize);
81 fMax.at(i).resize(inputSize);
82 fMin.at(i).assign(inputSize, 0);
83 fMax.at(i).assign(inputSize, 0);
92 if (!IsEnabled() || IsCreated())
return kTRUE;
94 Log() << kDEBUG <<
"\tPreparing the transformation." <<
Endl;
98 CalcNormalizationParams( events );
110 if (!IsCreated()) Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
119 if (cls < 0 || cls >= (
int) fMin.size()) cls = fMin.size()-1;
124 std::vector<Char_t>
mask;
127 if (fTransformedEvent==0) fTransformedEvent =
new Event();
134 std::vector<Char_t>::iterator itMask =
mask.begin();
135 for ( std::vector<Float_t>::iterator itInp =
input.begin(), itInpEnd =
input.end(); itInp != itInpEnd; ++itInp) {
145 min = minVector.at(iidx);
146 max = maxVector.at(iidx);
151 output.push_back( valnorm );
157 SetOutput( fTransformedEvent,
output,
mask, ev );
158 return fTransformedEvent;
166 if (!IsCreated()) Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
170 if (cls < 0 || cls > GetNClasses()) {
171 if (GetNClasses() > 1 ) cls = GetNClasses();
177 std::vector<Char_t>
mask;
180 if (fBackTransformedEvent==0) fBackTransformedEvent =
new Event( *ev );
187 for ( std::vector<Float_t>::iterator itInp =
input.begin(), itInpEnd =
input.end(); itInp != itInpEnd; ++itInp) {
190 min = minVector.at(iidx);
191 max = maxVector.at(iidx);
196 output.push_back( valnorm );
203 return fBackTransformedEvent;
211 if (events.size() <= 1)
212 Log() << kFATAL <<
"Not enough events (found " << events.size() <<
") to calculate the normalization" <<
Endl;
215 std::vector<Char_t>
mask;
217 UInt_t inputSize = fGet.size();
219 const UInt_t nCls = GetNClasses();
227 for (
UInt_t iinp=0; iinp<inputSize; ++iinp) {
228 for (
Int_t ic = 0; ic < numC; ic++) {
229 fMin.at(ic).at(iinp) = FLT_MAX;
230 fMax.at(ic).at(iinp) = -FLT_MAX;
234 std::vector<Event*>::const_iterator evIt = events.begin();
235 for (;evIt!=events.end();++evIt) {
238 UInt_t cls = (*evIt)->GetClass();
248 for ( std::vector<Float_t>::iterator itInp =
input.begin(), itInpEnd =
input.end(); itInp != itInpEnd; ++itInp) {
251 if( minVector.at(iidx) > val ) minVector.at(iidx) = val;
252 if( maxVector.at(iidx) < val ) maxVector.at(iidx) = val;
255 if (minVectorAll.at(iidx) > val) minVectorAll.at(iidx) = val;
256 if (maxVectorAll.at(iidx) < val) maxVectorAll.at(iidx) = val;
273 if (cls < 0 || cls > GetNClasses()) cls = GetNClasses();
277 std::vector<TString>* strVec =
new std::vector<TString>(
size);
280 for(
ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
281 min = fMin.at(cls).at(iinp);
282 max = fMax.at(cls).at(iinp);
285 UInt_t idx = (*itGet).second;
289 VariableInfo& varInfo = (
type==
'v'?fDsi.GetVariableInfo(idx):(
type==
't'?fDsi.GetTargetInfo(idx):fDsi.GetSpectatorInfo(idx)));
293 (*strVec)[iinp] = str;
306 o <<
"# min max for all variables for all classes one after the other and as a last entry for all classes together" << std::endl;
308 Int_t numC = GetNClasses()+1;
309 if (GetNClasses() <= 1 ) numC = 1;
311 UInt_t nvars = GetNVariables();
312 UInt_t ntgts = GetNTargets();
314 for (
Int_t icls = 0; icls < numC; icls++ ) {
315 o << icls << std::endl;
316 for (
UInt_t ivar=0; ivar<nvars; ivar++)
317 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(ivar) <<
" "
318 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(ivar) << std::endl;
319 for (
UInt_t itgt=0; itgt<ntgts; itgt++)
320 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(nvars+itgt) <<
" "
321 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(nvars+itgt) << std::endl;
323 o <<
"##" << std::endl;
335 Int_t numC = (GetNClasses()<= 1)?1:GetNClasses()+1;
337 for(
Int_t icls=0; icls<numC; icls++ ) {
342 for(
ItVarTypeIdx itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
359 void* inpnode = NULL;
362 if( inpnode != NULL )
381 fMin.resize(classindex+1);
382 fMax.resize(classindex+1);
390 if(nodeName==
"Ranges") {
408 UInt_t classindex, varindex, tgtindex, nvars, ntgts;
415 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
416 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
418 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
419 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
425 fMin.resize(classindex+1);
426 fMax.resize(classindex+1);
427 fMin[classindex].resize(nvars+ntgts,
Float_t(0));
428 fMax[classindex].resize(nvars+ntgts,
Float_t(0));
433 if(nodeName==
"Variables") {
441 }
else if (nodeName==
"Targets") {
445 gTools().
ReadAttr(tgtch,
"Min", fMin[classindex][nvars+tgtindex]);
446 gTools().
ReadAttr(tgtch,
"Max", fMax[classindex][nvars+tgtindex]);
464 UInt_t nvars = GetNVariables();
466 if(var.size() != nvars)
467 Log() << kFATAL <<
"<BuildTransformationFromVarInfo> can't build transformation,"
468 <<
" since the number of variables disagree" <<
Endl;
470 UInt_t numC = (GetNClasses()<=1)?1:GetNClasses()+1;
471 fMin.clear();fMin.resize( numC );
472 fMax.clear();fMax.resize( numC );
475 for(
UInt_t cls=0; cls<numC; ++cls) {
476 fMin[cls].resize(nvars+GetNTargets(),0);
477 fMax[cls].resize(nvars+GetNTargets(),0);
479 for(std::vector<TMVA::VariableInfo>::const_iterator
v = var.begin();
v!=var.end(); ++
v, ++vidx) {
480 fMin[cls][vidx] =
v->GetMin();
481 fMax[cls][vidx] =
v->GetMax();
482 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',vidx));
493 UInt_t nvars = GetNVariables();
494 UInt_t ntgts = GetNTargets();
495 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
496 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
498 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
499 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
503 istr.getline(buf,512);
507 while (!(buf[0]==
'#'&& buf[1]==
'#')) {
509 while (*
p==
' ' || *
p==
'\t')
p++;
510 if (*
p==
'#' || *
p==
'\0') {
511 istr.getline(buf,512);
514 std::stringstream sstr(buf);
516 for (
UInt_t ivar=0;ivar<nvars;ivar++) {
517 istr.getline(buf2,512);
518 std::stringstream sstr2(buf2);
519 sstr2 >> fMin[icls][ivar] >> fMax[icls][ivar];
521 for (
UInt_t itgt=0;itgt<ntgts;itgt++) {
522 istr.getline(buf2,512);
523 std::stringstream sstr2(buf2);
524 sstr2 >> fMin[icls][nvars+itgt] >> fMax[icls][nvars+itgt];
526 istr.getline(buf,512);
536 Int_t nCls = GetNClasses();
538 if (nCls <= 1 ) numC = 1;
539 for (
Int_t icls = 0; icls < numC; icls++ ) {
541 Log() << kINFO <<
"Transformation for all classes based on these ranges:" <<
Endl;
543 Log() << kINFO <<
"Transformation for class " << icls <<
" based on these ranges:" <<
Endl;
544 for(
ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ){
546 UInt_t idx = (*itGet).second;
548 TString typeString = (
type==
'v'?
"Variable: ": (
type==
't'?
"Target : ":
"Spectator : ") );
549 Log() << typeString.
Data() << std::setw(20) << fMin[icls][idx] << std::setw(20) << fMax[icls][idx] <<
Endl;
562 UInt_t nVar = fGet.size();
563 UInt_t numC = fMin.size();
566 fout <<
" double fOff_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
567 fout <<
" double fScal_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
572 fout <<
"//_______________________________________________________________________" << std::endl;
573 fout <<
"inline void " << fcncName <<
"::InitTransform_" << trCounter <<
"()" << std::endl;
574 fout <<
"{" << std::endl;
575 fout <<
" double fMin_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
576 fout <<
" double fMax_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
577 fout <<
" // Normalization transformation, initialisation" << std::endl;
578 for (
UInt_t ivar = 0; ivar < nVar; ivar++) {
579 for (
UInt_t icls = 0; icls < numC; icls++) {
582 fout <<
" fMin_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = " << std::setprecision(12) << min
584 fout <<
" fMax_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = " << std::setprecision(12) << max
586 fout <<
" fScal_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = 2.0/(fMax_" << trCounter <<
"["
587 << icls <<
"][" << ivar <<
"]-fMin_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"]);" << std::endl;
588 fout <<
" fOff_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = fMin_" << trCounter <<
"[" << icls
589 <<
"][" << ivar <<
"]*fScal_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"]+1.;" << std::endl;
592 fout <<
"}" << std::endl;
594 fout <<
"//_______________________________________________________________________" << std::endl;
595 fout <<
"inline void " << fcncName <<
"::Transform_" << trCounter <<
"( std::vector<double>& iv, int cls) const"
597 fout <<
"{" << std::endl;
598 fout <<
" // Normalization transformation" << std::endl;
599 fout <<
" if (cls < 0 || cls > " << GetNClasses() <<
") {" << std::endl;
600 fout <<
" if (" << GetNClasses() <<
" > 1 ) cls = " << GetNClasses() <<
";" << std::endl;
601 fout <<
" else cls = " << (fMin.size() == 1 ? 0 : 2) <<
";" << std::endl;
602 fout <<
" }" << std::endl;
603 fout <<
" const int nVar = " << nVar <<
";" << std::endl << std::endl;
604 fout <<
" // get indices of used variables" << std::endl;
606 fout <<
" static std::vector<double> dv;"
608 fout <<
" dv.resize(nVar);" << std::endl;
609 fout <<
" for (int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];" << std::endl;
611 fout <<
" for (int ivar=0;ivar<" << nVar <<
";ivar++) {" << std::endl;
612 fout <<
" double offset = fOff_" << trCounter <<
"[cls][ivar];" << std::endl;
613 fout <<
" double scale = fScal_" << trCounter <<
"[cls][ivar];" << std::endl;
614 fout <<
" iv[indicesPut.at(ivar)] = scale*dv[ivar]-offset;" << std::endl;
615 fout <<
" }" << std::endl;
616 fout <<
"}" << std::endl;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
winID h TVirtualViewer3D TVirtualGLPainter p
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 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 offset
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
Class that contains all the data information.
Singleton class for Global types used by TMVA.
Class for type info of MVA input variable.
const TString & GetLabel() const
const char * Data() const
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.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.