# class TMVA::MethodFisher: public TMVA::MethodBase

```
```
Fisher and Mahalanobis Discriminants (Linear Discriminant Analysis)

In the method of Fisher discriminants event selection is performed in a transformed variable space with zero linear correlations, by distinguishing the mean values of the signal and background distributions.

The linear discriminant analysis determines an axis in the (correlated) hyperspace of the input variables such that, when projecting the output classes (signal and background) upon this axis, they are pushed as far as possible away from each other, while events of a same class are confined in a close vicinity. The linearity property of this method is reflected in the metric with which "far apart" and "close vicinity" are determined: the covariance matrix of the discriminant variable space.

The classification of the events in signal and background classes relies on the following characteristics (only): overall sample means, xi, for each input variable, i, class-specific sample means, xS(B),i, and total covariance matrix Tij. The covariance matrix can be decomposed into the sum of a within- (Wij) and a between-class (Bij) class matrix. They describe the dispersion of events relative to the means of their own class (within-class matrix), and relative to the overall sample means (between-class matrix). The Fisher coefficients, Fi, are then given by

where in TMVA is set NS=NB, so that the factor in front of the sum simplifies to ½. The Fisher discriminant then reads
The offset F0 centers the sample mean of xFi at zero. Instead of using the within-class matrix, the Mahalanobis variant determines the Fisher coefficients as follows:
with resulting xMa that are very similar to the xFi.

TMVA provides two outputs for the ranking of the input variables:

• Fisher test: the Fisher analysis aims at simultaneously maximising the between-class separation, while minimising the within-class dispersion. A useful measure of the discrimination power of a variable is hence given by the diagonal quantity: Bii/Wii.
• Discrimination power: the value of the Fisher coefficient is a measure of the discriminating power of a variable. The discrimination power of set of input variables can therefore be measured by the scalar
The corresponding numbers are printed on standard output.
```

```

## Function Members (Methods)

public:
protected:
 virtual void TObject::DoError(int level, const char* location, const char* fmt, va_list va) const void TMVA::Configurable::EnableLooseOptions(Bool_t b = kTRUE) virtual void GetHelpMessage() const virtual void TMVA::IMethod::GetHelpMessage() const const TString& TMVA::MethodBase::GetInternalVarName(Int_t ivar) const const TString& TMVA::MethodBase::GetOriginalVarName(Int_t ivar) const const TString& TMVA::Configurable::GetReferenceFile() const static TMVA::MethodBase* TMVA::MethodBase::GetThisBase() Float_t TMVA::MethodBase::GetTWeight(const TMVA::Event* ev) const const TString& TMVA::MethodBase::GetWeightFileDir() const Bool_t TMVA::MethodBase::HasTrainingTree() const Bool_t TMVA::MethodBase::Help() const Bool_t TMVA::MethodBase::IgnoreEventsWithNegWeightsInTraining() const Bool_t TMVA::MethodBase::IsConstructedFromWeightFile() const Bool_t TMVA::MethodBase::IsNormalised() const TMVA::MsgLogger& TMVA::Configurable::Log() const Bool_t TMVA::Configurable::LooseOptionCheckingEnabled() const virtual void MakeClassSpecific(ostream&, const TString&) const virtual void TMVA::MethodBase::MakeClassSpecific(ostream&, const TString& = "") const virtual void TMVA::IMethod::MakeClassSpecific(ostream&, const TString&) const virtual void TMVA::MethodBase::MakeClassSpecificHeader(ostream&, const TString& = "") const void TObject::MakeZombie() void TMVA::Configurable::ResetSetFlag() void TMVA::MethodBase::SetNormalised(Bool_t norm) void TMVA::MethodBase::SetWeightFileDir(TString fileDir) void TMVA::MethodBase::SetWeightFileName(TString) void TMVA::MethodBase::Statistics(TMVA::Types::ETreeType treeType, const TString& theVarName, Double_t&, Double_t&, Double_t&, Double_t&, Double_t&, Double_t&) Bool_t TMVA::MethodBase::TxtWeightsOnly() const Bool_t TMVA::MethodBase::Verbose() const void TMVA::Configurable::WriteOptionsReferenceToFile()
private:
 virtual void DeclareOptions() void GetCov_BetweenClass() void GetCov_Full() void GetCov_WithinClass() void GetDiscrimPower() void GetFisherCoeff() void GetMean() virtual void Init() void InitMatrices() void PrintCoefficients() virtual void ProcessOptions()

## Data Members

