142 fTheMethod (
"Fisher" ),
143 fFisherMethod ( kFisher ),
159 const TString& theWeightFile) :
316 for (
UInt_t ivar=0; ivar<nvar; ivar++) { sumS[ivar] = sumB[ivar] = 0; }
331 for (
UInt_t ivar=0; ivar<nvar; ivar++) sum[ivar] += ev->
GetValue( ivar )*weight;
334 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
335 (*fMeanMatx)( ivar, 2 ) = sumS[ivar];
338 (*fMeanMatx)( ivar, 2 ) += sumB[ivar];
363 const Int_t nvar2 = nvar*nvar;
367 memset(sumSig,0,nvar2*
sizeof(
Double_t));
368 memset(sumBgd,0,nvar2*
sizeof(
Double_t));
383 Double_t v = ( (xval[
x] - (*fMeanMatx)(
x, 0))*(xval[
y] - (*fMeanMatx)(
y, 0)) )*weight;
386 Double_t v = ( (xval[
x] - (*fMeanMatx)(
x, 1))*(xval[
y] - (*fMeanMatx)(
y, 1)) )*weight;
430 prodSig = ( ((*fMeanMatx)(
x, 0) - (*
fMeanMatx)(
x, 2))*
432 prodBgd = ( ((*fMeanMatx)(
x, 1) - (*
fMeanMatx)(
x, 2))*
481 Log() <<
kWARNING <<
"<GetFisherCoeff> matrix is almost singular with deterninant=" 483 <<
" did you use the variables that are linear combinations or highly correlated?" 488 Log() <<
kFATAL <<
"<GetFisherCoeff> matrix is singular with determinant=" 490 <<
" did you use the variables that are linear combinations? \n" 491 <<
" do you any clue as to what went wrong in above printout of the covariance matrix? " 501 std::vector<Double_t> diffMeans(
GetNvar() );
503 for (ivar=0; ivar<
GetNvar(); ivar++) {
504 (*fFisherCoeff)[ivar] = 0;
506 for (jvar=0; jvar<
GetNvar(); jvar++) {
508 (*fFisherCoeff)[ivar] += invCov(ivar, jvar)*d;
511 (*fFisherCoeff)[ivar] *= xfact;
517 for (ivar=0; ivar<
GetNvar(); ivar++){
518 fF0 += (*fFisherCoeff)[ivar]*((*fMeanMatx)(ivar, 0) + (*
fMeanMatx)(ivar, 1));
534 if ((*
fCov)(ivar, ivar) != 0)
535 (*fDiscrimPow)[ivar] = (*fBetw)(ivar, ivar)/(*
fCov)(ivar, ivar);
565 Log() <<
kINFO <<
"NOTE: The coefficients must be applied to TRANFORMED variables" <<
Endl;
566 Log() <<
kINFO <<
" List of the transformation: " <<
Endl;
572 std::vector<TString> vars;
573 std::vector<Double_t> coeffs;
578 vars .push_back(
"(offset)" );
579 coeffs.push_back(
fF0 );
586 Log() <<
kINFO <<
"NOTE: You have chosen to use the \"Normalise\" booking option. Hence, the" <<
Endl;
587 Log() <<
kINFO <<
" coefficients must be applied to NORMALISED (') variables as follows:" <<
Endl;
596 << std::setw(3) << (
GetXmin(ivar) > 0 ?
" - " :
" + ")
599 << std::setw(3) <<
" - 1" 602 Log() <<
kINFO <<
"The TMVA Reader will properly account for this normalisation, but if the" <<
Endl;
603 Log() <<
kINFO <<
"Fisher classifier is applied outside the Reader, the transformation must be" <<
Endl;
604 Log() <<
kINFO <<
"implemented -- or the \"Normalise\" option is removed and Fisher retrained." <<
Endl;
615 for (
UInt_t ivar=0; ivar<GetNvar(); ivar++) istr >> (*fFisherCoeff)[ivar];
649 if (coeffidx==0)
fF0 = coeff;
660 Int_t dp = fout.precision();
661 fout <<
" double fFisher0;" << std::endl;
662 fout <<
" std::vector<double> fFisherCoefficients;" << std::endl;
663 fout <<
"};" << std::endl;
664 fout <<
"" << std::endl;
665 fout <<
"inline void " << className <<
"::Initialize() " << std::endl;
666 fout <<
"{" << std::endl;
667 fout <<
" fFisher0 = " << std::setprecision(12) <<
fF0 <<
";" << std::endl;
669 fout <<
" fFisherCoefficients.push_back( " << std::setprecision(12) << (*fFisherCoeff)[ivar] <<
" );" << std::endl;
672 fout <<
" // sanity check" << std::endl;
673 fout <<
" if (fFisherCoefficients.size() != fNvars) {" << std::endl;
674 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\"::Initialize: mismatch in number of input values\"" << std::endl;
675 fout <<
" << fFisherCoefficients.size() << \" != \" << fNvars << std::endl;" << std::endl;
676 fout <<
" fStatusIsClean = false;" << std::endl;
677 fout <<
" } " << std::endl;
678 fout <<
"}" << std::endl;
680 fout <<
"inline double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
681 fout <<
"{" << std::endl;
682 fout <<
" double retval = fFisher0;" << std::endl;
683 fout <<
" for (size_t ivar = 0; ivar < fNvars; ivar++) {" << std::endl;
684 fout <<
" retval += fFisherCoefficients[ivar]*inputValues[ivar];" << std::endl;
685 fout <<
" }" << std::endl;
687 fout <<
" return retval;" << std::endl;
688 fout <<
"}" << std::endl;
690 fout <<
"// Clean up" << std::endl;
691 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
692 fout <<
"{" << std::endl;
693 fout <<
" // clear coefficients" << std::endl;
694 fout <<
" fFisherCoefficients.clear(); " << std::endl;
695 fout <<
"}" << std::endl;
696 fout << std::setprecision(dp);
710 Log() <<
"Fisher discriminants select events by distinguishing the mean " <<
Endl;
711 Log() <<
"values of the signal and background distributions in a trans- " <<
Endl;
712 Log() <<
"formed variable space where linear correlations are removed." <<
Endl;
714 Log() <<
" (More precisely: the \"linear discriminator\" determines" <<
Endl;
715 Log() <<
" an axis in the (correlated) hyperspace of the input " <<
Endl;
716 Log() <<
" variables such that, when projecting the output classes " <<
Endl;
717 Log() <<
" (signal and background) upon this axis, they are pushed " <<
Endl;
718 Log() <<
" as far as possible away from each other, while events" <<
Endl;
719 Log() <<
" of a same class are confined in a close vicinity. The " <<
Endl;
720 Log() <<
" linearity property of this classifier is reflected in the " <<
Endl;
721 Log() <<
" metric with which \"far apart\" and \"close vicinity\" are " <<
Endl;
722 Log() <<
" determined: the covariance matrix of the discriminating" <<
Endl;
723 Log() <<
" variable space.)" <<
Endl;
727 Log() <<
"Optimal performance for Fisher discriminants is obtained for " <<
Endl;
728 Log() <<
"linearly correlated Gaussian-distributed variables. Any deviation" <<
Endl;
729 Log() <<
"from this ideal reduces the achievable separation power. In " <<
Endl;
730 Log() <<
"particular, no discrimination at all is achieved for a variable" <<
Endl;
731 Log() <<
"that has the same sample mean for signal and background, even if " <<
Endl;
732 Log() <<
"the shapes of the distributions are very different. Thus, Fisher " <<
Endl;
733 Log() <<
"discriminants often benefit from suitable transformations of the " <<
Endl;
734 Log() <<
"input variables. For example, if a variable x in [-1,1] has a " <<
Endl;
735 Log() <<
"a parabolic signal distributions, and a uniform background" <<
Endl;
736 Log() <<
"distributions, their mean value is zero in both cases, leading " <<
Endl;
737 Log() <<
"to no separation. The simple transformation x -> |x| renders this " <<
Endl;
738 Log() <<
"variable powerful for the use in a Fisher discriminant." <<
Endl;
void GetCov_BetweenClass(void)
the matrix of covariance 'between class' reflects the dispersion of the events of a class relative to...
const Ranking * CreateRanking()
computes ranking of input variables
UInt_t GetNVariables() const
static long int sum(long int i)
MethodFisher(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="Fisher")
standard constructor for the "Fisher"
MsgLogger & Endl(MsgLogger &ml)
void ReadWeightsFromStream(std::istream &i)
read Fisher coefficients from weight file
virtual ~MethodFisher(void)
destructor
void GetCov_Full(void)
compute full covariance matrix from sum of within and between matrices
void GetDiscrimPower(void)
computation of discrimination power indicator for each variable small values of "fWith" indicates lit...
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
Fisher can only handle classification with 2 classes.
EFisherMethod GetFisherMethod(void)
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
void AddWeightsXMLTo(void *parent) const
create XML description of Fisher classifier
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
std::vector< Double_t > * fFisherCoeff
virtual Double_t Determinant() const
Return the matrix determinant.
void GetHelpMessage() const
get help message text
const TString & GetInputLabel(Int_t i) const
const Event * GetEvent() const
EFisherMethod fFisherMethod
Double_t GetXmin(Int_t ivar) const
DataSetInfo & DataInfo() const
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not...
TMatrixT< Element > & Invert(Double_t *det=0)
Invert the matrix and calculate its determinant.
Double_t GetXmax(Int_t ivar) const
TMatrixT< Double_t > TMatrixD
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
returns the Fisher value (no fixed range)
void Train(void)
computation of Fisher coefficients by series of matrix operations
void ReadWeightsFromXML(void *wghtnode)
read Fisher coefficients from xml weight file
void ProcessOptions()
process user options
const char * GetName() const
void InitMatrices(void)
initializaton method; creates global matrices and vectors
void DeclareOptions()
MethodFisher options: format and syntax of option string: "type" where type is "Fisher" or "Mahalanob...
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
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 ...
Bool_t IsNormalised() const
void AddPreDefVal(const T &)
void Print(Option_t *name="") const
Print the matrix as a table of elements.
#define REGISTER_METHOD(CLASS)
for example
void MakeClassSpecific(std::ostream &, const TString &) const
write Fisher-specific classifier response
virtual void AddRank(const Rank &rank)
Add a new rank take ownership of it.
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
void PrintCoefficients(void)
display Fisher coefficients and discriminating power for each variable check maximum length of variab...
Bool_t IsSignal(const Event *ev) const
Double_t Sqrt(Double_t x)
void GetFisherCoeff(void)
Fisher = Sum { [coeff]*[variables] }.
std::vector< Double_t > * fDiscrimPow
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
void SetSignalReferenceCut(Double_t cut)
void Init(void)
default initialization called by all constructors