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);
97 Log() << kDEBUG <<
"\tPreparing the transformation." <<
Endl;
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;
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 );
175 if (!
IsCreated())
Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
186 std::vector<Char_t> mask;
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 );
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;
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;
292 std::vector<TString>* strVec =
new std::vector<TString>(
size);
296 min =
fMin.at(cls).at(iinp);
297 max =
fMax.at(cls).at(iinp);
299 Char_t type = (*itGet).first;
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;
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;
360 for(
Int_t icls=0; icls<numC; icls++ ) {
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);
467 if(nodeName==
"Variables") {
475 }
else if (nodeName==
"Targets") {
500 if(var.size() != nvars)
501 Log() << kFATAL <<
"<BuildTransformationFromVarInfo> can't build transformation,"
502 <<
" since the number of variables disagree" <<
Endl;
509 for(
UInt_t cls=0; cls<numC; ++cls) {
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));
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);
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;
579 Char_t type = (*itGet).first;
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;
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;
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
int Int_t
Signed integer 4 bytes (int).
char Char_t
Character 1 byte (char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
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.