101 if(DataInfo().GetNTargets()!=0) fNRegOut = DataInfo().GetNTargets();
106 (*fLDCoeff)[
iout] =
new std::vector<Double_t>( GetNvar()+1 );
110 SetSignalReferenceCut( 0.0 );
118 if (fSumMatx) {
delete fSumMatx; fSumMatx = 0; }
119 if (fSumValMatx) {
delete fSumValMatx; fSumValMatx = 0; }
120 if (fCoeffMatx) {
delete fCoeffMatx; fCoeffMatx = 0; }
122 for (vector< vector< Double_t >* >::iterator
vi=fLDCoeff->
begin();
vi!=fLDCoeff->
end(); ++
vi){
123 if (*
vi) {
delete *
vi; *
vi = 0; }
125 delete fLDCoeff; fLDCoeff = 0;
168 if (fRegressionReturnVal ==
NULL) fRegressionReturnVal =
new vector< Float_t >();
169 fRegressionReturnVal->resize( fNRegOut );
172 (*fRegressionReturnVal)[
iout] = (*(*fLDCoeff)[
iout])[0] ;
175 for (
auto const& val :
ev->GetValues()) {
176 (*fRegressionReturnVal)[
iout] += (*(*fLDCoeff)[
iout])[++
icoeff] * val;
183 return (*fRegressionReturnVal)[0];
193 if (fRegressionReturnVal ==
NULL) fRegressionReturnVal =
new vector< Float_t >();
194 fRegressionReturnVal->resize( fNRegOut );
197 (*fRegressionReturnVal)[
iout] = (*(*fLDCoeff)[
iout])[0] ;
200 for (
auto const& val :
ev->GetValues()) {
201 (*fRegressionReturnVal)[
iout] += (*(*fLDCoeff)[
iout])[++
icoeff] * val;
209 const Event*
evT2 = GetTransformationHandler().InverseTransform(
evT );
210 fRegressionReturnVal->clear();
214 return (*fRegressionReturnVal);
222 fSumMatx =
new TMatrixD( GetNvar()+1, GetNvar()+1 );
223 fSumValMatx =
new TMatrixD( GetNvar()+1, fNRegOut );
224 fCoeffMatx =
new TMatrixD( GetNvar()+1, fNRegOut );
234 const UInt_t nvar = DataInfo().GetNVariables();
246 if (IgnoreEventsWithNegWeightsInTraining() && weight <= 0)
continue;
249 (*fSumMatx)( 0, 0 ) += weight;
253 (*fSumMatx)(
ivar+1, 0 ) +=
ev->GetValue(
ivar ) * weight;
254 (*fSumMatx)( 0,
ivar+1 ) +=
ev->GetValue(
ivar ) * weight;
271 const UInt_t nvar = DataInfo().GetNVariables();
287 if (IgnoreEventsWithNegWeightsInTraining() && weight <= 0)
continue;
293 if (!DoRegression()){
294 val *= DataInfo().IsSignal(
ev);
296 val *=
ev->GetTarget(
ivar );
298 (*fSumValMatx)( 0,
ivar ) += val;
311 const UInt_t nvar = DataInfo().GetNVariables();
316 Log() << kWARNING <<
"<GetCoeff> matrix is almost singular with determinant="
318 <<
" did you use the variables that are linear combinations or highly correlated?"
322 Log() << kFATAL <<
"<GetCoeff> matrix is singular with determinant="
324 <<
" did you use the variables that are linear combinations?"
333 if (!DoRegression()) {
334 (*(*fLDCoeff)[
ivar])[0]=0.0;
336 (*(*fLDCoeff)[
ivar])[0]+=(*fCoeffMatx)(
jvar,
ivar)*(*fSumMatx)(0,
jvar)/(*fSumMatx)( 0, 0 );
338 (*(*fLDCoeff)[
ivar])[0]/=-2.0;
385 if (
ncoeff != GetNvar()+1) Log() << kFATAL <<
"Mismatch in number of output variables/coefficients: "
390 for (vector< vector< Double_t >* >::iterator
vi=fLDCoeff->
begin();
vi!=fLDCoeff->
end(); ++
vi){
391 if (*
vi) {
delete *
vi; *
vi = 0; }
393 delete fLDCoeff; fLDCoeff = 0;
417 fout <<
" std::vector<double> fLDCoefficients;" << std::endl;
418 fout <<
"};" << std::endl;
419 fout <<
"" << std::endl;
420 fout <<
"inline void " << className <<
"::Initialize() " << std::endl;
421 fout <<
"{" << std::endl;
424 fout <<
" fLDCoefficients.push_back( "
425 << std::setprecision(12) << (*(*fLDCoeff)[0])[
ivar]
426 << std::setprecision(
dp) <<
" );" << std::endl;
429 fout <<
" // sanity check" << std::endl;
430 fout <<
" if (fLDCoefficients.size() != fNvars+1) {" << std::endl;
431 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\"::Initialize: mismatch in number of input values\"" << std::endl;
432 fout <<
" << fLDCoefficients.size() << \" != \" << fNvars+1 << std::endl;" << std::endl;
433 fout <<
" fStatusIsClean = false;" << std::endl;
434 fout <<
" } " << std::endl;
435 fout <<
"}" << std::endl;
437 fout <<
"inline double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
438 fout <<
"{" << std::endl;
439 fout <<
" double retval = fLDCoefficients[0];" << std::endl;
440 fout <<
" for (size_t ivar = 1; ivar < fNvars+1; ivar++) {" << std::endl;
441 fout <<
" retval += fLDCoefficients[ivar]*inputValues[ivar-1];" << std::endl;
442 fout <<
" }" << std::endl;
444 fout <<
" return retval;" << std::endl;
445 fout <<
"}" << std::endl;
447 fout <<
"// Clean up" << std::endl;
448 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
449 fout <<
"{" << std::endl;
450 fout <<
" // clear coefficients" << std::endl;
451 fout <<
" fLDCoefficients.clear(); " << std::endl;
452 fout <<
"}" << std::endl;
460 fRanking =
new Ranking( GetName(),
"Discr. power" );
482 if (HasTrainingTree()) InitMatrices();
490 Log() << kHEADER <<
"Results for LD coefficients:" <<
Endl;
492 if (GetTransformationHandler().GetTransformationList().GetSize() != 0) {
493 Log() << kINFO <<
"NOTE: The coefficients must be applied to TRANFORMED variables" <<
Endl;
494 Log() << kINFO <<
" List of the transformation: " <<
Endl;
495 TListIter trIt(&GetTransformationHandler().GetTransformationList());
497 Log() << kINFO <<
" -- " <<
trf->GetName() <<
Endl;
500 std::vector<TString> vars;
501 std::vector<Double_t>
coeffs;
503 vars .push_back( GetInputLabel(
ivar) );
504 coeffs.push_back( (* (*fLDCoeff)[0])[
ivar+1] );
506 vars .push_back(
"(offset)" );
507 coeffs.push_back((* (*fLDCoeff)[0])[0] );
509 if (IsNormalised()) {
510 Log() << kINFO <<
"NOTE: You have chosen to use the \"Normalise\" booking option. Hence, the" <<
Endl;
511 Log() << kINFO <<
" coefficients must be applied to NORMALISED (') variables as follows:" <<
Endl;
518 << std::setw(
maxL+9) <<
TString(
"[") + GetInputLabel(
ivar) +
"]' = 2*("
520 << std::setw(3) << (GetXmin(
ivar) > 0 ?
" - " :
" + ")
521 << std::setw(6) <<
TMath::Abs(GetXmin(
ivar)) << std::setw(3) <<
")/"
522 << std::setw(6) << (GetXmax(
ivar) - GetXmin(
ivar) )
523 << std::setw(3) <<
" - 1"
526 Log() << kINFO <<
"The TMVA Reader will properly account for this normalisation, but if the" <<
Endl;
527 Log() << kINFO <<
"LD classifier is applied outside the Reader, the transformation must be" <<
Endl;
528 Log() << kINFO <<
"implemented -- or the \"Normalise\" option is removed and LD retrained." <<
Endl;
529 Log() << kINFO <<
Endl;
544 Log() <<
"Linear discriminants select events by distinguishing the mean " <<
Endl;
545 Log() <<
"values of the signal and background distributions in a trans- " <<
Endl;
546 Log() <<
"formed variable space where linear correlations are removed." <<
Endl;
547 Log() <<
"The LD implementation here is equivalent to the \"Fisher\" discriminant" <<
Endl;
548 Log() <<
"for classification, but also provides linear regression." <<
Endl;
550 Log() <<
" (More precisely: the \"linear discriminator\" determines" <<
Endl;
551 Log() <<
" an axis in the (correlated) hyperspace of the input " <<
Endl;
552 Log() <<
" variables such that, when projecting the output classes " <<
Endl;
553 Log() <<
" (signal and background) upon this axis, they are pushed " <<
Endl;
554 Log() <<
" as far as possible away from each other, while events" <<
Endl;
555 Log() <<
" of a same class are confined in a close vicinity. The " <<
Endl;
556 Log() <<
" linearity property of this classifier is reflected in the " <<
Endl;
557 Log() <<
" metric with which \"far apart\" and \"close vicinity\" are " <<
Endl;
558 Log() <<
" determined: the covariance matrix of the discriminating" <<
Endl;
559 Log() <<
" variable space.)" <<
Endl;
563 Log() <<
"Optimal performance for the linear discriminant is obtained for " <<
Endl;
564 Log() <<
"linearly correlated Gaussian-distributed variables. Any deviation" <<
Endl;
565 Log() <<
"from this ideal reduces the achievable separation power. In " <<
Endl;
566 Log() <<
"particular, no discrimination at all is achieved for a variable" <<
Endl;
567 Log() <<
"that has the same sample mean for signal and background, even if " <<
Endl;
568 Log() <<
"the shapes of the distributions are very different. Thus, the linear " <<
Endl;
569 Log() <<
"discriminant often benefits from a suitable transformation of the " <<
Endl;
570 Log() <<
"input variables. For example, if a variable x in [-1,1] has a " <<
Endl;
571 Log() <<
"a parabolic signal distributions, and a uniform background" <<
Endl;
572 Log() <<
"distributions, their mean value is zero in both cases, leading " <<
Endl;
573 Log() <<
"to no separation. The simple transformation x -> |x| renders this " <<
Endl;
574 Log() <<
"variable powerful for the use in a linear discriminant." <<
Endl;
578 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 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
const_iterator begin() const
const_iterator end() const
Class that contains all the data information.
Virtual base Class for all MVA method.
void GetSum(void)
Calculates the matrix transposed(X)*W*X with W being the diagonal weight matrix and X the coordinates...
void ReadWeightsFromStream(std::istream &i) override
read LD coefficients from weight file
void Init(void) override
default initialization called by all constructors
MethodLD(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="LD")
standard constructor for the LD
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets) override
LD can handle classification with 2 classes and regression with one regression-target.
void MakeClassSpecific(std::ostream &, const TString &) const override
write LD-specific classifier response
void ReadWeightsFromXML(void *wghtnode) override
read coefficients from xml weight file
void GetLDCoeff(void)
Calculates the coefficients used for classification/regression.
void GetHelpMessage() const override
get help message text
const Ranking * CreateRanking() override
computes ranking of input variables
void DeclareOptions() override
MethodLD options.
const std::vector< Float_t > & GetRegressionValues() override
Calculates the regression output.
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr) override
Returns the MVA classification output.
void PrintCoefficients(void)
Display the classification/regression coefficients for each variable.
void AddWeightsXMLTo(void *parent) const override
create XML description for LD classification and regression (for arbitrary number of output classes/t...
virtual ~MethodLD(void)
destructor
void Train(void) override
compute fSumMatx
void InitMatrices(void)
Initialization method; creates global matrices and vectors.
void GetSumVal(void)
Calculates the vector transposed(X)*W*Y with Y being the target vector.
void ProcessOptions() override
this is the preparation for training
Ranking for variables in method (implementation)
Singleton class for Global types used by TMVA.
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.