141 fFisherMethod ( kFisher ),
160 fTheMethod (
"Fisher" ),
161 fFisherMethod ( kFisher ),
179 fFisherCoeff =
new std::vector<Double_t>( GetNvar() );
182 SetSignalReferenceCut( 0.0 );
195 DeclareOptionRef( fTheMethod =
"Fisher",
"Method",
"Discrimination method" );
196 AddPreDefVal(
TString(
"Fisher"));
197 AddPreDefVal(
TString(
"Mahalanobis"));
205 if (fTheMethod ==
"Fisher" ) fFisherMethod = kFisher;
206 else fFisherMethod = kMahalanobis;
217 if (fBetw ) {
delete fBetw; fBetw = 0; }
218 if (fWith ) {
delete fWith; fWith = 0; }
219 if (fCov ) {
delete fCov; fCov = 0; }
220 if (fDiscrimPow ) {
delete fDiscrimPow; fDiscrimPow = 0; }
221 if (fFisherCoeff) {
delete fFisherCoeff; fFisherCoeff = 0; }
242 GetCov_WithinClass();
245 GetCov_BetweenClass();
286 fMeanMatx =
new TMatrixD( GetNvar(), 3 );
289 fBetw =
new TMatrixD( GetNvar(), GetNvar() );
290 fWith =
new TMatrixD( GetNvar(), GetNvar() );
291 fCov =
new TMatrixD( GetNvar(), GetNvar() );
294 fDiscrimPow =
new std::vector<Double_t>( GetNvar() );
306 const UInt_t nvar = DataInfo().GetNVariables();
321 if (DataInfo().IsSignal(
ev)) fSumOfWeightsS += weight;
322 else fSumOfWeightsB += weight;
337 (*fMeanMatx)(
ivar, 2 ) /= (fSumOfWeightsS + fSumOfWeightsB);
352 assert( fSumOfWeightsS > 0 && fSumOfWeightsB > 0 );
357 const Int_t nvar = GetNvar();
377 if (DataInfo().IsSignal(
ev)) {
400 (*fWith)(
x,
y) =
sumSig[k]/fSumOfWeightsS +
sumBgd[k]/fSumOfWeightsB;
418 assert( fSumOfWeightsS > 0 && fSumOfWeightsB > 0);
425 prodSig = ( ((*fMeanMatx)(
x, 0) - (*fMeanMatx)(
x, 2))*
426 ((*fMeanMatx)(
y, 0) - (*fMeanMatx)(
y, 2)) );
427 prodBgd = ( ((*fMeanMatx)(
x, 1) - (*fMeanMatx)(
x, 2))*
428 ((*fMeanMatx)(
y, 1) - (*fMeanMatx)(
y, 2)) );
430 (*fBetw)(
x,
y) = (fSumOfWeightsS*
prodSig + fSumOfWeightsB*
prodBgd) / (fSumOfWeightsS + fSumOfWeightsB);
442 (*fCov)(
x,
y) = (*fWith)(
x,
y) + (*fBetw)(
x,
y);
458 assert( fSumOfWeightsS > 0 && fSumOfWeightsB > 0);
462 switch (GetFisherMethod()) {
470 Log() << kFATAL <<
"<GetFisherCoeff> undefined method" << GetFisherMethod() <<
Endl;
476 Log() << kWARNING <<
"<GetFisherCoeff> matrix is almost singular with determinant="
478 <<
" did you use the variables that are linear combinations or highly correlated?"
483 Log() << kFATAL <<
"<GetFisherCoeff> matrix is singular with determinant="
485 <<
" did you use the variables that are linear combinations? \n"
486 <<
" do you any clue as to what went wrong in above printout of the covariance matrix? "
496 std::vector<Double_t>
diffMeans( GetNvar() );
499 (*fFisherCoeff)[
ivar] = 0;
513 fF0 += (*fFisherCoeff)[
ivar]*((*fMeanMatx)(
ivar, 0) + (*fMeanMatx)(
ivar, 1));
532 (*fDiscrimPow)[
ivar] = 0;
542 fRanking =
new Ranking( GetName(),
"Discr. power" );
545 fRanking->AddRank(
Rank( GetInputLabel(
ivar), (*fDiscrimPow)[
ivar] ) );
557 Log() << kHEADER <<
"Results for Fisher coefficients:" <<
Endl;
559 if (GetTransformationHandler().GetTransformationList().GetSize() != 0) {
560 Log() << kINFO <<
"NOTE: The coefficients must be applied to TRANFORMED variables" <<
Endl;
561 Log() << kINFO <<
" List of the transformation: " <<
Endl;
562 TListIter trIt(&GetTransformationHandler().GetTransformationList());
564 Log() << kINFO <<
" -- " <<
trf->GetName() <<
Endl;
567 std::vector<TString> vars;
568 std::vector<Double_t>
coeffs;
570 vars .push_back( GetInputLabel(
ivar) );
573 vars .push_back(
"(offset)" );
580 if (IsNormalised()) {
581 Log() << kINFO <<
"NOTE: You have chosen to use the \"Normalise\" booking option. Hence, the" <<
Endl;
582 Log() << kINFO <<
" coefficients must be applied to NORMALISED (') variables as follows:" <<
Endl;
589 << std::setw(
maxL+9) <<
TString(
"[") + GetInputLabel(
ivar) +
"]' = 2*("
591 << std::setw(3) << (GetXmin(
ivar) > 0 ?
" - " :
" + ")
592 << std::setw(6) <<
TMath::Abs(GetXmin(
ivar)) << std::setw(3) <<
")/"
593 << std::setw(6) << (GetXmax(
ivar) - GetXmin(
ivar) )
594 << std::setw(3) <<
" - 1"
597 Log() << kINFO <<
"The TMVA Reader will properly account for this normalisation, but if the" <<
Endl;
598 Log() << kINFO <<
"Fisher classifier is applied outside the Reader, the transformation must be" <<
Endl;
599 Log() << kINFO <<
"implemented -- or the \"Normalise\" option is removed and Fisher retrained." <<
Endl;
600 Log() << kINFO <<
Endl;
637 fFisherCoeff->resize(
ncoeff-1);
656 fout <<
" double fFisher0;" << std::endl;
657 fout <<
" std::vector<double> fFisherCoefficients;" << std::endl;
658 fout <<
"};" << std::endl;
659 fout <<
"" << std::endl;
660 fout <<
"inline void " << className <<
"::Initialize() " << std::endl;
661 fout <<
"{" << std::endl;
662 fout <<
" fFisher0 = " << std::setprecision(12) << fF0 <<
";" << std::endl;
664 fout <<
" fFisherCoefficients.push_back( " << std::setprecision(12) << (*fFisherCoeff)[
ivar] <<
" );" << std::endl;
667 fout <<
" // sanity check" << std::endl;
668 fout <<
" if (fFisherCoefficients.size() != fNvars) {" << std::endl;
669 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\"::Initialize: mismatch in number of input values\"" << std::endl;
670 fout <<
" << fFisherCoefficients.size() << \" != \" << fNvars << std::endl;" << std::endl;
671 fout <<
" fStatusIsClean = false;" << std::endl;
672 fout <<
" } " << std::endl;
673 fout <<
"}" << std::endl;
675 fout <<
"inline double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
676 fout <<
"{" << std::endl;
677 fout <<
" double retval = fFisher0;" << std::endl;
678 fout <<
" for (size_t ivar = 0; ivar < fNvars; ivar++) {" << std::endl;
679 fout <<
" retval += fFisherCoefficients[ivar]*inputValues[ivar];" << std::endl;
680 fout <<
" }" << std::endl;
682 fout <<
" return retval;" << std::endl;
683 fout <<
"}" << std::endl;
685 fout <<
"// Clean up" << std::endl;
686 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
687 fout <<
"{" << std::endl;
688 fout <<
" // clear coefficients" << std::endl;
689 fout <<
" fFisherCoefficients.clear(); " << std::endl;
690 fout <<
"}" << std::endl;
691 fout << std::setprecision(
dp);
705 Log() <<
"Fisher discriminants select events by distinguishing the mean " <<
Endl;
706 Log() <<
"values of the signal and background distributions in a trans- " <<
Endl;
707 Log() <<
"formed variable space where linear correlations are removed." <<
Endl;
709 Log() <<
" (More precisely: the \"linear discriminator\" determines" <<
Endl;
710 Log() <<
" an axis in the (correlated) hyperspace of the input " <<
Endl;
711 Log() <<
" variables such that, when projecting the output classes " <<
Endl;
712 Log() <<
" (signal and background) upon this axis, they are pushed " <<
Endl;
713 Log() <<
" as far as possible away from each other, while events" <<
Endl;
714 Log() <<
" of a same class are confined in a close vicinity. The " <<
Endl;
715 Log() <<
" linearity property of this classifier is reflected in the " <<
Endl;
716 Log() <<
" metric with which \"far apart\" and \"close vicinity\" are " <<
Endl;
717 Log() <<
" determined: the covariance matrix of the discriminating" <<
Endl;
718 Log() <<
" variable space.)" <<
Endl;
722 Log() <<
"Optimal performance for Fisher discriminants is obtained for " <<
Endl;
723 Log() <<
"linearly correlated Gaussian-distributed variables. Any deviation" <<
Endl;
724 Log() <<
"from this ideal reduces the achievable separation power. In " <<
Endl;
725 Log() <<
"particular, no discrimination at all is achieved for a variable" <<
Endl;
726 Log() <<
"that has the same sample mean for signal and background, even if " <<
Endl;
727 Log() <<
"the shapes of the distributions are very different. Thus, Fisher " <<
Endl;
728 Log() <<
"discriminants often benefit from suitable transformations of the " <<
Endl;
729 Log() <<
"input variables. For example, if a variable x in [-1,1] has a " <<
Endl;
730 Log() <<
"a parabolic signal distributions, and a uniform background" <<
Endl;
731 Log() <<
"distributions, their mean value is zero in both cases, leading " <<
Endl;
732 Log() <<
"to no separation. The simple transformation x -> |x| renders this " <<
Endl;
733 Log() <<
"variable powerful for the use in a Fisher discriminant." <<
Endl;
737 Log() <<
"<None>" <<
Endl;
#define REGISTER_METHOD(CLASS)
for example
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 result
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.
Virtual base Class for all MVA method.
Fisher and Mahalanobis Discriminants (Linear Discriminant Analysis)
void GetCov_Full(void)
compute full covariance matrix from sum of within and between matrices
void GetHelpMessage() const override
get help message text
MethodFisher(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="Fisher")
standard constructor for the "Fisher"
virtual ~MethodFisher(void)
destructor
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets) override
Fisher can only handle classification with 2 classes.
void AddWeightsXMLTo(void *parent) const override
create XML description of Fisher classifier
void GetDiscrimPower(void)
computation of discrimination power indicator for each variable small values of "fWith" indicates lit...
void PrintCoefficients(void)
display Fisher coefficients and discriminating power for each variable check maximum length of variab...
void GetCov_BetweenClass(void)
the matrix of covariance 'between class' reflects the dispersion of the events of a class relative to...
void Init(void) override
default initialization called by all constructors
void DeclareOptions() override
MethodFisher options: format and syntax of option string: "type" where type is "Fisher" or "Mahalanob...
void MakeClassSpecific(std::ostream &, const TString &) const override
write Fisher-specific classifier response
void ReadWeightsFromXML(void *wghtnode) override
read Fisher coefficients from xml weight file
void GetFisherCoeff(void)
Fisher = Sum { [coeff]*[variables] }.
void GetMean(void)
compute mean values of variables in each sample, and the overall means
void Train(void) override
computation of Fisher coefficients by series of matrix operations
void InitMatrices(void)
initialization method; creates global matrices and vectors
void GetCov_WithinClass(void)
the matrix of covariance 'within class' reflects the dispersion of the events relative to the center ...
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr) override
returns the Fisher value (no fixed range)
void ProcessOptions() override
process user options
const Ranking * CreateRanking() override
computes ranking of input variables
void ReadWeightsFromStream(std::istream &i) override
read Fisher coefficients from weight file
Ranking for variables in method (implementation)
Singleton class for Global types used by TMVA.
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
static uint64_t sum(uint64_t i)