76 UInt_t inputSize = fGet.size();
77 Int_t numC = GetNClasses()+1;
78 if (GetNClasses() <= 1 ) numC = 1;
82 for (
Int_t i=0; i<numC; i++) {
83 fMin.at(i).resize(inputSize);
84 fMax.at(i).resize(inputSize);
85 fMin.at(i).assign(inputSize, 0);
86 fMax.at(i).assign(inputSize, 0);
95 if (!IsEnabled() || IsCreated())
return kTRUE;
97 Log() << kDEBUG <<
"\tPreparing the transformation." <<
Endl;
101 CalcNormalizationParams( events );
113 if (!IsCreated()) Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
122 if (cls < 0 || cls >= (
int) fMin.size()) cls = fMin.size()-1;
127 std::vector<Char_t>
mask;
130 if (fTransformedEvent==0) fTransformedEvent =
new Event();
137 std::vector<Char_t>::iterator itMask =
mask.begin();
138 for ( std::vector<Float_t>::iterator itInp =
input.begin(), itInpEnd =
input.end(); itInp != itInpEnd; ++itInp) {
148 min = minVector.at(iidx);
149 max = maxVector.at(iidx);
155 valnorm = (val-
offset)*scale * 2 - 1;
157 fabs(max)>fabs(min) ? valnorm=val/fabs(max) : valnorm=val/fabs(min);
160 output.push_back( valnorm );
166 SetOutput( fTransformedEvent, output,
mask, ev );
167 return fTransformedEvent;
175 if (!IsCreated()) Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
179 if (cls < 0 || cls > GetNClasses()) {
180 if (GetNClasses() > 1 ) cls = GetNClasses();
186 std::vector<Char_t>
mask;
189 if (fBackTransformedEvent==0) fBackTransformedEvent =
new Event( *ev );
196 for ( std::vector<Float_t>::iterator itInp =
input.begin(), itInpEnd =
input.end(); itInp != itInpEnd; ++itInp) {
199 min = minVector.at(iidx);
200 max = maxVector.at(iidx);
206 valnorm =
offset+((val+1)/(scale * 2));
208 fabs(max)>fabs(min) ? valnorm=val*fabs(max) : valnorm=val*fabs(min);
211 output.push_back( valnorm );
216 SetOutput( fBackTransformedEvent, output,
mask, ev,
kTRUE );
218 return fBackTransformedEvent;
226 if (events.size() <= 1)
227 Log() << kFATAL <<
"Not enough events (found " << events.size() <<
") to calculate the normalization" <<
Endl;
230 std::vector<Char_t>
mask;
232 UInt_t inputSize = fGet.size();
234 const UInt_t nCls = GetNClasses();
242 for (
UInt_t iinp=0; iinp<inputSize; ++iinp) {
243 for (
Int_t ic = 0; ic < numC; ic++) {
244 fMin.at(ic).at(iinp) = FLT_MAX;
245 fMax.at(ic).at(iinp) = -FLT_MAX;
249 std::vector<Event*>::const_iterator evIt = events.begin();
250 for (;evIt!=events.end();++evIt) {
253 UInt_t cls = (*evIt)->GetClass();
263 for ( std::vector<Float_t>::iterator itInp =
input.begin(), itInpEnd =
input.end(); itInp != itInpEnd; ++itInp) {
266 if( minVector.at(iidx) > val ) minVector.at(iidx) = val;
267 if( maxVector.at(iidx) < val ) maxVector.at(iidx) = val;
270 if (minVectorAll.at(iidx) > val) minVectorAll.at(iidx) = val;
271 if (maxVectorAll.at(iidx) < val) maxVectorAll.at(iidx) = val;
288 if (cls < 0 || cls > GetNClasses()) cls = GetNClasses();
292 std::vector<TString>* strVec =
new std::vector<TString>(
size);
295 for(
ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
296 min = fMin.at(cls).at(iinp);
297 max = fMax.at(cls).at(iinp);
300 UInt_t idx = (*itGet).second;
305 scale = 1.0/(max-min);
308 fabs(max)>fabs(min) ? scale=.5/fabs(max) : scale=.5/fabs(min);
311 VariableInfo& varInfo = (
type==
'v'?fDsi.GetVariableInfo(idx):(
type==
't'?fDsi.GetTargetInfo(idx):fDsi.GetSpectatorInfo(idx)));
315 (*strVec)[iinp] = str;
328 o <<
"# min max for all variables for all classes one after the other and as a last entry for all classes together" << std::endl;
330 Int_t numC = GetNClasses()+1;
331 if (GetNClasses() <= 1 ) numC = 1;
333 UInt_t nvars = GetNVariables();
334 UInt_t ntgts = GetNTargets();
336 for (
Int_t icls = 0; icls < numC; icls++ ) {
337 o << icls << std::endl;
338 for (
UInt_t ivar=0; ivar<nvars; ivar++)
339 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(ivar) <<
" "
340 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(ivar) << std::endl;
341 for (
UInt_t itgt=0; itgt<ntgts; itgt++)
342 o << std::setprecision(12) << std::setw(20) << fMin.at(icls).at(nvars+itgt) <<
" "
343 << std::setprecision(12) << std::setw(20) << fMax.at(icls).at(nvars+itgt) << std::endl;
345 o <<
"##" << std::endl;
355 gTools().
AddAttr(trfxml,
"UseOffsetOrNot", (fNoOffset?
"NoOffset":
"UseOffset") );
358 Int_t numC = (GetNClasses()<= 1)?1:GetNClasses()+1;
360 for(
Int_t icls=0; icls<numC; icls++ ) {
365 for(
ItVarTypeIdx itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ) {
381 if (
gTools().HasAttr(trfnode,
"UseOffsetOrNot")) {
386 if (UseOffsetOrNot ==
"NoOffset")
393 void* inpnode = NULL;
396 if( inpnode != NULL )
415 fMin.resize(classindex+1);
416 fMax.resize(classindex+1);
424 if(nodeName==
"Ranges") {
442 UInt_t classindex, varindex, tgtindex, nvars, ntgts;
449 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
450 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
452 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
453 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
459 fMin.resize(classindex+1);
460 fMax.resize(classindex+1);
461 fMin[classindex].resize(nvars+ntgts,
Float_t(0));
462 fMax[classindex].resize(nvars+ntgts,
Float_t(0));
467 if(nodeName==
"Variables") {
475 }
else if (nodeName==
"Targets") {
479 gTools().
ReadAttr(tgtch,
"Min", fMin[classindex][nvars+tgtindex]);
480 gTools().
ReadAttr(tgtch,
"Max", fMax[classindex][nvars+tgtindex]);
498 UInt_t nvars = GetNVariables();
500 if(var.size() != nvars)
501 Log() << kFATAL <<
"<BuildTransformationFromVarInfo> can't build transformation,"
502 <<
" since the number of variables disagree" <<
Endl;
504 UInt_t numC = (GetNClasses()<=1)?1:GetNClasses()+1;
505 fMin.clear();fMin.resize( numC );
506 fMax.clear();fMax.resize( numC );
509 for(
UInt_t cls=0; cls<numC; ++cls) {
510 fMin[cls].resize(nvars+GetNTargets(),0);
511 fMax[cls].resize(nvars+GetNTargets(),0);
513 for(std::vector<TMVA::VariableInfo>::const_iterator
v = var.begin();
v!=var.end(); ++
v, ++vidx) {
514 fMin[cls][vidx] =
v->GetMin();
515 fMax[cls][vidx] =
v->GetMax();
516 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',vidx));
527 UInt_t nvars = GetNVariables();
528 UInt_t ntgts = GetNTargets();
529 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
530 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
532 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
533 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
537 istr.getline(buf,512);
541 while (!(buf[0]==
'#'&& buf[1]==
'#')) {
543 while (*
p==
' ' || *
p==
'\t')
p++;
544 if (*
p==
'#' || *
p==
'\0') {
545 istr.getline(buf,512);
548 std::stringstream sstr(buf);
550 for (
UInt_t ivar=0;ivar<nvars;ivar++) {
551 istr.getline(buf2,512);
552 std::stringstream sstr2(buf2);
553 sstr2 >> fMin[icls][ivar] >> fMax[icls][ivar];
555 for (
UInt_t itgt=0;itgt<ntgts;itgt++) {
556 istr.getline(buf2,512);
557 std::stringstream sstr2(buf2);
558 sstr2 >> fMin[icls][nvars+itgt] >> fMax[icls][nvars+itgt];
560 istr.getline(buf,512);
570 Int_t nCls = GetNClasses();
572 if (nCls <= 1 ) numC = 1;
573 for (
Int_t icls = 0; icls < numC; icls++ ) {
575 Log() << kINFO <<
"Transformation for all classes based on these ranges:" <<
Endl;
577 Log() << kINFO <<
"Transformation for class " << icls <<
" based on these ranges:" <<
Endl;
578 for(
ItVarTypeIdxConst itGet = fGet.begin(), itGetEnd = fGet.end(); itGet != itGetEnd; ++itGet ){
580 UInt_t idx = (*itGet).second;
582 TString typeString = (
type==
'v'?
"Variable: ": (
type==
't'?
"Target : ":
"Spectator : ") );
583 Log() << typeString.
Data() << std::setw(20) << fMin[icls][idx] << std::setw(20) << fMax[icls][idx] <<
Endl;
596 UInt_t nVar = fGet.size();
597 UInt_t numC = fMin.size();
600 fout <<
" double fOff_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
601 fout <<
" double fScal_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
606 fout <<
"//_______________________________________________________________________" << std::endl;
607 fout <<
"inline void " << fcncName <<
"::InitTransform_" << trCounter <<
"()" << std::endl;
608 fout <<
"{" << std::endl;
609 fout <<
" double fMin_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
610 fout <<
" double fMax_" << trCounter <<
"[" << numC <<
"][" << nVar <<
"];" << std::endl;
611 fout <<
" // Normalization transformation, initialisation" << std::endl;
612 for (
UInt_t ivar = 0; ivar < nVar; ivar++) {
613 for (
UInt_t icls = 0; icls < numC; icls++) {
616 fout <<
" fMin_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = " << std::setprecision(12) << min
618 fout <<
" fMax_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = " << std::setprecision(12) << max
620 fout <<
" fScal_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = 2.0/(fMax_" << trCounter <<
"["
621 << icls <<
"][" << ivar <<
"]-fMin_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"]);" << std::endl;
622 fout <<
" fOff_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"] = fMin_" << trCounter <<
"[" << icls
623 <<
"][" << ivar <<
"]*fScal_" << trCounter <<
"[" << icls <<
"][" << ivar <<
"]+1.;" << std::endl;
626 fout <<
"}" << std::endl;
628 fout <<
"//_______________________________________________________________________" << std::endl;
629 fout <<
"inline void " << fcncName <<
"::Transform_" << trCounter <<
"( std::vector<double>& iv, int cls) const"
631 fout <<
"{" << std::endl;
632 fout <<
" // Normalization transformation" << std::endl;
633 fout <<
" if (cls < 0 || cls > " << GetNClasses() <<
") {" << std::endl;
634 fout <<
" if (" << GetNClasses() <<
" > 1 ) cls = " << GetNClasses() <<
";" << std::endl;
635 fout <<
" else cls = " << (fMin.size() == 1 ? 0 : 2) <<
";" << std::endl;
636 fout <<
" }" << std::endl;
637 fout <<
" const int nVar = " << nVar <<
";" << std::endl << std::endl;
638 fout <<
" // get indices of used variables" << std::endl;
640 fout <<
" static std::vector<double> dv;"
642 fout <<
" dv.resize(nVar);" << std::endl;
643 fout <<
" for (int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];" << std::endl;
645 fout <<
" for (int ivar=0;ivar<" << nVar <<
";ivar++) {" << std::endl;
646 fout <<
" double offset = fOff_" << trCounter <<
"[cls][ivar];" << std::endl;
647 fout <<
" double scale = fScal_" << trCounter <<
"[cls][ivar];" << std::endl;
648 fout <<
" iv[indicesPut.at(ivar)] = scale*dv[ivar]-offset;" << std::endl;
649 fout <<
" }" << std::endl;
650 fout <<
"}" << std::endl;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char Char_t
Character 1 byte (char)
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
float Float_t
Float 4 bytes (float)
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.