170 Log() << kWARNING <<
"<Train> H-matrix S is almost singular with determinant= " 172 <<
" did you use the variables that are linear combinations or highly correlated ???" 176 Log() << kWARNING <<
"<Train> H-matrix B is almost singular with determinant= " 178 <<
" did you use the variables that are linear combinations or highly correlated ???" 183 Log() << kFATAL <<
"<Train> H-matrix S is singular with determinant= " 185 <<
" did you use the variables that are linear combinations ???" 189 Log() << kFATAL <<
"<Train> H-matrix B is singular with determinant= " 191 <<
" did you use the variables that are linear combinations ???" 213 TMatrixD mat2(nvar, nvar); mat2 *= 0;
229 if (
DataInfo().IsSignal(origEvt) != isSignal)
continue;
236 sumOfWeights += weight;
239 for (ivar=0; ivar<nvar; ivar++) xval[ivar] = ev->
GetValue(ivar);
242 for (ivar=0; ivar<nvar; ivar++) {
244 vec(ivar) += xval[ivar]*weight;
245 mat2(ivar, ivar) += (xval[ivar]*xval[ivar])*weight;
247 for (jvar=ivar+1; jvar<nvar; jvar++) {
248 mat2(ivar, jvar) += (xval[ivar]*xval[jvar])*weight;
249 mat2(jvar, ivar) = mat2(ivar, jvar);
255 for (ivar=0; ivar<nvar; ivar++) {
257 if (isSignal) (*fVecMeanS)(ivar) = vec(ivar)/sumOfWeights;
258 else (*
fVecMeanB)(ivar) = vec(ivar)/sumOfWeights;
260 for (jvar=0; jvar<nvar; jvar++) {
261 (*mat)(ivar, jvar) = mat2(ivar, jvar)/sumOfWeights - vec(ivar)*vec(jvar)/(sumOfWeights*sumOfWeights);
276 if (s+b < 0)
Log() << kFATAL <<
"big trouble: s+b: " << s+b <<
Endl;
281 return (b - s)/(s +
b);
295 std::vector<Double_t> val( nvar );
305 for (ivar=0; ivar<nvar; ivar++) val[ivar] = ev->
GetValue( ivar );
308 for (ivar=0; ivar<nvar; ivar++) {
309 for (jvar=0; jvar<nvar; jvar++) {
311 chi2 += ( (val[ivar] - (*fVecMeanS)(ivar))*(val[jvar] - (*fVecMeanS)(jvar))
312 * (*fInvHMatrixS)(ivar,jvar) );
314 chi2 += ( (val[ivar] - (*fVecMeanB)(ivar))*(val[jvar] - (*fVecMeanB)(jvar))
315 * (*fInvHMatrixB)(ivar,jvar) );
320 if (chi2 < 0)
Log() << kFATAL <<
"<GetChi2> negative chi2: " << chi2 <<
Endl;
365 for (ivar=0; ivar<
GetNvar(); ivar++)
369 for (ivar=0; ivar<
GetNvar(); ivar++)
370 for (jvar=0; jvar<
GetNvar(); jvar++)
374 for (ivar=0; ivar<
GetNvar(); ivar++)
375 for (jvar=0; jvar<
GetNvar(); jvar++)
384 fout <<
" // arrays of input evt vs. variable " << std::endl;
385 fout <<
" double fInvHMatrixS[" <<
GetNvar() <<
"][" <<
GetNvar() <<
"]; // inverse H-matrix (signal)" << std::endl;
386 fout <<
" double fInvHMatrixB[" <<
GetNvar() <<
"][" <<
GetNvar() <<
"]; // inverse H-matrix (background)" << std::endl;
387 fout <<
" double fVecMeanS[" <<
GetNvar() <<
"]; // vector of mean values (signal)" << std::endl;
388 fout <<
" double fVecMeanB[" <<
GetNvar() <<
"]; // vector of mean values (background)" << std::endl;
389 fout <<
" " << std::endl;
390 fout <<
" double GetChi2( const std::vector<double>& inputValues, int type ) const;" << std::endl;
391 fout <<
"};" << std::endl;
392 fout <<
" " << std::endl;
393 fout <<
"void " << className <<
"::Initialize() " << std::endl;
394 fout <<
"{" << std::endl;
395 fout <<
" // init vectors with mean values" << std::endl;
397 fout <<
" fVecMeanS[" << ivar <<
"] = " << (*fVecMeanS)(ivar) <<
";" << std::endl;
398 fout <<
" fVecMeanB[" << ivar <<
"] = " << (*fVecMeanB)(ivar) <<
";" << std::endl;
400 fout <<
" " << std::endl;
401 fout <<
" // init H-matrices" << std::endl;
404 fout <<
" fInvHMatrixS[" << ivar <<
"][" << jvar <<
"] = " 405 << (*fInvHMatrixS)(ivar,jvar) <<
";" << std::endl;
406 fout <<
" fInvHMatrixB[" << ivar <<
"][" << jvar <<
"] = " 407 << (*fInvHMatrixB)(ivar,jvar) <<
";" << std::endl;
410 fout <<
"}" << std::endl;
411 fout <<
" " << std::endl;
412 fout <<
"inline double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
413 fout <<
"{" << std::endl;
414 fout <<
" // returns the H-matrix signal estimator" << std::endl;
415 fout <<
" std::vector<double> inputValuesSig = inputValues;" << std::endl;
416 fout <<
" std::vector<double> inputValuesBgd = inputValues;" << std::endl;
422 fout <<
" Transform(inputValuesSig," << signalClass <<
");" << std::endl;
423 fout <<
" Transform(inputValuesBgd," << backgroundClass <<
");" << std::endl;
428 fout <<
" double s = GetChi2( inputValuesSig, " <<
Types::kSignal <<
" );" << std::endl;
429 fout <<
" double b = GetChi2( inputValuesBgd, " <<
Types::kBackground <<
" );" << std::endl;
433 fout <<
" " << std::endl;
434 fout <<
" if (s+b <= 0) std::cout << \"Problem in class " << className <<
"::GetMvaValue__: s+b = \"" << std::endl;
435 fout <<
" << s+b << \" <= 0 \" << std::endl;" << std::endl;
436 fout <<
" " << std::endl;
437 fout <<
" return (b - s)/(s + b);" << std::endl;
438 fout <<
"}" << std::endl;
439 fout <<
" " << std::endl;
440 fout <<
"inline double " << className <<
"::GetChi2( const std::vector<double>& inputValues, int type ) const" << std::endl;
441 fout <<
"{" << std::endl;
442 fout <<
" // compute chi2-estimator for event according to type (signal/background)" << std::endl;
443 fout <<
" " << std::endl;
444 fout <<
" size_t ivar,jvar;" << std::endl;
445 fout <<
" double chi2 = 0;" << std::endl;
446 fout <<
" for (ivar=0; ivar<GetNvar(); ivar++) {" << std::endl;
447 fout <<
" for (jvar=0; jvar<GetNvar(); jvar++) {" << std::endl;
449 fout <<
" chi2 += ( (inputValues[ivar] - fVecMeanS[ivar])*(inputValues[jvar] - fVecMeanS[jvar])" << std::endl;
450 fout <<
" * fInvHMatrixS[ivar][jvar] );" << std::endl;
451 fout <<
" else" << std::endl;
452 fout <<
" chi2 += ( (inputValues[ivar] - fVecMeanB[ivar])*(inputValues[jvar] - fVecMeanB[jvar])" << std::endl;
453 fout <<
" * fInvHMatrixB[ivar][jvar] );" << std::endl;
454 fout <<
" }" << std::endl;
455 fout <<
" } // loop over variables " << std::endl;
456 fout <<
" " << std::endl;
457 fout <<
" // sanity check" << std::endl;
458 fout <<
" if (chi2 < 0) std::cout << \"Problem in class " << className <<
"::GetChi2: chi2 = \"" << std::endl;
459 fout <<
" << chi2 << \" < 0 \" << std::endl;" << std::endl;
460 fout <<
" " << std::endl;
461 fout <<
" return chi2;" << std::endl;
462 fout <<
"}" << std::endl;
463 fout <<
" " << std::endl;
464 fout <<
"// Clean up" << std::endl;
465 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
466 fout <<
"{" << std::endl;
467 fout <<
" // nothing to clear" << std::endl;
468 fout <<
"}" << std::endl;
482 Log() <<
"The H-Matrix classifier discriminates one class (signal) of a feature" <<
Endl;
483 Log() <<
"vector from another (background). The correlated elements of the" <<
Endl;
484 Log() <<
"vector are assumed to be Gaussian distributed, and the inverse of" <<
Endl;
485 Log() <<
"the covariance matrix is the H-Matrix. A multivariate chi-squared" <<
Endl;
486 Log() <<
"estimator is built that exploits differences in the mean values of" <<
Endl;
487 Log() <<
"the vector elements between the two classes for the purpose of" <<
Endl;
488 Log() <<
"discrimination." <<
Endl;
492 Log() <<
"The TMVA implementation of the H-Matrix classifier has been shown" <<
Endl;
493 Log() <<
"to underperform in comparison with the corresponding Fisher discriminant," <<
Endl;
494 Log() <<
"when using similar assumptions and complexity. Its use is therefore" <<
Endl;
495 Log() <<
"depreciated. Only in cases where the background model is strongly" <<
Endl;
496 Log() <<
"non-Gaussian, H-Matrix may perform better than Fisher. In such" <<
Endl;
497 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)
Singleton class for Global types used by TMVA.
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.
Virtual base Class for all MVA method.
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
Class that contains all the data information.
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
constexpr Double_t E()
Base of natural log: .
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
static constexpr double s
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
H-Matrix method, which is implemented as a simple comparison of chi-squared estimators for signal and...
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
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)