private:
 enum EFisherMethod { kFisher kMahalanobis }; enum TMVA::MethodBase::EWeightFileType { kROOT kTEXT }; enum TMVA::MethodBase::ECutOrientation { kNegative kPositive }; enum TObject::EStatusBits { kCanDelete kMustCleanup kObjInCanvas kIsReferenced kHasUUID kCannotPick kNoContextMenu kInvalidObject }; enum TObject::[unnamed] { kIsOnHeap kNotDeleted kZombie kBitMask kSingleKey kOverwrite kWriteDelete };
public:
 Bool_t TMVA::MethodBase::fSetupCompleted is method setup
protected:
 TMVA::Types::EAnalysisType TMVA::MethodBase::fAnalysisType method-mode : true --> regression, false --> classification UInt_t TMVA::MethodBase::fBackgroundClass index of the Background-class vector* TMVA::MethodBase::fInputVars vector of input variables used in MVA Int_t TMVA::MethodBase::fNbins number of bins in representative histograms Int_t TMVA::MethodBase::fNbinsH number of bins in evaluation histograms TMVA::Ranking* TMVA::MethodBase::fRanking pointer to ranking object (created by derived classifiers) vector* TMVA::MethodBase::fRegressionReturnVal holds the return-value for the regression UInt_t TMVA::MethodBase::fSignalClass index of the Signal-class Bool_t TMVA::MethodBase::fTxtWeightsOnly if TRUE, write weights only to text files
private:
 TMatrixD* fBetw between-class matrix TMatrixD* fCov full covariance matrix vector* fDiscrimPow discriminating power Double_t fF0 offset vector* fFisherCoeff Fisher coefficients TMVA::MethodFisher::EFisherMethod fFisherMethod Fisher or Mahalanobis TMatrixD* fMeanMatx Double_t fSumOfWeightsB sum-of-weights for background training events Double_t fSumOfWeightsS sum-of-weights for signal training events TString fTheMethod Fisher or Mahalanobis TMatrixD* fWith within-class matrix

## Function documentation

MethodFisher(const TString& jobName, const TString& methodTitle, TMVA::DataSetInfo& dsi, const TString& theOption = "Fisher", TDirectory* theTargetDir = 0)
``` standard constructor for the "Fisher"
```
MethodFisher(TMVA::DataSetInfo& dsi, const TString& theWeightFile, TDirectory* theTargetDir = NULL)
``` constructor from weight file
```
void Init( void )
``` default initialization called by all constructors
```
void DeclareOptions()
``` MethodFisher options:
format and syntax of option string: "type"
where type is "Fisher" or "Mahalanobis"

```
void ProcessOptions()
``` process user options
```
~MethodFisher( void )
``` destructor
```
Bool_t HasAnalysisType(TMVA::Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
``` Fisher can only handle classification with 2 classes
```
void Train( void )
``` computation of Fisher coefficients by series of matrix operations
```
Double_t GetMvaValue(Double_t* err = 0)
``` returns the Fisher value (no fixed range)
```
void InitMatrices( void )
``` initializaton method; creates global matrices and vectors
```
void GetMean( void )
``` compute mean values of variables in each sample, and the overall means
```
void GetCov_WithinClass( void )
``` the matrix of covariance 'within class' reflects the dispersion of the
events relative to the center of gravity of their own class
```
void GetCov_BetweenClass( void )
``` the matrix of covariance 'between class' reflects the dispersion of the
events of a class relative to the global center of gravity of all the class
hence the separation between classes
```
void GetCov_Full( void )
``` compute full covariance matrix from sum of within and between matrices
```
void GetFisherCoeff( void )
``` Fisher = Sum { [coeff]*[variables] }

let Xs be the array of the mean values of variables for signal evts
let Xb be the array of the mean values of variables for backgd evts
let InvWith be the inverse matrix of the 'within class' correlation matrix

then the array of Fisher coefficients is
[coeff] =sqrt(fNsig*fNbgd)/fNevt*transpose{Xs-Xb}*InvWith
```
void GetDiscrimPower( void )
``` computation of discrimination power indicator for each variable
small values of "fWith" indicates little compactness of sig & of backgd
big values of "fBetw" indicates large separation between sig & backgd

we want signal & backgd classes as compact and separated as possible
the discriminating power is then defined as the ration "fBetw/fWith"
```
const TMVA::Ranking* CreateRanking()
``` computes ranking of input variables
```
void PrintCoefficients( void )
``` display Fisher coefficients and discriminating power for each variable
check maximum length of variable name
```
void WriteWeightsToStream(ostream& o) const
``` save the weights
```
``` read Fisher coefficients from weight file
```
``` create XML description of Fisher classifier
```
``` read Fisher coefficients from xml weight file
``` write Fisher-specific classifier response
``` get help message text
`{ return fFisherMethod; }`