ROOT  6.06/09
Reference Guide
MethodLD.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Krzysztof Danielowski, Kamil Kraszewski, Maciej Kruk, Jan Therhaag
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : MethodLD *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Linear Discriminant - Simple Linear Regression and Classification *
12  * *
13  * Authors (alphabetical): *
14  * Krzysztof Danielowski <danielow@cern.ch> - IFJ PAN & AGH, Poland *
15  * Kamil Kraszewski <kalq@cern.ch> - IFJ PAN & UJ, Poland *
16  * Maciej Kruk <mkruk@cern.ch> - IFJ PAN & AGH, Poland *
17  * Jan Therhaag <therhaag@physik.uni-bonn.de> - Uni Bonn, Germany *
18  * *
19  * Copyright (c) 2005-2011: *
20  * CERN, Switzerland *
21  * PAN, Poland *
22  * U. of Bonn, Germany *
23  * *
24  * Redistribution and use in source and binary forms, with or without *
25  * modification, are permitted according to the terms listed in LICENSE *
26  * (http://tmva.sourceforge.net/LICENSE) *
27  * *
28  **********************************************************************************/
29 
30 #include <iomanip>
31 
32 #include "TMath.h"
33 #include "Riostream.h"
34 #include "TMatrix.h"
35 #include "TMatrixD.h"
36 
38 #include "TMVA/MethodLD.h"
39 #include "TMVA/Tools.h"
40 #include "TMVA/Ranking.h"
41 #include "TMVA/Types.h"
42 #include "TMVA/PDF.h"
43 #include "TMVA/ClassifierFactory.h"
44 
45 using std::vector;
46 
48 
49 ClassImp(TMVA::MethodLD)
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// standard constructor for the LD
53 
54 TMVA::MethodLD::MethodLD( const TString& jobName,
55  const TString& methodTitle,
56  DataSetInfo& dsi,
57  const TString& theOption,
58  TDirectory* theTargetDir ) :
59  MethodBase( jobName, Types::kLD, methodTitle, dsi, theOption, theTargetDir ),
60  fNRegOut ( 0 ),
61  fSumMatx ( 0 ),
62  fSumValMatx( 0 ),
63  fCoeffMatx ( 0 ),
64  fLDCoeff ( 0 )
65 {
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// constructor from weight file
70 
71 TMVA::MethodLD::MethodLD( DataSetInfo& theData, const TString& theWeightFile, TDirectory* theTargetDir )
72  : MethodBase( Types::kLD, theData, theWeightFile, theTargetDir ),
73  fNRegOut ( 0 ),
74  fSumMatx ( 0 ),
75  fSumValMatx( 0 ),
76  fCoeffMatx ( 0 ),
77  fLDCoeff ( 0 )
78 {
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// default initialization called by all constructors
83 
85 {
86  if(DataInfo().GetNTargets()!=0) fNRegOut = DataInfo().GetNTargets();
87  else fNRegOut = 1;
88 
89  fLDCoeff = new vector< vector< Double_t >* >(fNRegOut);
90  for (Int_t iout = 0; iout<fNRegOut; iout++){
91  (*fLDCoeff)[iout] = new std::vector<Double_t>( GetNvar()+1 );
92  }
93 
94  // the minimum requirement to declare an event signal-like
95  SetSignalReferenceCut( 0.0 );
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// destructor
100 
102 {
103  if (fSumMatx) { delete fSumMatx; fSumMatx = 0; }
104  if (fSumValMatx) { delete fSumValMatx; fSumValMatx = 0; }
105  if (fCoeffMatx) { delete fCoeffMatx; fCoeffMatx = 0; }
106  if (fLDCoeff) {
107  for (vector< vector< Double_t >* >::iterator vi=fLDCoeff->begin(); vi!=fLDCoeff->end(); vi++){
108  if (*vi) { delete *vi; *vi = 0; }
109  }
110  delete fLDCoeff; fLDCoeff = 0;
111  }
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// LD can handle classification with 2 classes and regression with one regression-target
116 
118 {
119  if (type == Types::kClassification && numberClasses == 2) return kTRUE;
120  else if (type == Types::kRegression && numberTargets == 1) {
121  Log() << "regression with " << numberTargets << " targets.";
122  return kTRUE;
123  }
124  else return kFALSE;
125 }
126 
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// compute fSumMatx
130 
132 {
133  GetSum();
134 
135  // compute fSumValMatx
136  GetSumVal();
137 
138  // compute fCoeffMatx and fLDCoeff
139  GetLDCoeff();
140 
141  // nice output
142  PrintCoefficients();
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 ///Returns the MVA classification output
147 
149 {
150  const Event* ev = GetEvent();
151 
152  if (fRegressionReturnVal == NULL) fRegressionReturnVal = new vector< Float_t >();
153  fRegressionReturnVal->resize( fNRegOut );
154 
155  for (Int_t iout = 0; iout<fNRegOut; iout++) {
156  (*fRegressionReturnVal)[iout] = (*(*fLDCoeff)[iout])[0] ;
157 
158  int icoeff=0;
159  for (std::vector<Float_t>::const_iterator it = ev->GetValues().begin();it!=ev->GetValues().end();++it){
160  (*fRegressionReturnVal)[iout] += (*(*fLDCoeff)[iout])[++icoeff] * (*it);
161  }
162  }
163 
164  // cannot determine error
165  NoErrorCalc(err, errUpper);
166 
167  return (*fRegressionReturnVal)[0];
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 ///Calculates the regression output
172 
173 const std::vector< Float_t >& TMVA::MethodLD::GetRegressionValues()
174 {
175  const Event* ev = GetEvent();
176 
177  if (fRegressionReturnVal == NULL) fRegressionReturnVal = new vector< Float_t >();
178  fRegressionReturnVal->resize( fNRegOut );
179 
180  for (Int_t iout = 0; iout<fNRegOut; iout++) {
181  (*fRegressionReturnVal)[iout] = (*(*fLDCoeff)[iout])[0] ;
182 
183  int icoeff = 0;
184  for (std::vector<Float_t>::const_iterator it = ev->GetValues().begin();it!=ev->GetValues().end();++it){
185  (*fRegressionReturnVal)[iout] += (*(*fLDCoeff)[iout])[++icoeff] * (*it);
186  }
187  }
188 
189  // perform inverse transformation
190  Event* evT = new Event(*ev);
191  for (Int_t iout = 0; iout<fNRegOut; iout++) evT->SetTarget(iout,(*fRegressionReturnVal)[iout]);
192 
193  const Event* evT2 = GetTransformationHandler().InverseTransform( evT );
194  fRegressionReturnVal->clear();
195  for (Int_t iout = 0; iout<fNRegOut; iout++) fRegressionReturnVal->push_back(evT2->GetTarget(iout));
196 
197  delete evT;
198  return (*fRegressionReturnVal);
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// Initializaton method; creates global matrices and vectors
203 
205 {
206  fSumMatx = new TMatrixD( GetNvar()+1, GetNvar()+1 );
207  fSumValMatx = new TMatrixD( GetNvar()+1, fNRegOut );
208  fCoeffMatx = new TMatrixD( GetNvar()+1, fNRegOut );
209 
210 }
211 
212 ////////////////////////////////////////////////////////////////////////////////
213 /// Calculates the matrix transposed(X)*W*X with W being the diagonal weight matrix
214 /// and X the coordinates values
215 
217 {
218  const UInt_t nvar = DataInfo().GetNVariables();
219 
220  for (UInt_t ivar = 0; ivar<=nvar; ivar++){
221  for (UInt_t jvar = 0; jvar<=nvar; jvar++) (*fSumMatx)( ivar, jvar ) = 0;
222  }
223 
224  // compute sample means
225  Long64_t nevts = Data()->GetNEvents();
226  for (Int_t ievt=0; ievt<nevts; ievt++) {
227  const Event * ev = GetEvent(ievt);
228  Double_t weight = ev->GetWeight();
229 
230  if (IgnoreEventsWithNegWeightsInTraining() && weight <= 0) continue;
231 
232  // Sum of weights
233  (*fSumMatx)( 0, 0 ) += weight;
234 
235  // Sum of coordinates
236  for (UInt_t ivar=0; ivar<nvar; ivar++) {
237  (*fSumMatx)( ivar+1, 0 ) += ev->GetValue( ivar ) * weight;
238  (*fSumMatx)( 0, ivar+1 ) += ev->GetValue( ivar ) * weight;
239  }
240 
241  // Sum of products of coordinates
242  for (UInt_t ivar=0; ivar<nvar; ivar++){
243  for (UInt_t jvar=0; jvar<nvar; jvar++){
244  (*fSumMatx)( ivar+1, jvar+1 ) += ev->GetValue( ivar ) * ev->GetValue( jvar ) * weight;
245  }
246  }
247  }
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 ///Calculates the vector transposed(X)*W*Y with Y being the target vector
252 
254 {
255  const UInt_t nvar = DataInfo().GetNVariables();
256 
257  for (Int_t ivar = 0; ivar<fNRegOut; ivar++){
258  for (UInt_t jvar = 0; jvar<=nvar; jvar++){
259  (*fSumValMatx)(jvar,ivar) = 0;
260  }
261  }
262 
263  // Sum of coordinates multiplied by values
264  for (Int_t ievt=0; ievt<Data()->GetNEvents(); ievt++) {
265 
266  // retrieve the event
267  const Event* ev = GetEvent(ievt);
268  Double_t weight = ev->GetWeight();
269 
270  // in case event with neg weights are to be ignored
271  if (IgnoreEventsWithNegWeightsInTraining() && weight <= 0) continue;
272 
273  for (Int_t ivar=0; ivar<fNRegOut; ivar++) {
274 
275  Double_t val = weight;
276 
277  if (!DoRegression()){
278  val *= DataInfo().IsSignal(ev); // yes it works.. but I'm still surprised (Helge).. would have not set y_B to zero though..
279  }else {//for regression
280  val *= ev->GetTarget( ivar );
281  }
282  (*fSumValMatx)( 0,ivar ) += val;
283  for (UInt_t jvar=0; jvar<nvar; jvar++) {
284  (*fSumValMatx)(jvar+1,ivar ) += ev->GetValue(jvar) * val;
285  }
286  }
287  }
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 ///Calculates the coeffiecients used for classification/regression
292 
294 {
295  const UInt_t nvar = DataInfo().GetNVariables();
296 
297  for (Int_t ivar = 0; ivar<fNRegOut; ivar++){
298  TMatrixD invSum( *fSumMatx );
299  if ( TMath::Abs(invSum.Determinant()) < 10E-24 ) {
300  Log() << kWARNING << "<GetCoeff> matrix is almost singular with determinant="
301  << TMath::Abs(invSum.Determinant())
302  << " did you use the variables that are linear combinations or highly correlated?"
303  << Endl;
304  }
305  if ( TMath::Abs(invSum.Determinant()) < 10E-120 ) {
306  Log() << kFATAL << "<GetCoeff> matrix is singular with determinant="
307  << TMath::Abs(invSum.Determinant())
308  << " did you use the variables that are linear combinations?"
309  << Endl;
310  }
311  invSum.Invert();
312 
313  fCoeffMatx = new TMatrixD( invSum * (*fSumValMatx));
314  for (UInt_t jvar = 0; jvar<nvar+1; jvar++) {
315  (*(*fLDCoeff)[ivar])[jvar] = (*fCoeffMatx)(jvar, ivar );
316  }
317  if (!DoRegression()) {
318  (*(*fLDCoeff)[ivar])[0]=0.0;
319  for (UInt_t jvar = 1; jvar<nvar+1; jvar++){
320  (*(*fLDCoeff)[ivar])[0]+=(*fCoeffMatx)(jvar,ivar)*(*fSumMatx)(0,jvar)/(*fSumMatx)( 0, 0 );
321  }
322  (*(*fLDCoeff)[ivar])[0]/=-2.0;
323  }
324 
325  }
326 }
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 /// read LD coefficients from weight file
330 
331 void TMVA::MethodLD::ReadWeightsFromStream( std::istream& istr )
332 {
333  for (Int_t iout=0; iout<fNRegOut; iout++){
334  for (UInt_t icoeff=0; icoeff<GetNvar()+1; icoeff++){
335  istr >> (*(*fLDCoeff)[iout])[icoeff];
336  }
337  }
338 }
339 
340 ////////////////////////////////////////////////////////////////////////////////
341 /// create XML description for LD classification and regression
342 /// (for arbitrary number of output classes/targets)
343 
344 void TMVA::MethodLD::AddWeightsXMLTo( void* parent ) const
345 {
346  void* wght = gTools().AddChild(parent, "Weights");
347  gTools().AddAttr( wght, "NOut", fNRegOut );
348  gTools().AddAttr( wght, "NCoeff", GetNvar()+1 );
349  for (Int_t iout=0; iout<fNRegOut; iout++) {
350  for (UInt_t icoeff=0; icoeff<GetNvar()+1; icoeff++) {
351  void* coeffxml = gTools().AddChild( wght, "Coefficient" );
352  gTools().AddAttr( coeffxml, "IndexOut", iout );
353  gTools().AddAttr( coeffxml, "IndexCoeff", icoeff );
354  gTools().AddAttr( coeffxml, "Value", (*(*fLDCoeff)[iout])[icoeff] );
355  }
356  }
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 /// read coefficients from xml weight file
361 
362 void TMVA::MethodLD::ReadWeightsFromXML( void* wghtnode )
363 {
364  UInt_t ncoeff;
365  gTools().ReadAttr( wghtnode, "NOut", fNRegOut );
366  gTools().ReadAttr( wghtnode, "NCoeff", ncoeff );
367 
368  // sanity checks
369  if (ncoeff != GetNvar()+1) Log() << kFATAL << "Mismatch in number of output variables/coefficients: "
370  << ncoeff << " != " << GetNvar()+1 << Endl;
371 
372  // create vector with coefficients (double vector due to arbitrary output dimension)
373  if (fLDCoeff) {
374  for (vector< vector< Double_t >* >::iterator vi=fLDCoeff->begin(); vi!=fLDCoeff->end(); vi++){
375  if (*vi) { delete *vi; *vi = 0; }
376  }
377  delete fLDCoeff; fLDCoeff = 0;
378  }
379  fLDCoeff = new vector< vector< Double_t >* >(fNRegOut);
380  for (Int_t ivar = 0; ivar<fNRegOut; ivar++) (*fLDCoeff)[ivar] = new std::vector<Double_t>( ncoeff );
381 
382  void* ch = gTools().GetChild(wghtnode);
383  Double_t coeff;
384  Int_t iout, icoeff;
385  while (ch) {
386  gTools().ReadAttr( ch, "IndexOut", iout );
387  gTools().ReadAttr( ch, "IndexCoeff", icoeff );
388  gTools().ReadAttr( ch, "Value", coeff );
389 
390  (*(*fLDCoeff)[iout])[icoeff] = coeff;
391 
392  ch = gTools().GetNextChild(ch);
393  }
394 }
395 
396 ////////////////////////////////////////////////////////////////////////////////
397 /// write LD-specific classifier response
398 
399 void TMVA::MethodLD::MakeClassSpecific( std::ostream& fout, const TString& className ) const
400 {
401  fout << " std::vector<double> fLDCoefficients;" << std::endl;
402  fout << "};" << std::endl;
403  fout << "" << std::endl;
404  fout << "inline void " << className << "::Initialize() " << std::endl;
405  fout << "{" << std::endl;
406  for (UInt_t ivar=0; ivar<GetNvar()+1; ivar++) {
407  Int_t dp = fout.precision();
408  fout << " fLDCoefficients.push_back( "
409  << std::setprecision(12) << (*(*fLDCoeff)[0])[ivar]
410  << std::setprecision(dp) << " );" << std::endl;
411  }
412  fout << std::endl;
413  fout << " // sanity check" << std::endl;
414  fout << " if (fLDCoefficients.size() != fNvars+1) {" << std::endl;
415  fout << " std::cout << \"Problem in class \\\"\" << fClassName << \"\\\"::Initialize: mismatch in number of input values\"" << std::endl;
416  fout << " << fLDCoefficients.size() << \" != \" << fNvars+1 << std::endl;" << std::endl;
417  fout << " fStatusIsClean = false;" << std::endl;
418  fout << " } " << std::endl;
419  fout << "}" << std::endl;
420  fout << std::endl;
421  fout << "inline double " << className << "::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
422  fout << "{" << std::endl;
423  fout << " double retval = fLDCoefficients[0];" << std::endl;
424  fout << " for (size_t ivar = 1; ivar < fNvars+1; ivar++) {" << std::endl;
425  fout << " retval += fLDCoefficients[ivar]*inputValues[ivar-1];" << std::endl;
426  fout << " }" << std::endl;
427  fout << std::endl;
428  fout << " return retval;" << std::endl;
429  fout << "}" << std::endl;
430  fout << std::endl;
431  fout << "// Clean up" << std::endl;
432  fout << "inline void " << className << "::Clear() " << std::endl;
433  fout << "{" << std::endl;
434  fout << " // clear coefficients" << std::endl;
435  fout << " fLDCoefficients.clear(); " << std::endl;
436  fout << "}" << std::endl;
437 }
438 ////////////////////////////////////////////////////////////////////////////////
439 /// computes ranking of input variables
440 
442 {
443  // create the ranking object
444  fRanking = new Ranking( GetName(), "Discr. power" );
445 
446  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) {
447  fRanking->AddRank( Rank( GetInputLabel(ivar), TMath::Abs((* (*fLDCoeff)[0])[ivar+1] )) );
448  }
449 
450  return fRanking;
451 }
452 
453 ////////////////////////////////////////////////////////////////////////////////
454 ///MethodLD options
455 
457 {
458  AddPreDefVal(TString("LD"));
459 }
460 
461 ////////////////////////////////////////////////////////////////////////////////
462 /// this is the preparation for training
463 
465 {
466  if (HasTrainingTree()) InitMatrices();
467 }
468 
469 ////////////////////////////////////////////////////////////////////////////////
470 ///Display the classification/regression coefficients for each variable
471 
473 {
474  Log() << kINFO << "Results for LD coefficients:" << Endl;
475 
476  if (GetTransformationHandler().GetTransformationList().GetSize() != 0) {
477  Log() << kINFO << "NOTE: The coefficients must be applied to TRANFORMED variables" << Endl;
478  Log() << kINFO << " List of the transformation: " << Endl;
479  TListIter trIt(&GetTransformationHandler().GetTransformationList());
480  while (VariableTransformBase *trf = (VariableTransformBase*) trIt() ) {
481  Log() << kINFO << " -- " << trf->GetName() << Endl;
482  }
483  }
484  std::vector<TString> vars;
485  std::vector<Double_t> coeffs;
486  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) {
487  vars .push_back( GetInputLabel(ivar) );
488  coeffs.push_back( (* (*fLDCoeff)[0])[ivar+1] );
489  }
490  vars .push_back( "(offset)" );
491  coeffs.push_back((* (*fLDCoeff)[0])[0] );
492  TMVA::gTools().FormattedOutput( coeffs, vars, "Variable" , "Coefficient", Log() );
493  if (IsNormalised()) {
494  Log() << kINFO << "NOTE: You have chosen to use the \"Normalise\" booking option. Hence, the" << Endl;
495  Log() << kINFO << " coefficients must be applied to NORMALISED (') variables as follows:" << Endl;
496  Int_t maxL = 0;
497  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) if (GetInputLabel(ivar).Length() > maxL) maxL = GetInputLabel(ivar).Length();
498 
499  // Print normalisation expression (see Tools.cxx): "2*(x - xmin)/(xmax - xmin) - 1.0"
500  for (UInt_t ivar=0; ivar<GetNvar(); ivar++) {
501  Log() << kINFO
502  << std::setw(maxL+9) << TString("[") + GetInputLabel(ivar) + "]' = 2*("
503  << std::setw(maxL+2) << TString("[") + GetInputLabel(ivar) + "]"
504  << std::setw(3) << (GetXmin(ivar) > 0 ? " - " : " + ")
505  << std::setw(6) << TMath::Abs(GetXmin(ivar)) << std::setw(3) << ")/"
506  << std::setw(6) << (GetXmax(ivar) - GetXmin(ivar) )
507  << std::setw(3) << " - 1"
508  << Endl;
509  }
510  Log() << kINFO << "The TMVA Reader will properly account for this normalisation, but if the" << Endl;
511  Log() << kINFO << "LD classifier is applied outside the Reader, the transformation must be" << Endl;
512  Log() << kINFO << "implemented -- or the \"Normalise\" option is removed and LD retrained." << Endl;
513  Log() << kINFO << Endl;
514  }
515 }
516 
517 ////////////////////////////////////////////////////////////////////////////////
518 /// get help message text
519 ///
520 /// typical length of text line:
521 /// "|--------------------------------------------------------------|"
522 
524 {
525  Log() << Endl;
526  Log() << gTools().Color("bold") << "--- Short description:" << gTools().Color("reset") << Endl;
527  Log() << Endl;
528  Log() << "Linear discriminants select events by distinguishing the mean " << Endl;
529  Log() << "values of the signal and background distributions in a trans- " << Endl;
530  Log() << "formed variable space where linear correlations are removed." << Endl;
531  Log() << "The LD implementation here is equivalent to the \"Fisher\" discriminant" << Endl;
532  Log() << "for classification, but also provides linear regression." << Endl;
533  Log() << Endl;
534  Log() << " (More precisely: the \"linear discriminator\" determines" << Endl;
535  Log() << " an axis in the (correlated) hyperspace of the input " << Endl;
536  Log() << " variables such that, when projecting the output classes " << Endl;
537  Log() << " (signal and background) upon this axis, they are pushed " << Endl;
538  Log() << " as far as possible away from each other, while events" << Endl;
539  Log() << " of a same class are confined in a close vicinity. The " << Endl;
540  Log() << " linearity property of this classifier is reflected in the " << Endl;
541  Log() << " metric with which \"far apart\" and \"close vicinity\" are " << Endl;
542  Log() << " determined: the covariance matrix of the discriminating" << Endl;
543  Log() << " variable space.)" << Endl;
544  Log() << Endl;
545  Log() << gTools().Color("bold") << "--- Performance optimisation:" << gTools().Color("reset") << Endl;
546  Log() << Endl;
547  Log() << "Optimal performance for the linear discriminant is obtained for " << Endl;
548  Log() << "linearly correlated Gaussian-distributed variables. Any deviation" << Endl;
549  Log() << "from this ideal reduces the achievable separation power. In " << Endl;
550  Log() << "particular, no discrimination at all is achieved for a variable" << Endl;
551  Log() << "that has the same sample mean for signal and background, even if " << Endl;
552  Log() << "the shapes of the distributions are very different. Thus, the linear " << Endl;
553  Log() << "discriminant often benefits from a suitable transformation of the " << Endl;
554  Log() << "input variables. For example, if a variable x in [-1,1] has a " << Endl;
555  Log() << "a parabolic signal distributions, and a uniform background" << Endl;
556  Log() << "distributions, their mean value is zero in both cases, leading " << Endl;
557  Log() << "to no separation. The simple transformation x -> |x| renders this " << Endl;
558  Log() << "variable powerful for the use in a linear discriminant." << Endl;
559  Log() << Endl;
560  Log() << gTools().Color("bold") << "--- Performance tuning via configuration options:" << gTools().Color("reset") << Endl;
561  Log() << Endl;
562  Log() << "<None>" << Endl;
563 }
virtual const std::vector< Float_t > & GetRegressionValues()
Calculates the regression output.
Definition: MethodLD.cxx:173
const Ranking * CreateRanking()
computes ranking of input variables
Definition: MethodLD.cxx:441
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
long long Long64_t
Definition: RtypesCore.h:69
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
LD can handle classification with 2 classes and regression with one regression-target.
Definition: MethodLD.cxx:117
void GetSumVal(void)
Calculates the vector transposed(X)*W*Y with Y being the target vector.
Definition: MethodLD.cxx:253
EAnalysisType
Definition: Types.h:124
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual ~MethodLD(void)
destructor
Definition: MethodLD.cxx:101
void PrintCoefficients(void)
Display the classification/regression coefficients for each variable.
Definition: MethodLD.cxx:472
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
Definition: Event.cxx:376
void AddAttr(void *node, const char *, const T &value, Int_t precision=16)
Definition: Tools.h:308
void * AddChild(void *parent, const char *childname, const char *content=0, bool isRootNode=false)
add child node
Definition: Tools.cxx:1134
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Iterator of linked list.
Definition: TList.h:187
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Definition: Event.cxx:231
void ReadWeightsFromXML(void *wghtnode)
read coefficients from xml weight file
Definition: MethodLD.cxx:362
Tools & gTools()
Definition: Tools.cxx:79
ClassImp(TMVA::MethodLD) TMVA
standard constructor for the LD
Definition: MethodLD.cxx:49
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
Returns the MVA classification output.
Definition: MethodLD.cxx:148
void * GetChild(void *parent, const char *childname=0)
get child node
Definition: Tools.cxx:1158
std::vector< std::vector< double > > Data
MethodLD(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="LD", TDirectory *theTargetDir=0)
void MakeClassSpecific(std::ostream &, const TString &) const
write LD-specific classifier response
Definition: MethodLD.cxx:399
TMatrixT< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant.
Definition: TMatrixT.cxx:1387
TMatrixT< Double_t > TMatrixD
Definition: TMatrixDfwd.h:24
void ReadWeightsFromStream(std::istream &i)
read LD coefficients from weight file
Definition: MethodLD.cxx:331
void AddWeightsXMLTo(void *parent) const
create XML description for LD classification and regression (for arbitrary number of output classes/t...
Definition: MethodLD.cxx:344
unsigned int UInt_t
Definition: RtypesCore.h:42
Double_t E()
Definition: TMath.h:54
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
Definition: Event.cxx:354
void ReadAttr(void *node, const char *, T &value)
Definition: Tools.h:295
void DeclareOptions()
MethodLD options.
Definition: MethodLD.cxx:456
double Double_t
Definition: RtypesCore.h:55
Describe directory structure in memory.
Definition: TDirectory.h:41
int type
Definition: TGX11.cxx:120
void * GetNextChild(void *prevchild, const char *childname=0)
XML helpers.
Definition: Tools.cxx:1170
void FormattedOutput(const std::vector< Double_t > &, const std::vector< TString > &, const TString titleVars, const TString titleValues, MsgLogger &logger, TString format="%+1.3f")
formatted output of simple table
Definition: Tools.cxx:896
const TString & Color(const TString &)
human readable color strings
Definition: Tools.cxx:837
void GetSum(void)
Calculates the matrix transposed(X)*W*X with W being the diagonal weight matrix and X the coordinates...
Definition: MethodLD.cxx:216
Float_t GetTarget(UInt_t itgt) const
Definition: Event.h:101
#define REGISTER_METHOD(CLASS)
for example
Abstract ClassifierFactory template that handles arbitrary types.
std::vector< Float_t > & GetValues()
Definition: Event.h:93
void GetLDCoeff(void)
Calculates the coeffiecients used for classification/regression.
Definition: MethodLD.cxx:293
#define NULL
Definition: Rtypes.h:82
virtual Double_t Determinant() const
Return the matrix determinant.
Definition: TMatrixT.cxx:1352
void Train(void)
compute fSumMatx
Definition: MethodLD.cxx:131
void InitMatrices(void)
Initializaton method; creates global matrices and vectors.
Definition: MethodLD.cxx:204
void Init(void)
default initialization called by all constructors
Definition: MethodLD.cxx:84
const Bool_t kTRUE
Definition: Rtypes.h:91
void GetHelpMessage() const
get help message text
Definition: MethodLD.cxx:523
Definition: math.cpp:60
void ProcessOptions()
this is the preparation for training
Definition: MethodLD.cxx:464