99 (*fLDCoeff)[iout] =
new std::vector<Double_t>(
GetNvar()+1 );
115 for (vector< vector< Double_t >* >::iterator vi=
fLDCoeff->begin(); vi!=
fLDCoeff->end(); vi++){
116 if (*vi) {
delete *vi; *vi = 0; }
129 Log() <<
"regression with " << numberTargets <<
" targets.";
166 (*fRegressionReturnVal)[iout] = (*(*fLDCoeff)[iout])[0] ;
169 for (std::vector<Float_t>::const_iterator it = ev->
GetValues().begin();it!=ev->
GetValues().end();++it){
170 (*fRegressionReturnVal)[iout] += (*(*fLDCoeff)[iout])[++icoeff] * (*it);
191 (*fRegressionReturnVal)[iout] = (*(*fLDCoeff)[iout])[0] ;
194 for (std::vector<Float_t>::const_iterator it = ev->
GetValues().begin();it!=ev->
GetValues().end();++it){
195 (*fRegressionReturnVal)[iout] += (*(*fLDCoeff)[iout])[++icoeff] * (*it);
230 for (
UInt_t ivar = 0; ivar<=nvar; ivar++){
231 for (
UInt_t jvar = 0; jvar<=nvar; jvar++) (*
fSumMatx)( ivar, jvar ) = 0;
236 for (
Int_t ievt=0; ievt<nevts; ievt++) {
243 (*fSumMatx)( 0, 0 ) += weight;
246 for (
UInt_t ivar=0; ivar<nvar; ivar++) {
247 (*fSumMatx)( ivar+1, 0 ) += ev->
GetValue( ivar ) * weight;
248 (*fSumMatx)( 0, ivar+1 ) += ev->
GetValue( ivar ) * weight;
252 for (
UInt_t ivar=0; ivar<nvar; ivar++){
253 for (
UInt_t jvar=0; jvar<nvar; jvar++){
254 (*fSumMatx)( ivar+1, jvar+1 ) += ev->
GetValue( ivar ) * ev->
GetValue( jvar ) * weight;
268 for (
UInt_t jvar = 0; jvar<=nvar; jvar++){
269 (*fSumValMatx)(jvar,ivar) = 0;
292 (*fSumValMatx)( 0,ivar ) += val;
293 for (
UInt_t jvar=0; jvar<nvar; jvar++) {
294 (*fSumValMatx)(jvar+1,ivar ) += ev->
GetValue(jvar) * val;
310 Log() <<
kWARNING <<
"<GetCoeff> matrix is almost singular with determinant=" 312 <<
" did you use the variables that are linear combinations or highly correlated?" 316 Log() <<
kFATAL <<
"<GetCoeff> matrix is singular with determinant=" 318 <<
" did you use the variables that are linear combinations?" 324 for (
UInt_t jvar = 0; jvar<nvar+1; jvar++) {
325 (*(*fLDCoeff)[ivar])[jvar] = (*
fCoeffMatx)(jvar, ivar );
328 (*(*fLDCoeff)[ivar])[0]=0.0;
329 for (
UInt_t jvar = 1; jvar<nvar+1; jvar++){
332 (*(*fLDCoeff)[ivar])[0]/=-2.0;
345 istr >> (*(*fLDCoeff)[iout])[icoeff];
379 if (ncoeff !=
GetNvar()+1)
Log() <<
kFATAL <<
"Mismatch in number of output variables/coefficients: " 384 for (vector< vector< Double_t >* >::iterator vi=
fLDCoeff->begin(); vi!=
fLDCoeff->end(); vi++){
385 if (*vi) {
delete *vi; *vi = 0; }
390 for (
Int_t ivar = 0; ivar<fNRegOut; ivar++) (*fLDCoeff)[ivar] = new std::vector<Double_t>( ncoeff );
400 (*(*fLDCoeff)[iout])[icoeff] = coeff;
411 fout <<
" std::vector<double> fLDCoefficients;" << std::endl;
412 fout <<
"};" << std::endl;
413 fout <<
"" << std::endl;
414 fout <<
"inline void " << className <<
"::Initialize() " << std::endl;
415 fout <<
"{" << std::endl;
417 Int_t dp = fout.precision();
418 fout <<
" fLDCoefficients.push_back( " 419 << std::setprecision(12) << (*(*fLDCoeff)[0])[ivar]
420 << std::setprecision(dp) <<
" );" << std::endl;
423 fout <<
" // sanity check" << std::endl;
424 fout <<
" if (fLDCoefficients.size() != fNvars+1) {" << std::endl;
425 fout <<
" std::cout << \"Problem in class \\\"\" << fClassName << \"\\\"::Initialize: mismatch in number of input values\"" << std::endl;
426 fout <<
" << fLDCoefficients.size() << \" != \" << fNvars+1 << std::endl;" << std::endl;
427 fout <<
" fStatusIsClean = false;" << std::endl;
428 fout <<
" } " << std::endl;
429 fout <<
"}" << std::endl;
431 fout <<
"inline double " << className <<
"::GetMvaValue__( const std::vector<double>& inputValues ) const" << std::endl;
432 fout <<
"{" << std::endl;
433 fout <<
" double retval = fLDCoefficients[0];" << std::endl;
434 fout <<
" for (size_t ivar = 1; ivar < fNvars+1; ivar++) {" << std::endl;
435 fout <<
" retval += fLDCoefficients[ivar]*inputValues[ivar-1];" << std::endl;
436 fout <<
" }" << std::endl;
438 fout <<
" return retval;" << std::endl;
439 fout <<
"}" << std::endl;
441 fout <<
"// Clean up" << std::endl;
442 fout <<
"inline void " << className <<
"::Clear() " << std::endl;
443 fout <<
"{" << std::endl;
444 fout <<
" // clear coefficients" << std::endl;
445 fout <<
" fLDCoefficients.clear(); " << std::endl;
446 fout <<
"}" << std::endl;
487 Log() <<
kINFO <<
"NOTE: The coefficients must be applied to TRANFORMED variables" <<
Endl;
488 Log() <<
kINFO <<
" List of the transformation: " <<
Endl;
494 std::vector<TString> vars;
495 std::vector<Double_t> coeffs;
498 coeffs.push_back( (* (*
fLDCoeff)[0])[ivar+1] );
500 vars .push_back(
"(offset)" );
501 coeffs.push_back((* (*
fLDCoeff)[0])[0] );
504 Log() <<
kINFO <<
"NOTE: You have chosen to use the \"Normalise\" booking option. Hence, the" <<
Endl;
505 Log() <<
kINFO <<
" coefficients must be applied to NORMALISED (') variables as follows:" <<
Endl;
514 << std::setw(3) << (
GetXmin(ivar) > 0 ?
" - " :
" + ")
517 << std::setw(3) <<
" - 1" 520 Log() <<
kINFO <<
"The TMVA Reader will properly account for this normalisation, but if the" <<
Endl;
521 Log() <<
kINFO <<
"LD classifier is applied outside the Reader, the transformation must be" <<
Endl;
522 Log() <<
kINFO <<
"implemented -- or the \"Normalise\" option is removed and LD retrained." <<
Endl;
538 Log() <<
"Linear discriminants select events by distinguishing the mean " <<
Endl;
539 Log() <<
"values of the signal and background distributions in a trans- " <<
Endl;
540 Log() <<
"formed variable space where linear correlations are removed." <<
Endl;
541 Log() <<
"The LD implementation here is equivalent to the \"Fisher\" discriminant" <<
Endl;
542 Log() <<
"for classification, but also provides linear regression." <<
Endl;
544 Log() <<
" (More precisely: the \"linear discriminator\" determines" <<
Endl;
545 Log() <<
" an axis in the (correlated) hyperspace of the input " <<
Endl;
546 Log() <<
" variables such that, when projecting the output classes " <<
Endl;
547 Log() <<
" (signal and background) upon this axis, they are pushed " <<
Endl;
548 Log() <<
" as far as possible away from each other, while events" <<
Endl;
549 Log() <<
" of a same class are confined in a close vicinity. The " <<
Endl;
550 Log() <<
" linearity property of this classifier is reflected in the " <<
Endl;
551 Log() <<
" metric with which \"far apart\" and \"close vicinity\" are " <<
Endl;
552 Log() <<
" determined: the covariance matrix of the discriminating" <<
Endl;
553 Log() <<
" variable space.)" <<
Endl;
557 Log() <<
"Optimal performance for the linear discriminant is obtained for " <<
Endl;
558 Log() <<
"linearly correlated Gaussian-distributed variables. Any deviation" <<
Endl;
559 Log() <<
"from this ideal reduces the achievable separation power. In " <<
Endl;
560 Log() <<
"particular, no discrimination at all is achieved for a variable" <<
Endl;
561 Log() <<
"that has the same sample mean for signal and background, even if " <<
Endl;
562 Log() <<
"the shapes of the distributions are very different. Thus, the linear " <<
Endl;
563 Log() <<
"discriminant often benefits from a suitable transformation of the " <<
Endl;
564 Log() <<
"input variables. For example, if a variable x in [-1,1] has a " <<
Endl;
565 Log() <<
"a parabolic signal distributions, and a uniform background" <<
Endl;
566 Log() <<
"distributions, their mean value is zero in both cases, leading " <<
Endl;
567 Log() <<
"to no separation. The simple transformation x -> |x| renders this " <<
Endl;
568 Log() <<
"variable powerful for the use in a linear discriminant." <<
Endl;
virtual const std::vector< Float_t > & GetRegressionValues()
Calculates the regression output.
UInt_t GetNVariables() const
const Ranking * CreateRanking()
computes ranking of input variables
MsgLogger & Endl(MsgLogger &ml)
std::vector< std::vector< Double_t > *> * fLDCoeff
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
LD can handle classification with 2 classes and regression with one regression-target.
void GetSumVal(void)
Calculates the vector transposed(X)*W*Y with Y being the target vector.
TransformationHandler & GetTransformationHandler(Bool_t takeReroutedIfAvailable=true)
UInt_t GetNTargets() const
virtual ~MethodLD(void)
destructor
void PrintCoefficients(void)
Display the classification/regression coefficients for each variable.
virtual Double_t Determinant() const
Return the matrix determinant.
const TString & GetInputLabel(Int_t i) const
void ReadWeightsFromXML(void *wghtnode)
read coefficients from xml weight file
Double_t GetMvaValue(Double_t *err=0, Double_t *errUpper=0)
Returns the MVA classification output.
const Event * GetEvent() const
Double_t GetXmin(Int_t ivar) const
DataSetInfo & DataInfo() const
Bool_t DoRegression() 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
void ReadWeightsFromStream(std::istream &i)
read LD coefficients from weight file
Float_t GetTarget(UInt_t itgt) const
UInt_t GetNTargets() const
Bool_t HasTrainingTree() const
const char * GetName() const
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
void DeclareOptions()
MethodLD options.
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
Bool_t IgnoreEventsWithNegWeightsInTraining() const
void MakeClassSpecific(std::ostream &, const TString &) const
write LD-specific classifier response
MethodLD(const TString &jobName, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="LD")
standard constructor for the LD
Bool_t IsNormalised() const
void AddPreDefVal(const T &)
void GetSum(void)
Calculates the matrix transposed(X)*W*X with W being the diagonal weight matrix and X the coordinates...
#define REGISTER_METHOD(CLASS)
for example
Abstract ClassifierFactory template that handles arbitrary types.
std::vector< Float_t > & GetValues()
void GetLDCoeff(void)
Calculates the coeffiecients used for classification/regression.
virtual void AddRank(const Rank &rank)
Add a new rank take ownership of it.
Long64_t GetNEvents(Types::ETreeType type=Types::kMaxTreeType) const
void Train(void)
compute fSumMatx
Bool_t IsSignal(const Event *ev) const
void InitMatrices(void)
Initializaton method; creates global matrices and vectors.
std::vector< Float_t > * fRegressionReturnVal
void GetHelpMessage() const
get help message text
void Init(void)
default initialization called by all constructors
void AddWeightsXMLTo(void *parent) const
create XML description for LD classification and regression (for arbitrary number of output classes/t...
void NoErrorCalc(Double_t *const err, Double_t *const errUpper)
void SetSignalReferenceCut(Double_t cut)
void ProcessOptions()
this is the preparation for training