80 for (
Int_t i=0; i<numC; i++) {
81 fMin.at(i).resize(inputSize);
82 fMax.at(i).resize(inputSize);
83 fMin.at(i).assign(inputSize, 0);
84 fMax.at(i).assign(inputSize, 0);
95 Log() << kDEBUG <<
"\tPreparing the transformation." <<
Endl;
111 if (!
IsCreated())
Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
120 if (cls < 0 || cls >= (
int)
fMin.size()) cls =
fMin.size()-1;
125 std::vector<Char_t> mask;
135 std::vector<Char_t>::iterator itMask = mask.begin();
136 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) {
146 min = minVector.at(iidx);
147 max = maxVector.at(iidx);
151 Float_t valnorm = (val-offset)*scale * 2 - 1;
152 output.push_back( valnorm );
167 if (!
IsCreated())
Log() << kFATAL <<
"Transformation not yet created" <<
Endl;
178 std::vector<Char_t> mask;
188 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) {
191 min = minVector.at(iidx);
192 max = maxVector.at(iidx);
196 Float_t valnorm = offset+((val+1)/(scale * 2));
197 output.push_back( valnorm );
212 if (events.size() <= 1)
213 Log() << kFATAL <<
"Not enough events (found " << events.size() <<
") to calculate the normalization" <<
Endl;
216 std::vector<Char_t> mask;
228 for (
UInt_t iinp=0; iinp<inputSize; ++iinp) {
229 for (
Int_t ic = 0; ic < numC; ic++) {
230 fMin.at(ic).at(iinp) = FLT_MAX;
231 fMax.at(ic).at(iinp) = -FLT_MAX;
235 std::vector<Event*>::const_iterator evIt = events.begin();
236 for (;evIt!=events.end();evIt++) {
249 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) {
252 if( minVector.at(iidx) > val ) minVector.at(iidx) = val;
253 if( maxVector.at(iidx) < val ) maxVector.at(iidx) = val;
256 if (minVectorAll.at(iidx) > val) minVectorAll.at(iidx) = val;
257 if (maxVectorAll.at(iidx) < val) maxVectorAll.at(iidx) = val;
278 std::vector<TString>* strVec =
new std::vector<TString>(size);
282 min =
fMin.at(cls).at(iinp);
283 max =
fMax.at(cls).at(iinp);
286 UInt_t idx = (*itGet).second;
292 if (offset < 0) str =
Form(
"2*%g*([%s] + %g) - 1", scale, varInfo.
GetLabel().
Data(), -offset );
293 else str =
Form(
"2*%g*([%s] - %g) - 1", scale, varInfo.
GetLabel().
Data(), offset );
294 (*strVec)[iinp] = str;
307 o <<
"# min max for all variables for all classes one after the other and as a last entry for all classes together" << std::endl;
315 for (
Int_t icls = 0; icls < numC; icls++ ) {
316 o << icls << std::endl;
317 for (
UInt_t ivar=0; ivar<nvars; ivar++)
318 o << std::setprecision(12) << std::setw(20) <<
fMin.at(icls).at(ivar) <<
" " 319 << std::setprecision(12) << std::setw(20) <<
fMax.at(icls).at(ivar) << std::endl;
320 for (
UInt_t itgt=0; itgt<ntgts; itgt++)
321 o << std::setprecision(12) << std::setw(20) <<
fMin.at(icls).at(nvars+itgt) <<
" " 322 << std::setprecision(12) << std::setw(20) <<
fMax.at(icls).at(nvars+itgt) << std::endl;
324 o <<
"##" << std::endl;
338 for(
Int_t icls=0; icls<numC; icls++ ) {
360 void* inpnode =
NULL;
363 if( inpnode !=
NULL )
382 fMin.resize(classindex+1);
383 fMax.resize(classindex+1);
391 if(nodeName==
"Ranges") {
409 UInt_t classindex, varindex, tgtindex, nvars, ntgts;
416 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
417 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
419 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
420 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
426 fMin.resize(classindex+1);
427 fMax.resize(classindex+1);
434 if(nodeName==
"Variables") {
442 }
else if (nodeName==
"Targets") {
467 if(var.size() != nvars)
468 Log() << kFATAL <<
"<BuildTransformationFromVarInfo> can't build transformation," 469 <<
" since the number of variables disagree" <<
Endl;
476 for(
UInt_t cls=0; cls<numC; ++cls) {
480 for(std::vector<TMVA::VariableInfo>::const_iterator
v = var.begin();
v!=var.end(); ++
v, ++vidx) {
481 fMin[cls][vidx] =
v->GetMin();
482 fMax[cls][vidx] =
v->GetMax();
483 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',vidx));
496 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
497 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
499 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
500 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
504 istr.getline(buf,512);
508 while (!(buf[0]==
'#'&& buf[1]==
'#')) {
510 while (*p==
' ' || *p==
'\t') p++;
511 if (*p==
'#' || *p==
'\0') {
512 istr.getline(buf,512);
515 std::stringstream sstr(buf);
517 for (
UInt_t ivar=0;ivar<nvars;ivar++) {
518 istr.getline(buf2,512);
519 std::stringstream sstr2(buf2);
520 sstr2 >>
fMin[icls][ivar] >>
fMax[icls][ivar];
522 for (
UInt_t itgt=0;itgt<ntgts;itgt++) {
523 istr.getline(buf2,512);
524 std::stringstream sstr2(buf2);
525 sstr2 >>
fMin[icls][nvars+itgt] >>
fMax[icls][nvars+itgt];
527 istr.getline(buf,512);
539 if (nCls <= 1 ) numC = 1;
540 for (
Int_t icls = 0; icls < numC; icls++ ) {
542 Log() << kINFO <<
"Transformation for all classes based on these ranges:" <<
Endl;
544 Log() << kINFO <<
"Transformation for class " << icls <<
" based on these ranges:" <<
Endl;
548 UInt_t idx = (*itGet).second;
550 TString typeString = (type==
'v'?
"Variable: ": (type==
't'?
"Target : ":
"Spectator : ") );
551 Log() << typeString.
Data() << std::setw(20) <<
fMin[icls][idx] << std::setw(20) <<
fMax[icls][idx] <<
Endl;
569 fout <<
" double fMin_"<<trCounter<<
"["<<numC<<
"]["<<nVar<<
"];" << std::endl;
570 fout <<
" double fMax_"<<trCounter<<
"["<<numC<<
"]["<<nVar<<
"];" << std::endl;
575 fout <<
"//_______________________________________________________________________" << std::endl;
576 fout <<
"inline void " << fcncName <<
"::InitTransform_"<<trCounter<<
"()" << std::endl;
577 fout <<
"{" << std::endl;
578 fout <<
" // Normalization transformation, initialisation" << std::endl;
579 for (
UInt_t ivar=0; ivar<nVar; ivar++) {
580 for (
UInt_t icls = 0; icls < numC; icls++) {
583 fout <<
" fMin_"<<trCounter<<
"["<<icls<<
"]["<<ivar<<
"] = " << std::setprecision(12)
584 << min <<
";" << std::endl;
585 fout <<
" fMax_"<<trCounter<<
"["<<icls<<
"]["<<ivar<<
"] = " << std::setprecision(12)
586 << max <<
";" << std::endl;
589 fout <<
"}" << std::endl;
591 fout <<
"//_______________________________________________________________________" << std::endl;
592 fout <<
"inline void " << fcncName <<
"::Transform_"<<trCounter<<
"( std::vector<double>& iv, int cls) const" << std::endl;
593 fout <<
"{" << std::endl;
594 fout <<
" // Normalization transformation" << std::endl;
595 fout <<
" if (cls < 0 || cls > "<<
GetNClasses()<<
") {"<< std::endl;
597 fout <<
" else cls = "<<(
fMin.size()==1?0:2)<<
";"<< std::endl;
598 fout <<
" }"<< std::endl;
599 fout <<
" const int nVar = " << nVar <<
";" << std::endl << std::endl;
600 fout <<
" // get indices of used variables" << std::endl;
602 fout <<
" static std::vector<double> dv;" << std::endl;
603 fout <<
" dv.resize(nVar);" << std::endl;
604 fout <<
" for (int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];" << std::endl;
606 fout <<
" for (int ivar=0;ivar<"<<nVar<<
";ivar++) {" << std::endl;
607 fout <<
" double offset = fMin_"<<trCounter<<
"[cls][ivar];" << std::endl;
608 fout <<
" double scale = 1.0/(fMax_"<<trCounter<<
"[cls][ivar]-fMin_"<<trCounter<<
"[cls][ivar]);" << std::endl;
609 fout <<
" iv[indicesPut.at(ivar)] = (dv[ivar]-offset)*scale * 2 - 1;" << std::endl;
610 fout <<
" }" << std::endl;
611 fout <<
"}" << std::endl;
MsgLogger & Endl(MsgLogger &ml)
Singleton class for Global types used by TMVA.
Short_t Min(Short_t a, Short_t b)
const TString & GetLabel() const
Class that contains all the data information.
VariableInfo & GetTargetInfo(Int_t i)
char * Form(const char *fmt,...)
static RooMathCoreReg dummy
VariableInfo & GetSpectatorInfo(Int_t i)
VariableInfo & GetVariableInfo(Int_t i)
Abstract ClassifierFactory template that handles arbitrary types.
Short_t Max(Short_t a, Short_t b)
Class for type info of MVA input variable.
const char * Data() const