168 Log() <<
kWARNING <<
"<Train> H-matrix S is almost singular with deterinant= " 170 <<
" did you use the variables that are linear combinations or highly correlated ???" 174 Log() <<
kWARNING <<
"<Train> H-matrix B is almost singular with deterinant= " 176 <<
" did you use the variables that are linear combinations or highly correlated ???" 181 Log() <<
kFATAL <<
"<Train> H-matrix S is singular with deterinant= " 183 <<
" did you use the variables that are linear combinations ???" 187 Log() <<
kFATAL <<
"<Train> H-matrix B is singular with deterinant= " 189 <<
" did you use the variables that are linear combinations ???" 211 TMatrixD mat2(nvar, nvar); mat2 *= 0;
227 if (
DataInfo().IsSignal(origEvt) != isSignal)
continue;
234 sumOfWeights += weight;
237 for (ivar=0; ivar<nvar; ivar++) xval[ivar] = ev->
GetValue(ivar);
240 for (ivar=0; ivar<nvar; ivar++) {
242 vec(ivar) += xval[ivar]*weight;
243 mat2(ivar, ivar) += (xval[ivar]*xval[ivar])*weight;
245 for (jvar=ivar+1; jvar<nvar; jvar++) {
246 mat2(ivar, jvar) += (xval[ivar]*xval[jvar])*weight;
247 mat2(jvar, ivar) = mat2(ivar, jvar);
253 for (ivar=0; ivar<nvar; ivar++) {
255 if (isSignal) (*fVecMeanS)(ivar) = vec(ivar)/sumOfWeights;
256 else (*
fVecMeanB)(ivar) = vec(ivar)/sumOfWeights;
258 for (jvar=0; jvar<nvar; jvar++) {
259 (*mat)(ivar, jvar) = mat2(ivar, jvar)/sumOfWeights - vec(ivar)*vec(jvar)/(sumOfWeights*sumOfWeights);
274 if (s+b < 0)
Log() <<
kFATAL <<
"big trouble: s+b: " << s+b <<
Endl;
279 return (b - s)/(s +
b);
293 std::vector<Double_t> val( nvar );
303 for (ivar=0; ivar<nvar; ivar++) val[ivar] = ev->
GetValue( ivar );
306 for (ivar=0; ivar<nvar; ivar++) {
307 for (jvar=0; jvar<nvar; jvar++) {
309 chi2 += ( (val[ivar] - (*fVecMeanS)(ivar))*(val[jvar] - (*fVecMeanS)(jvar))
310 * (*fInvHMatrixS)(ivar,jvar) );
312 chi2 += ( (val[ivar] - (*fVecMeanB)(ivar))*(val[jvar] - (*fVecMeanB)(jvar))
313 * (*fInvHMatrixB)(ivar,jvar) );
318 if (chi2 < 0)
Log() <<
kFATAL <<
"<GetChi2> negative chi2: " << chi2 <<
Endl;
363 for (ivar=0; ivar<
GetNvar(); ivar++)
367 for (ivar=0; ivar<
GetNvar(); ivar++)
368 for (jvar=0; jvar<
GetNvar(); jvar++)
372 for (ivar=0; ivar<
GetNvar(); ivar++)
373 for (jvar=0; jvar<
GetNvar(); jvar++)
382 fout <<
" // arrays of input evt vs. variable " << std::endl;
383 fout <<
" double fInvHMatrixS[" <<
GetNvar() <<
"][" <<
GetNvar() <<
"]; // inverse H-matrix (signal)" << std::endl;
384 fout <<
" double fInvHMatrixB[" <<
GetNvar() <<
"][" <<
GetNvar() <<
"]; // inverse H-matrix (background)" << std::endl;
385 fout <<
" double fVecMeanS[" <<
GetNvar() <<
"]; // vector of mean values (signal)" << std::endl;
386 fout <<
" double fVecMeanB[" <<
GetNvar() <<
"]; // vector of mean values (background)" << std::endl;
387 fout <<
" " << std::endl;
388 fout <<
" double GetChi2( const std::vector<double>& inputValues, int type ) const;" << std::endl;
389 fout <<
"};" << std::endl;
390 fout <<
" " << std::endl;
391 fout <<
"void " << className <<
"::Initialize() " << std::endl;
392 fout <<
"{" << std::endl;
393 fout <<
" // init vectors with mean values" << std::endl;
395 fout <<
" fVecMeanS[" << ivar <<
"] = " << (*fVecMeanS)(ivar) <<
";" << std::endl;
396 fout <<
" fVecMeanB[" << ivar <<
"] = " << (*fVecMeanB)(ivar) <<
";" << std::endl;
398 fout <<
" " << std::endl;
399 fout <<
" // init H-matrices" << std::endl;
402 fout <<
" fInvHMatrixS[" << ivar <<
"][" << jvar <<
"] = " 403 << (*fInvHMatrixS)(ivar,jvar) <<
";" << std::endl;
404 fout <<
" fInvHMatrixB[" << ivar <<
"][" << jvar <<
"] = " 405 << (*fInvHMatrixB)(ivar,jvar) <<
";" << std::endl;
408 fout <<
"}" << std::endl;
409 fout <<
" " << std::endl;
410 fout <<
"inline double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
411 fout <<
"{" << std::endl;
412 fout <<
" // returns the H-matrix signal estimator" << std::endl;
413 fout <<
" std::vector<double> inputValuesSig = inputValues;" << std::endl;
414 fout <<
" std::vector<double> inputValuesBgd = inputValues;" << std::endl;
420 fout <<
" Transform(inputValuesSig," << signalClass <<
");" << std::endl;
421 fout <<
" Transform(inputValuesBgd," << backgroundClass <<
");" << std::endl;
426 fout <<
" double s = GetChi2( inputValuesSig, " <<
Types::kSignal <<
" );" << std::endl;
427 fout <<
" double b = GetChi2( inputValuesBgd, " <<
Types::kBackground <<
" );" << std::endl;
431 fout <<
" " << std::endl;
432 fout <<
" if (s+b <= 0) std::cout << \"Problem in class " << className <<
"::GetMvaValue__: s+b = \"" << std::endl;
433 fout <<
" << s+b << \" <= 0 \" << std::endl;" << std::endl;
434 fout <<
" " << std::endl;
435 fout <<
" return (b - s)/(s + b);" << std::endl;
436 fout <<
"}" << std::endl;
437 fout <<
" " << std::endl;
438 fout <<
"inline double " << className <<
"::GetChi2( const std::vector<double>& inputValues, int type ) const" << std::endl;
439 fout <<
"{" << std::endl;
440 fout <<
" // compute chi2-estimator for event according to type (signal/background)" << std::endl;
441 fout <<
" " << std::endl;
442 fout <<
" size_t ivar,jvar;" << std::endl;
443 fout <<
" double chi2 = 0;" << std::endl;
444 fout <<
" for (ivar=0; ivar<GetNvar(); ivar++) {" << std::endl;
445 fout <<
" for (jvar=0; jvar<GetNvar(); jvar++) {" << std::endl;
447 fout <<
" chi2 += ( (inputValues[ivar] - fVecMeanS[ivar])*(inputValues[jvar] - fVecMeanS[jvar])" << std::endl;
448 fout <<
" * fInvHMatrixS[ivar][jvar] );" << std::endl;
449 fout <<
" else" << std::endl;
450 fout <<
" chi2 += ( (inputValues[ivar] - fVecMeanB[ivar])*(inputValues[jvar] - fVecMeanB[jvar])" << std::endl;
451 fout <<
" * fInvHMatrixB[ivar][jvar] );" << std::endl;
452 fout <<
" }" << std::endl;
453 fout <<
" } // loop over variables " << std::endl;
454 fout <<
" " << std::endl;
455 fout <<
" // sanity check" << std::endl;
456 fout <<
" if (chi2 < 0) std::cout << \"Problem in class " << className <<
"::GetChi2: chi2 = \"" << std::endl;
457 fout <<
" << chi2 << \" < 0 \" << std::endl;" << std::endl;
458 fout <<
" " << std::endl;
459 fout <<
" return chi2;" << std::endl;
460 fout <<
"}" << std::endl;
461 fout <<
" " << std::endl;
462 fout <<
"// Clean up" << std::endl;
463 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
464 fout <<
"{" << std::endl;
465 fout <<
" // nothing to clear" << std::endl;
466 fout <<
"}" << std::endl;
480 Log() <<
"The H-Matrix classifier discriminates one class (signal) of a feature" <<
Endl;
481 Log() <<
"vector from another (background). The correlated elements of the" <<
Endl;
482 Log() <<
"vector are assumed to be Gaussian distributed, and the inverse of" <<
Endl;
483 Log() <<
"the covariance matrix is the H-Matrix. A multivariate chi-squared" <<
Endl;
484 Log() <<
"estimator is built that exploits differences in the mean values of" <<
Endl;
485 Log() <<
"the vector elements between the two classes for the purpose of" <<
Endl;
486 Log() <<
"discrimination." <<
Endl;
490 Log() <<
"The TMVA implementation of the H-Matrix classifier has been shown" <<
Endl;
491 Log() <<
"to underperform in comparison with the corresponding Fisher discriminant," <<
Endl;
492 Log() <<
"when using similar assumptions and complexity. Its use is therefore" <<
Endl;
493 Log() <<
"depreciated. Only in cases where the background model is strongly" <<
Endl;
494 Log() <<
"non-Gaussian, H-Matrix may perform better than Fisher. In such" <<
Endl;
495 Log() <<
"occurrences the user is advised to employ non-linear classifiers. " <<
Endl;
void ReadWeightsFromXML(void *wghtnode)
read weights from XML file
UInt_t GetNVariables() const
void Init()
default initialization called by all constructors
MsgLogger & Endl(MsgLogger &ml)
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns the H-matrix signal estimator
void ProcessOptions()
process user options
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
FDA can handle classification with 2 classes and regression with one regression-target.
void MakeClassSpecific(std::ostream &, const TString &) const
write Fisher-specific classifier response
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
virtual Double_t Determinant() const
Return the matrix determinant.
void ReadWeightsFromStream(std::istream &istr)
read variable names and min/max NOTE: the latter values are mandatory for the normalisation in the re...
virtual ~MethodHMatrix()
destructor
DataSetInfo & DataInfo() const
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
TVectorT< Double_t > TVectorD
TMatrixT< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant.
void AddWeightsXMLTo(void *parent) const
create XML description for HMatrix classification
UInt_t GetNEvents() const
temporary event when testing on a different DataSet than the own one
TMatrixT< Double_t > TMatrixD
ClassInfo * GetClassInfo(Int_t clNum) const
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Bool_t IgnoreEventsWithNegWeightsInTraining() const
void Train()
computes H-matrices for signal and background samples
MethodHMatrix(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor for the H-Matrix method
void ComputeCovariance(Bool_t, TMatrixD *)
compute covariance matrix
static RooMathCoreReg dummy
void SetCurrentType(Types::ETreeType type) const
void GetHelpMessage() const
get help message text
#define REGISTER_METHOD(CLASS)
for example
Abstract ClassifierFactory template that handles arbitrary types.
void DeclareOptions()
MethodHMatrix options: none (apart from those implemented in MethodBase)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
virtual Int_t GetSize() const
const Event * GetEvent() const
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
void SetSignalReferenceCut(Double_t cut)
Double_t GetChi2(Types::ESBType)
compute chi2-estimator for event according to type (signal/background)