75 for (
Int_t i=0; i<numC; i++) {
76 fMin.at(i).resize(inputSize);
77 fMax.at(i).resize(inputSize);
78 fMin.at(i).assign(inputSize, 0);
79 fMax.at(i).assign(inputSize, 0);
115 if (cls < 0 || cls >= (
int)
fMin.size()) cls =
fMin.size()-1;
120 std::vector<Char_t> mask;
130 std::vector<Char_t>::iterator itMask = mask.begin();
131 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) {
141 min = minVector.at(iidx);
142 max = maxVector.at(iidx);
146 Float_t valnorm = (val-offset)*scale * 2 - 1;
147 output.push_back( valnorm );
173 std::vector<Char_t> mask;
183 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) {
186 min = minVector.at(iidx);
187 max = maxVector.at(iidx);
191 Float_t valnorm = offset+((val+1)/(scale * 2));
192 output.push_back( valnorm );
207 if (events.size() <= 1)
208 Log() <<
kFATAL <<
"Not enough events (found " << events.size() <<
") to calculate the normalization" <<
Endl;
211 std::vector<Char_t> mask;
223 for (
UInt_t iinp=0; iinp<inputSize; ++iinp) {
224 for (
Int_t ic = 0; ic < numC; ic++) {
225 fMin.at(ic).at(iinp) = FLT_MAX;
226 fMax.at(ic).at(iinp) = -FLT_MAX;
230 std::vector<Event*>::const_iterator evIt = events.begin();
231 for (;evIt!=events.end();evIt++) {
244 for ( std::vector<Float_t>::iterator itInp = input.begin(), itInpEnd = input.end(); itInp != itInpEnd; ++itInp) {
247 if( minVector.at(iidx) > val ) minVector.at(iidx) = val;
248 if( maxVector.at(iidx) < val ) maxVector.at(iidx) = val;
251 if (minVectorAll.at(iidx) > val) minVectorAll.at(iidx) = val;
252 if (maxVectorAll.at(iidx) < val) maxVectorAll.at(iidx) = val;
273 std::vector<TString>* strVec =
new std::vector<TString>(size);
277 min =
fMin.at(cls).at(iinp);
278 max =
fMax.at(cls).at(iinp);
281 UInt_t idx = (*itGet).second;
287 if (offset < 0) str =
Form(
"2*%g*([%s] + %g) - 1", scale, varInfo.
GetLabel().
Data(), -offset );
288 else str =
Form(
"2*%g*([%s] - %g) - 1", scale, varInfo.
GetLabel().
Data(), offset );
289 (*strVec)[iinp] = str;
302 o <<
"# min max for all variables for all classes one after the other and as a last entry for all classes together" << std::endl;
310 for (
Int_t icls = 0; icls < numC; icls++ ) {
311 o << icls << std::endl;
312 for (
UInt_t ivar=0; ivar<nvars; ivar++)
313 o << std::setprecision(12) << std::setw(20) <<
fMin.at(icls).at(ivar) <<
" " 314 << std::setprecision(12) << std::setw(20) <<
fMax.at(icls).at(ivar) << std::endl;
315 for (
UInt_t itgt=0; itgt<ntgts; itgt++)
316 o << std::setprecision(12) << std::setw(20) <<
fMin.at(icls).at(nvars+itgt) <<
" " 317 << std::setprecision(12) << std::setw(20) <<
fMax.at(icls).at(nvars+itgt) << std::endl;
319 o <<
"##" << std::endl;
333 for(
Int_t icls=0; icls<numC; icls++ ) {
355 void* inpnode =
NULL;
358 if( inpnode !=
NULL )
377 fMin.resize(classindex+1);
378 fMax.resize(classindex+1);
386 if(nodeName==
"Ranges") {
404 UInt_t classindex, varindex, tgtindex, nvars, ntgts;
411 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
412 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
414 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
415 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
421 fMin.resize(classindex+1);
422 fMax.resize(classindex+1);
429 if(nodeName==
"Variables") {
437 }
else if (nodeName==
"Targets") {
462 if(var.size() != nvars)
463 Log() <<
kFATAL <<
"<BuildTransformationFromVarInfo> can't build transformation," 464 <<
" since the number of variables disagree" <<
Endl;
471 for(
UInt_t cls=0; cls<numC; ++cls) {
475 for(std::vector<TMVA::VariableInfo>::const_iterator
v = var.begin();
v!=var.end(); ++
v, ++vidx) {
476 fMin[cls][vidx] =
v->GetMin();
477 fMax[cls][vidx] =
v->GetMax();
478 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',vidx));
491 for(
UInt_t ivar = 0; ivar < nvars; ++ivar ){
492 fGet.push_back(std::pair<Char_t,UInt_t>(
'v',ivar));
494 for(
UInt_t itgt = 0; itgt < ntgts; ++itgt ){
495 fGet.push_back(std::pair<Char_t,UInt_t>(
't',itgt));
499 istr.getline(buf,512);
503 while (!(buf[0]==
'#'&& buf[1]==
'#')) {
505 while (*p==
' ' || *p==
'\t') p++;
506 if (*p==
'#' || *p==
'\0') {
507 istr.getline(buf,512);
510 std::stringstream sstr(buf);
512 for (
UInt_t ivar=0;ivar<nvars;ivar++) {
513 istr.getline(buf2,512);
514 std::stringstream sstr2(buf2);
515 sstr2 >>
fMin[icls][ivar] >>
fMax[icls][ivar];
517 for (
UInt_t itgt=0;itgt<ntgts;itgt++) {
518 istr.getline(buf2,512);
519 std::stringstream sstr2(buf2);
520 sstr2 >>
fMin[icls][nvars+itgt] >>
fMax[icls][nvars+itgt];
522 istr.getline(buf,512);
534 if (nCls <= 1 ) numC = 1;
535 for (
Int_t icls = 0; icls < numC; icls++ ) {
537 Log() <<
kINFO <<
"Transformation for all classes based on these ranges:" <<
Endl;
539 Log() <<
kINFO <<
"Transformation for class " << icls <<
" based on these ranges:" <<
Endl;
543 UInt_t idx = (*itGet).second;
545 TString typeString = (type==
'v'?
"Variable: ": (type==
't'?
"Target : ":
"Spectator : ") );
546 Log() << typeString.
Data() << std::setw(20) <<
fMin[icls][idx] << std::setw(20) <<
fMax[icls][idx] <<
Endl;
564 fout <<
" double fMin_"<<trCounter<<
"["<<numC<<
"]["<<nVar<<
"];" << std::endl;
565 fout <<
" double fMax_"<<trCounter<<
"["<<numC<<
"]["<<nVar<<
"];" << std::endl;
570 fout <<
"//_______________________________________________________________________" << std::endl;
571 fout <<
"inline void " << fcncName <<
"::InitTransform_"<<trCounter<<
"()" << std::endl;
572 fout <<
"{" << std::endl;
573 fout <<
" // Normalization transformation, initialisation" << std::endl;
574 for (
UInt_t ivar=0; ivar<nVar; ivar++) {
575 for (
UInt_t icls = 0; icls < numC; icls++) {
578 fout <<
" fMin_"<<trCounter<<
"["<<icls<<
"]["<<ivar<<
"] = " << std::setprecision(12)
579 << min <<
";" << std::endl;
580 fout <<
" fMax_"<<trCounter<<
"["<<icls<<
"]["<<ivar<<
"] = " << std::setprecision(12)
581 << max <<
";" << std::endl;
584 fout <<
"}" << std::endl;
586 fout <<
"//_______________________________________________________________________" << std::endl;
587 fout <<
"inline void " << fcncName <<
"::Transform_"<<trCounter<<
"( std::vector<double>& iv, int cls) const" << std::endl;
588 fout <<
"{" << std::endl;
589 fout <<
" // Normalization transformation" << std::endl;
590 fout <<
" if (cls < 0 || cls > "<<
GetNClasses()<<
") {"<< std::endl;
592 fout <<
" else cls = "<<(
fMin.size()==1?0:2)<<
";"<< std::endl;
593 fout <<
" }"<< std::endl;
594 fout <<
" const int nVar = " << nVar <<
";" << std::endl << std::endl;
595 fout <<
" // get indices of used variables" << std::endl;
597 fout <<
" static std::vector<double> dv;" << std::endl;
598 fout <<
" dv.resize(nVar);" << std::endl;
599 fout <<
" for (int ivar=0; ivar<nVar; ivar++) dv[ivar] = iv[indicesGet.at(ivar)];" << std::endl;
601 fout <<
" for (int ivar=0;ivar<"<<nVar<<
";ivar++) {" << std::endl;
602 fout <<
" double offset = fMin_"<<trCounter<<
"[cls][ivar];" << std::endl;
603 fout <<
" double scale = 1.0/(fMax_"<<trCounter<<
"[cls][ivar]-fMin_"<<trCounter<<
"[cls][ivar]);" << std::endl;
604 fout <<
" iv[indicesPut.at(ivar)] = (dv[ivar]-offset)*scale * 2 - 1;" << std::endl;
605 fout <<
" }" << std::endl;
606 fout <<
"}" << std::endl;
MsgLogger & Endl(MsgLogger &ml)
Short_t Min(Short_t a, Short_t b)
const TString & GetLabel() const
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)
const char * Data() const