169 Log() << kWARNING <<
"<Train> H-matrix S is almost singular with determinant= "
171 <<
" did you use the variables that are linear combinations or highly correlated ???"
175 Log() << kWARNING <<
"<Train> H-matrix B is almost singular with determinant= "
177 <<
" did you use the variables that are linear combinations or highly correlated ???"
182 Log() << kFATAL <<
"<Train> H-matrix S is singular with determinant= "
184 <<
" did you use the variables that are linear combinations ???"
188 Log() << kFATAL <<
"<Train> H-matrix B is singular with determinant= "
190 <<
" did you use the variables that are linear combinations ???"
212 TMatrixD mat2(nvar, nvar); mat2 *= 0;
222 const Event* origEvt =
Data()->GetEvent(i);
228 if (
DataInfo().IsSignal(origEvt) != isSignal)
continue;
235 sumOfWeights += weight;
238 for (ivar=0; ivar<nvar; ivar++) xval[ivar] = ev->
GetValue(ivar);
241 for (ivar=0; ivar<nvar; ivar++) {
243 vec(ivar) += xval[ivar]*weight;
244 mat2(ivar, ivar) += (xval[ivar]*xval[ivar])*weight;
246 for (jvar=ivar+1; jvar<nvar; jvar++) {
247 mat2(ivar, jvar) += (xval[ivar]*xval[jvar])*weight;
248 mat2(jvar, ivar) = mat2(ivar, jvar);
254 for (ivar=0; ivar<nvar; ivar++) {
256 if (isSignal) (*fVecMeanS)(ivar) =
vec(ivar)/sumOfWeights;
259 for (jvar=0; jvar<nvar; jvar++) {
260 (*mat)(ivar, jvar) = mat2(ivar, jvar)/sumOfWeights -
vec(ivar)*
vec(jvar)/(sumOfWeights*sumOfWeights);
275 if (s+
b < 0)
Log() << kFATAL <<
"big trouble: s+b: " << s+
b <<
Endl;
280 return (
b - s)/(s +
b);
294 std::vector<Double_t> val( nvar );
304 for (ivar=0; ivar<nvar; ivar++) val[ivar] = ev->
GetValue( ivar );
307 for (ivar=0; ivar<nvar; ivar++) {
308 for (jvar=0; jvar<nvar; jvar++) {
310 chi2 += ( (val[ivar] - (*fVecMeanS)(ivar))*(val[jvar] - (*fVecMeanS)(jvar))
311 * (*fInvHMatrixS)(ivar,jvar) );
313 chi2 += ( (val[ivar] - (*fVecMeanB)(ivar))*(val[jvar] - (*fVecMeanB)(jvar))
314 * (*fInvHMatrixB)(ivar,jvar) );
319 if (chi2 < 0)
Log() << kFATAL <<
"<GetChi2> negative chi2: " << chi2 <<
Endl;
364 for (ivar=0; ivar<
GetNvar(); ivar++)
368 for (ivar=0; ivar<
GetNvar(); ivar++)
369 for (jvar=0; jvar<
GetNvar(); jvar++)
373 for (ivar=0; ivar<
GetNvar(); ivar++)
374 for (jvar=0; jvar<
GetNvar(); jvar++)
383 fout <<
" // arrays of input evt vs. variable " << std::endl;
384 fout <<
" double fInvHMatrixS[" <<
GetNvar() <<
"][" <<
GetNvar() <<
"]; // inverse H-matrix (signal)" << std::endl;
385 fout <<
" double fInvHMatrixB[" <<
GetNvar() <<
"][" <<
GetNvar() <<
"]; // inverse H-matrix (background)" << std::endl;
386 fout <<
" double fVecMeanS[" <<
GetNvar() <<
"]; // vector of mean values (signal)" << std::endl;
387 fout <<
" double fVecMeanB[" <<
GetNvar() <<
"]; // vector of mean values (background)" << std::endl;
388 fout <<
" " << std::endl;
389 fout <<
" double GetChi2( const std::vector<double>& inputValues, int type ) const;" << std::endl;
390 fout <<
"};" << std::endl;
391 fout <<
" " << std::endl;
392 fout <<
"void " << className <<
"::Initialize() " << std::endl;
393 fout <<
"{" << std::endl;
394 fout <<
" // init vectors with mean values" << std::endl;
396 fout <<
" fVecMeanS[" << ivar <<
"] = " << (*fVecMeanS)(ivar) <<
";" << std::endl;
397 fout <<
" fVecMeanB[" << ivar <<
"] = " << (*fVecMeanB)(ivar) <<
";" << std::endl;
399 fout <<
" " << std::endl;
400 fout <<
" // init H-matrices" << std::endl;
403 fout <<
" fInvHMatrixS[" << ivar <<
"][" << jvar <<
"] = "
404 << (*fInvHMatrixS)(ivar,jvar) <<
";" << std::endl;
405 fout <<
" fInvHMatrixB[" << ivar <<
"][" << jvar <<
"] = "
406 << (*fInvHMatrixB)(ivar,jvar) <<
";" << std::endl;
409 fout <<
"}" << std::endl;
410 fout <<
" " << std::endl;
411 fout <<
"inline double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
412 fout <<
"{" << std::endl;
413 fout <<
" // returns the H-matrix signal estimator" << std::endl;
414 fout <<
" std::vector<double> inputValuesSig = inputValues;" << std::endl;
415 fout <<
" std::vector<double> inputValuesBgd = inputValues;" << std::endl;
418 UInt_t signalClass =
DataInfo().GetClassInfo(
"Signal")->GetNumber();
419 UInt_t backgroundClass=
DataInfo().GetClassInfo(
"Background")->GetNumber();
421 fout <<
" Transform(inputValuesSig," << signalClass <<
");" << std::endl;
422 fout <<
" Transform(inputValuesBgd," << backgroundClass <<
");" << std::endl;
427 fout <<
" double s = GetChi2( inputValuesSig, " <<
Types::kSignal <<
" );" << std::endl;
428 fout <<
" double b = GetChi2( inputValuesBgd, " <<
Types::kBackground <<
" );" << std::endl;
432 fout <<
" " << std::endl;
433 fout <<
" if (s+b <= 0) std::cout << \"Problem in class " << className <<
"::GetMvaValue__: s+b = \"" << std::endl;
434 fout <<
" << s+b << \" <= 0 \" << std::endl;" << std::endl;
435 fout <<
" " << std::endl;
436 fout <<
" return (b - s)/(s + b);" << std::endl;
437 fout <<
"}" << std::endl;
438 fout <<
" " << std::endl;
439 fout <<
"inline double " << className <<
"::GetChi2( const std::vector<double>& inputValues, int type ) const" << std::endl;
440 fout <<
"{" << std::endl;
441 fout <<
" // compute chi2-estimator for event according to type (signal/background)" << std::endl;
442 fout <<
" " << std::endl;
443 fout <<
" size_t ivar,jvar;" << std::endl;
444 fout <<
" double chi2 = 0;" << std::endl;
445 fout <<
" for (ivar=0; ivar<GetNvar(); ivar++) {" << std::endl;
446 fout <<
" for (jvar=0; jvar<GetNvar(); jvar++) {" << std::endl;
448 fout <<
" chi2 += ( (inputValues[ivar] - fVecMeanS[ivar])*(inputValues[jvar] - fVecMeanS[jvar])" << std::endl;
449 fout <<
" * fInvHMatrixS[ivar][jvar] );" << std::endl;
450 fout <<
" else" << std::endl;
451 fout <<
" chi2 += ( (inputValues[ivar] - fVecMeanB[ivar])*(inputValues[jvar] - fVecMeanB[jvar])" << std::endl;
452 fout <<
" * fInvHMatrixB[ivar][jvar] );" << std::endl;
453 fout <<
" }" << std::endl;
454 fout <<
" } // loop over variables " << std::endl;
455 fout <<
" " << std::endl;
456 fout <<
" // sanity check" << std::endl;
457 fout <<
" if (chi2 < 0) std::cout << \"Problem in class " << className <<
"::GetChi2: chi2 = \"" << std::endl;
458 fout <<
" << chi2 << \" < 0 \" << std::endl;" << std::endl;
459 fout <<
" " << std::endl;
460 fout <<
" return chi2;" << std::endl;
461 fout <<
"}" << std::endl;
462 fout <<
" " << std::endl;
463 fout <<
"// Clean up" << std::endl;
464 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
465 fout <<
"{" << std::endl;
466 fout <<
" // nothing to clear" << std::endl;
467 fout <<
"}" << std::endl;
481 Log() <<
"The H-Matrix classifier discriminates one class (signal) of a feature" <<
Endl;
482 Log() <<
"vector from another (background). The correlated elements of the" <<
Endl;
483 Log() <<
"vector are assumed to be Gaussian distributed, and the inverse of" <<
Endl;
484 Log() <<
"the covariance matrix is the H-Matrix. A multivariate chi-squared" <<
Endl;
485 Log() <<
"estimator is built that exploits differences in the mean values of" <<
Endl;
486 Log() <<
"the vector elements between the two classes for the purpose of" <<
Endl;
487 Log() <<
"discrimination." <<
Endl;
491 Log() <<
"The TMVA implementation of the H-Matrix classifier has been shown" <<
Endl;
492 Log() <<
"to underperform in comparison with the corresponding Fisher discriminant," <<
Endl;
493 Log() <<
"when using similar assumptions and complexity. Its use is therefore" <<
Endl;
494 Log() <<
"depreciated. Only in cases where the background model is strongly" <<
Endl;
495 Log() <<
"non-Gaussian, H-Matrix may perform better than Fisher. In such" <<
Endl;
496 Log() <<
"occurrences the user is advised to employ non-linear classifiers. " <<
Endl;
#define REGISTER_METHOD(CLASS)
for example
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
TMatrixT< Double_t > TMatrixD
TVectorT< Double_t > TVectorD
Class that contains all the data information.
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
MethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
standard constructor
Bool_t IgnoreEventsWithNegWeightsInTraining() const
UInt_t GetNEvents() const
DataSetInfo & DataInfo() const
const Event * fTmpEvent
! temporary event when testing on a different DataSet than the own one
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
void SetSignalReferenceCut(Double_t cut)
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
void Train() override
computes H-matrices for signal and background samples
void GetHelpMessage() const override
get help message text
void ReadWeightsFromXML(void *wghtnode) override
read weights from XML file
virtual ~MethodHMatrix()
destructor
void AddWeightsXMLTo(void *parent) const override
create XML description for HMatrix classification
void ReadWeightsFromStream(std::istream &istr) override
read variable names and min/max NOTE: the latter values are mandatory for the normalisation in the re...
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets) override
FDA can handle classification with 2 classes and regression with one regression-target.
MethodHMatrix(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor for the H-Matrix method
TMatrixD * fInvHMatrixS
inverse H-matrix (signal)
void ComputeCovariance(Bool_t, TMatrixD *)
compute covariance matrix
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr) override
returns the H-matrix signal estimator
void DeclareOptions() override
MethodHMatrix options: none (apart from those implemented in MethodBase).
void Init() override
default initialization called by all constructors
Double_t GetChi2(Types::ESBType)
compute chi2-estimator for event according to type (signal/background)
void MakeClassSpecific(std::ostream &, const TString &) const override
write Fisher-specific classifier response
TVectorD * fVecMeanS
vector of mean values (signal)
void ProcessOptions() override
process user options
TVectorD * fVecMeanB
vector of mean values (background)
TMatrixD * fInvHMatrixB
inverse H-matrix (background)
Singleton class for Global types used by TMVA.
@ kSignal
Never change this number - it is elsewhere assumed to be zero !
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.