66 for (std::vector<TMatrixD*>::iterator it = fDecorrMatrices.begin(); it != fDecorrMatrices.end(); ++it) {
67 if ((*it) != 0)
delete (*it);
85 if (!IsEnabled() || IsCreated())
return kTRUE;
87 Log() << kINFO <<
"Preparing the Decorrelation transformation..." <<
Endl;
89 Int_t inputSize = fGet.size();
90 SetNVariables(inputSize);
92 if (inputSize > 200) {
93 Log() << kINFO <<
"----------------------------------------------------------------------------"
96 <<
": More than 200 variables, will not calculate decorrelation matrix "
98 Log() << kINFO <<
"----------------------------------------------------------------------------"
103 CalcSQRMats( events, GetNClasses() );
115 Int_t whichMatrix = cls;
119 if (cls < 0 || cls > GetNClasses()) whichMatrix = GetNClasses();
121 TMatrixD*
m = fDecorrMatrices.at(whichMatrix);
123 if (whichMatrix == GetNClasses() )
124 Log() << kFATAL <<
"Transformation matrix all classes is not defined"
127 Log() << kFATAL <<
"Transformation matrix for class " << whichMatrix <<
" is not defined"
131 const Int_t nvar = fGet.size();
132 std::vector<TString>* strVec =
new std::vector<TString>;
135 for (
Int_t ivar=0; ivar<nvar; ivar++) {
137 for (
Int_t jvar=0; jvar<nvar; jvar++) {
138 str += ((*m)(ivar,jvar) > 0) ?
" + " :
" - ";
141 Int_t idx = fGet.at(jvar).second;
154 Log() << kFATAL <<
"VariableDecorrTransform::GetTransformationStrings : unknown type '" <<
type <<
"'." <<
Endl;
157 strVec->push_back( str );
169 Log() << kFATAL <<
"Transformation matrix not yet created"
172 Int_t whichMatrix = cls;
175 if (cls < 0 || cls >= (
int) fDecorrMatrices.size()) whichMatrix = fDecorrMatrices.size()-1;
182 TMatrixD*
m = fDecorrMatrices.at(whichMatrix);
184 if (whichMatrix == GetNClasses() )
185 Log() << kFATAL <<
"Transformation matrix all classes is not defined"
188 Log() << kFATAL <<
"Transformation matrix for class " << whichMatrix <<
" is not defined"
192 if (fTransformedEvent==0 || fTransformedEvent->GetNVariables()!=ev->
GetNVariables()) {
193 if (fTransformedEvent!=0) {
delete fTransformedEvent; fTransformedEvent = 0; }
194 fTransformedEvent =
new Event();
198 const Int_t nvar = fGet.size();
200 std::vector<Float_t>
input;
201 std::vector<Char_t>
mask;
204 if( hasMaskedEntries ){
207 if( numMasked>0 && numOK>0 ){
208 Log() << kFATAL <<
"You mixed variables and targets in the decorrelation transformation. This is not possible." <<
Endl;
210 SetOutput( fTransformedEvent,
input,
mask, ev );
211 return fTransformedEvent;
215 for (
Int_t ivar=0; ivar<nvar; ivar++) vec(ivar) =
input.at(ivar);
221 for (
Int_t ivar=0; ivar<nvar; ivar++)
input.push_back( vec(ivar) );
223 SetOutput( fTransformedEvent,
input,
mask, ev );
225 return fTransformedEvent;
234 Log() << kFATAL <<
"Inverse transformation for decorrelation transformation not yet implemented. Hence, this transformation cannot be applied together with regression if targets should be transformed. Please contact the authors if necessary." <<
Endl;
237 return fBackTransformedEvent;
246 for (std::vector<TMatrixD*>::iterator it = fDecorrMatrices.begin();
247 it != fDecorrMatrices.end(); ++it)
248 if (0 != (*it) ) {
delete (*it); *it=0; }
252 const UInt_t matNum = (maxCls<=1)?maxCls:maxCls+1;
253 fDecorrMatrices.resize( matNum, (
TMatrixD*) 0 );
258 for (
UInt_t cls=0; cls<matNum; cls++) {
261 Log() << kFATAL <<
"<GetSQRMats> Zero pointer returned for SQR matrix" <<
Endl;
262 fDecorrMatrices[cls] = sqrMat;
263 delete (*covMat)[cls];
274 Int_t dp = o.precision();
275 for (std::vector<TMatrixD*>::const_iterator itm = fDecorrMatrices.begin(); itm != fDecorrMatrices.end(); ++itm) {
276 o <<
"# correlation matrix " << std::endl;
278 o << cls <<
" " << mat->
GetNrows() <<
" x " << mat->
GetNcols() << std::endl;
281 o << std::setprecision(12) << std::setw(20) << (*mat)[row][col] <<
" ";
287 o <<
"##" << std::endl;
288 o << std::setprecision(dp);
301 for (std::vector<TMatrixD*>::const_iterator itm = fDecorrMatrices.begin(); itm != fDecorrMatrices.end(); ++itm) {
324 for( std::vector<TMatrixD*>::iterator it = fDecorrMatrices.begin(); it != fDecorrMatrices.end(); ++it )
325 if( (*it) != 0 )
delete (*it);
326 fDecorrMatrices.clear();
330 void* inpnode = NULL;
353 std::stringstream s(content);
354 for (
Int_t row = 0; row<nrows; row++) {
355 for (
Int_t col = 0; col<ncols; col++) {
356 s >> (*mat)[row][col];
359 fDecorrMatrices.push_back(mat);
371 istr.getline(buf,512);
373 Int_t nrows(0), ncols(0);
375 while (!(buf[0]==
'#'&& buf[1]==
'#')) {
377 while (*
p==
' ' || *
p==
'\t')
p++;
378 if (*
p==
'#' || *
p==
'\0') {
379 istr.getline(buf,512);
382 std::stringstream sstr(buf);
385 if (strvar==
"signal" || strvar==
"background") {
387 if(strvar==
"background") cls=1;
388 if(strvar==classname) classIdx = cls;
390 sstr >> nrows >> dummy >> ncols;
391 if (fDecorrMatrices.size() <= cls ) fDecorrMatrices.resize(cls+1);
392 if (fDecorrMatrices.at(cls) != 0)
delete fDecorrMatrices.at(cls);
397 istr >> (*mat)[row][col];
401 istr.getline(buf,512);
404 fDecorrMatrices.push_back(
new TMatrixD(*fDecorrMatrices[classIdx]) );
415 for (std::vector<TMatrixD*>::iterator itm = fDecorrMatrices.begin(); itm != fDecorrMatrices.end(); ++itm) {
416 Log() << kINFO <<
"Transformation matrix "<< cls <<
":" <<
Endl;
426 Int_t dp = fout.precision();
428 UInt_t numC = fDecorrMatrices.size();
431 TMatrixD* mat = fDecorrMatrices.at(0);
433 fout <<
" double fDecTF_"<<trCounter<<
"["<<numC<<
"]["<<mat->
GetNrows()<<
"]["<<mat->
GetNcols()<<
"];" << std::endl;
438 fout <<
"//_______________________________________________________________________" << std::endl;
439 fout <<
"inline void " << fcncName <<
"::InitTransform_"<<trCounter<<
"()" << std::endl;
440 fout <<
"{" << std::endl;
441 fout <<
" // Decorrelation transformation, initialisation" << std::endl;
442 for (
UInt_t icls = 0; icls < numC; icls++){
443 TMatrixD* matx = fDecorrMatrices.at(icls);
444 for (
int i=0; i<matx->
GetNrows(); i++) {
445 for (
int j=0; j<matx->
GetNcols(); j++) {
446 fout <<
" fDecTF_"<<trCounter<<
"["<<icls<<
"]["<<i<<
"]["<<j<<
"] = " << std::setprecision(12) << (*matx)[i][j] <<
";" << std::endl;
450 fout <<
"}" << std::endl;
452 TMatrixD* matx = fDecorrMatrices.at(0);
453 fout <<
"//_______________________________________________________________________" << std::endl;
454 fout <<
"inline void " << fcncName <<
"::Transform_"<<trCounter<<
"( std::vector<double>& iv, int cls) const" << std::endl;
455 fout <<
"{" << std::endl;
456 fout <<
" // Decorrelation transformation" << std::endl;
457 fout <<
" if (cls < 0 || cls > "<<GetNClasses()<<
") {"<< std::endl;
458 fout <<
" if ("<<GetNClasses()<<
" > 1 ) cls = "<<GetNClasses()<<
";"<< std::endl;
459 fout <<
" else cls = "<<(fDecorrMatrices.size()==1?0:2)<<
";"<< std::endl;
460 fout <<
" }"<< std::endl;
464 fout <<
" std::vector<double> tv;" << std::endl;
465 fout <<
" for (int i=0; i<"<<matx->
GetNrows()<<
";i++) {" << std::endl;
466 fout <<
" double v = 0;" << std::endl;
467 fout <<
" for (int j=0; j<"<<matx->
GetNcols()<<
"; j++)" << std::endl;
468 fout <<
" v += iv[indicesGet.at(j)] * fDecTF_"<<trCounter<<
"[cls][i][j];" << std::endl;
469 fout <<
" tv.push_back(v);" << std::endl;
470 fout <<
" }" << std::endl;
471 fout <<
" for (int i=0; i<"<<matx->
GetNrows()<<
";i++) iv[indicesPut.at(i)] = tv[i];" << std::endl;
472 fout <<
"}" << std::endl;
475 fout << std::setprecision(dp);
char Char_t
Character 1 byte (char)
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TMatrixT< Double_t > TMatrixD
Class that contains all the data information.
UInt_t GetNVariables() const
accessor to the number of variables
Singleton class for Global types used by TMVA.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
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 Abs(Short_t d)
Returns the absolute value of parameter Short_t d.