00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef ROOT_TMVA_RuleFitParams
00034 #define ROOT_TMVA_RuleFitParams
00035
00036 #if ROOT_VERSION_CODE >= 364802
00037 #ifndef ROOT_TMathBase
00038 #include "TMathBase.h"
00039 #endif
00040 #else
00041 #ifndef ROOT_TMath
00042 #include "TMath.h"
00043 #endif
00044 #endif
00045
00046 #ifndef ROOT_TMVA_Event
00047 #include "TMVA/Event.h"
00048 #endif
00049
00050 class TTree;
00051
00052 namespace TMVA {
00053
00054 class RuleEnsemble;
00055 class MsgLogger;
00056 class RuleFit;
00057 class RuleFitParams {
00058
00059 public:
00060
00061 RuleFitParams();
00062 virtual ~RuleFitParams();
00063
00064 void Init();
00065
00066
00067 void SetMsgType( EMsgType t );
00068
00069
00070 void SetRuleFit( RuleFit *rf ) { fRuleFit = rf; }
00071
00072
00073 void SetGDNPathSteps( Int_t np ) { fGDNPathSteps = np; }
00074
00075
00076 void SetGDPathStep( Double_t s ) { fGDPathStep = s; }
00077
00078
00079 void SetGDTauRange( Double_t t0, Double_t t1 )
00080 {
00081 fGDTauMin = (t0>1.0 ? 1.0:(t0<0.0 ? 0.0:t0));
00082 fGDTauMax = (t1>1.0 ? 1.0:(t1<0.0 ? 0.0:t1));
00083 if (fGDTauMax<fGDTauMin) fGDTauMax = fGDTauMin;
00084 }
00085
00086
00087 void SetGDTauScan( UInt_t n ) { fGDTauScan = n; }
00088
00089
00090 void SetGDTau( Double_t t ) { fGDTau = t; }
00091
00092
00093 void SetGDErrScale( Double_t s ) { fGDErrScale = s; }
00094 void SetGDTauPrec( Double_t p ) { fGDTauPrec=p; CalcGDNTau(); fGDTauVec.resize(fGDNTau); }
00095
00096
00097 Int_t Type( const Event * e ) const;
00098
00099 UInt_t GetPathIdx1() const { return fPathIdx1; }
00100 UInt_t GetPathIdx2() const { return fPathIdx2; }
00101 UInt_t GetPerfIdx1() const { return fPerfIdx1; }
00102 UInt_t GetPerfIdx2() const { return fPerfIdx2; }
00103
00104
00105 Double_t LossFunction( const Event& e ) const;
00106
00107
00108 Double_t LossFunction( UInt_t evtidx ) const;
00109 Double_t LossFunction( UInt_t evtidx, UInt_t itau ) const;
00110
00111
00112 Double_t Risk(UInt_t ind1, UInt_t ind2, Double_t neff) const;
00113 Double_t Risk(UInt_t ind1, UInt_t ind2, Double_t neff, UInt_t itau) const;
00114
00115
00116 Double_t RiskPath() const { return Risk(fPathIdx1,fPathIdx2,fNEveEffPath); }
00117 Double_t RiskPerf() const { return Risk(fPerfIdx1,fPerfIdx2,fNEveEffPerf); }
00118 Double_t RiskPerf( UInt_t itau ) const { return Risk(fPerfIdx1,fPerfIdx2,fNEveEffPerf,itau); }
00119
00120
00121 UInt_t RiskPerfTst();
00122
00123
00124 Double_t Penalty() const;
00125
00126
00127 void InitGD();
00128
00129
00130 Int_t FindGDTau();
00131
00132
00133 void MakeGDPath();
00134
00135 protected:
00136
00137
00138 typedef std::vector<TMVA::Event *>::const_iterator EventItr;
00139
00140
00141 void InitNtuple();
00142
00143
00144 void CalcGDNTau() { fGDNTau = static_cast<UInt_t>(1.0/fGDTauPrec)+1; if (fGDNTau>100000) fGDNTau=100000; }
00145
00146
00147 void FillCoefficients();
00148
00149
00150 void CalcFStar();
00151
00152
00153 Double_t ErrorRateBin();
00154
00155
00156 Double_t ErrorRateReg();
00157
00158
00159 Double_t ErrorRateRocRaw( std::vector<Double_t> & sFsig, std::vector<Double_t> & sFbkg );
00160 Double_t ErrorRateRoc();
00161 void ErrorRateRocTst();
00162
00163
00164 Double_t Optimism();
00165
00166
00167 void MakeGradientVector();
00168
00169
00170 void UpdateCoefficients();
00171
00172
00173 Double_t CalcAverageResponse();
00174 Double_t CalcAverageResponseOLD();
00175
00176
00177 Double_t CalcAverageTruth();
00178
00179
00180 void EvaluateAverage(UInt_t ind1, UInt_t ind2,
00181 std::vector<Double_t> &avsel,
00182 std::vector<Double_t> &avrul);
00183
00184
00185 void EvaluateAveragePath() { EvaluateAverage( fPathIdx1, fPathIdx2, fAverageSelectorPath, fAverageRulePath ); }
00186
00187
00188 void EvaluateAveragePerf() { EvaluateAverage( fPerfIdx1, fPerfIdx2, fAverageSelectorPerf, fAverageRulePerf ); }
00189
00190
00191 void MakeTstGradientVector();
00192 void UpdateTstCoefficients();
00193 void CalcTstAverageResponse();
00194
00195
00196 RuleFit * fRuleFit;
00197 RuleEnsemble * fRuleEnsemble;
00198
00199 UInt_t fNRules;
00200 UInt_t fNLinear;
00201
00202
00203
00204
00205 UInt_t fPathIdx1;
00206 UInt_t fPathIdx2;
00207 UInt_t fPerfIdx1;
00208 UInt_t fPerfIdx2;
00209 Double_t fNEveEffPath;
00210 Double_t fNEveEffPerf;
00211
00212 std::vector<Double_t> fAverageSelectorPath;
00213 std::vector<Double_t> fAverageRulePath;
00214 std::vector<Double_t> fAverageSelectorPerf;
00215 std::vector<Double_t> fAverageRulePerf;
00216
00217 std::vector<Double_t> fGradVec;
00218 std::vector<Double_t> fGradVecLin;
00219
00220 std::vector< std::vector<Double_t> > fGradVecTst;
00221 std::vector< std::vector<Double_t> > fGradVecLinTst;
00222
00223 std::vector<Double_t> fGDErrTst;
00224 std::vector<Char_t> fGDErrTstOK;
00225 std::vector< std::vector<Double_t> > fGDCoefTst;
00226 std::vector< std::vector<Double_t> > fGDCoefLinTst;
00227 std::vector<Double_t> fGDOfsTst;
00228 std::vector< Double_t > fGDTauVec;
00229 UInt_t fGDNTauTstOK;
00230 UInt_t fGDNTau;
00231 Double_t fGDTauPrec;
00232 UInt_t fGDTauScan;
00233 Double_t fGDTauMin;
00234 Double_t fGDTauMax;
00235 Double_t fGDTau;
00236 Double_t fGDPathStep;
00237 Int_t fGDNPathSteps;
00238 Double_t fGDErrScale;
00239
00240 Double_t fAverageTruth;
00241
00242 std::vector<Double_t> fFstar;
00243 Double_t fFstarMedian;
00244
00245 TTree *fGDNtuple;
00246 Double_t fNTRisk;
00247 Double_t fNTErrorRate;
00248 Double_t fNTNuval;
00249 Double_t fNTCoefRad;
00250 Double_t fNTOffset;
00251 Double_t *fNTCoeff;
00252 Double_t *fNTLinCoeff;
00253
00254 Double_t fsigave;
00255 Double_t fsigrms;
00256 Double_t fbkgave;
00257 Double_t fbkgrms;
00258
00259 private:
00260
00261 mutable MsgLogger* fLogger;
00262 MsgLogger& Log() const { return *fLogger; }
00263
00264 };
00265
00266
00267
00268 class AbsValue {
00269
00270 public:
00271
00272 Bool_t operator()( Double_t first, Double_t second ) const { return TMath::Abs(first) < TMath::Abs(second); }
00273 };
00274 }
00275
00276
00277 #endif