File indexing completed on 2025-01-18 10:11:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifndef ROOT_TMVA_RuleFitParams
0034 #define ROOT_TMVA_RuleFitParams
0035
0036 #include "TMathBase.h"
0037
0038 #include "TMVA/Event.h"
0039
0040 #include <vector>
0041
0042 class TTree;
0043
0044 namespace TMVA {
0045
0046 class RuleEnsemble;
0047 class MsgLogger;
0048 class RuleFit;
0049 class RuleFitParams {
0050
0051 public:
0052
0053 RuleFitParams();
0054 virtual ~RuleFitParams();
0055
0056 void Init();
0057
0058
0059 void SetMsgType( EMsgType t );
0060
0061
0062 void SetRuleFit( RuleFit *rf ) { fRuleFit = rf; }
0063
0064
0065 void SetGDNPathSteps( Int_t np ) { fGDNPathSteps = np; }
0066
0067
0068 void SetGDPathStep( Double_t s ) { fGDPathStep = s; }
0069
0070
0071 void SetGDTauRange( Double_t t0, Double_t t1 )
0072 {
0073 fGDTauMin = (t0>1.0 ? 1.0:(t0<0.0 ? 0.0:t0));
0074 fGDTauMax = (t1>1.0 ? 1.0:(t1<0.0 ? 0.0:t1));
0075 if (fGDTauMax<fGDTauMin) fGDTauMax = fGDTauMin;
0076 }
0077
0078
0079 void SetGDTauScan( UInt_t n ) { fGDTauScan = n; }
0080
0081
0082 void SetGDTau( Double_t t ) { fGDTau = t; }
0083
0084
0085 void SetGDErrScale( Double_t s ) { fGDErrScale = s; }
0086 void SetGDTauPrec( Double_t p ) { fGDTauPrec=p; CalcGDNTau(); fGDTauVec.resize(fGDNTau); }
0087
0088
0089 Int_t Type( const Event * e ) const;
0090
0091 UInt_t GetPathIdx1() const { return fPathIdx1; }
0092 UInt_t GetPathIdx2() const { return fPathIdx2; }
0093 UInt_t GetPerfIdx1() const { return fPerfIdx1; }
0094 UInt_t GetPerfIdx2() const { return fPerfIdx2; }
0095
0096
0097 Double_t LossFunction( const Event& e ) const;
0098
0099
0100 Double_t LossFunction( UInt_t evtidx ) const;
0101 Double_t LossFunction( UInt_t evtidx, UInt_t itau ) const;
0102
0103
0104 Double_t Risk(UInt_t ind1, UInt_t ind2, Double_t neff) const;
0105 Double_t Risk(UInt_t ind1, UInt_t ind2, Double_t neff, UInt_t itau) const;
0106
0107
0108 Double_t RiskPath() const { return Risk(fPathIdx1,fPathIdx2,fNEveEffPath); }
0109 Double_t RiskPerf() const { return Risk(fPerfIdx1,fPerfIdx2,fNEveEffPerf); }
0110 Double_t RiskPerf( UInt_t itau ) const { return Risk(fPerfIdx1,fPerfIdx2,fNEveEffPerf,itau); }
0111
0112
0113 UInt_t RiskPerfTst();
0114
0115
0116 Double_t Penalty() const;
0117
0118
0119 void InitGD();
0120
0121
0122 Int_t FindGDTau();
0123
0124
0125 void MakeGDPath();
0126
0127 protected:
0128
0129
0130 typedef std::vector<const TMVA::Event *>::const_iterator EventItr;
0131
0132
0133 void InitNtuple();
0134
0135
0136 void CalcGDNTau() { fGDNTau = static_cast<UInt_t>(1.0/fGDTauPrec)+1; if (fGDNTau>100000) fGDNTau=100000; }
0137
0138
0139 void FillCoefficients();
0140
0141
0142 void CalcFStar();
0143
0144
0145 Double_t ErrorRateBin();
0146
0147
0148 Double_t ErrorRateReg();
0149
0150
0151 Double_t ErrorRateRocRaw( std::vector<Double_t> & sFsig, std::vector<Double_t> & sFbkg );
0152 Double_t ErrorRateRoc();
0153 void ErrorRateRocTst();
0154
0155
0156 Double_t Optimism();
0157
0158
0159 void MakeGradientVector();
0160
0161
0162 void UpdateCoefficients();
0163
0164
0165 Double_t CalcAverageResponse();
0166 Double_t CalcAverageResponseOLD();
0167
0168
0169 Double_t CalcAverageTruth();
0170
0171
0172 void EvaluateAverage(UInt_t ind1, UInt_t ind2,
0173 std::vector<Double_t> &avsel,
0174 std::vector<Double_t> &avrul);
0175
0176
0177 void EvaluateAveragePath() { EvaluateAverage( fPathIdx1, fPathIdx2, fAverageSelectorPath, fAverageRulePath ); }
0178
0179
0180 void EvaluateAveragePerf() { EvaluateAverage( fPerfIdx1, fPerfIdx2, fAverageSelectorPerf, fAverageRulePerf ); }
0181
0182
0183 void MakeTstGradientVector();
0184 void UpdateTstCoefficients();
0185 void CalcTstAverageResponse();
0186
0187
0188 RuleFit * fRuleFit;
0189 RuleEnsemble * fRuleEnsemble;
0190
0191 UInt_t fNRules;
0192 UInt_t fNLinear;
0193
0194
0195
0196
0197 UInt_t fPathIdx1;
0198 UInt_t fPathIdx2;
0199 UInt_t fPerfIdx1;
0200 UInt_t fPerfIdx2;
0201 Double_t fNEveEffPath;
0202 Double_t fNEveEffPerf;
0203
0204 std::vector<Double_t> fAverageSelectorPath;
0205 std::vector<Double_t> fAverageRulePath;
0206 std::vector<Double_t> fAverageSelectorPerf;
0207 std::vector<Double_t> fAverageRulePerf;
0208
0209 std::vector<Double_t> fGradVec;
0210 std::vector<Double_t> fGradVecLin;
0211
0212 std::vector< std::vector<Double_t> > fGradVecTst;
0213 std::vector< std::vector<Double_t> > fGradVecLinTst;
0214
0215 std::vector<Double_t> fGDErrTst;
0216 std::vector<Char_t> fGDErrTstOK;
0217 std::vector< std::vector<Double_t> > fGDCoefTst;
0218 std::vector< std::vector<Double_t> > fGDCoefLinTst;
0219 std::vector<Double_t> fGDOfsTst;
0220 std::vector< Double_t > fGDTauVec;
0221 UInt_t fGDNTauTstOK;
0222 UInt_t fGDNTau;
0223 Double_t fGDTauPrec;
0224 UInt_t fGDTauScan;
0225 Double_t fGDTauMin;
0226 Double_t fGDTauMax;
0227 Double_t fGDTau;
0228 Double_t fGDPathStep;
0229 Int_t fGDNPathSteps;
0230 Double_t fGDErrScale;
0231
0232 Double_t fAverageTruth;
0233
0234 std::vector<Double_t> fFstar;
0235 Double_t fFstarMedian;
0236
0237 TTree *fGDNtuple;
0238 Double_t fNTRisk;
0239 Double_t fNTErrorRate;
0240 Double_t fNTNuval;
0241 Double_t fNTCoefRad;
0242 Double_t fNTOffset;
0243 Double_t *fNTCoeff;
0244 Double_t *fNTLinCoeff;
0245
0246 Double_t fsigave;
0247 Double_t fsigrms;
0248 Double_t fbkgave;
0249 Double_t fbkgrms;
0250
0251 private:
0252
0253 mutable MsgLogger* fLogger;
0254 MsgLogger& Log() const { return *fLogger; }
0255
0256 };
0257
0258
0259
0260 class AbsValue {
0261
0262 public:
0263
0264 Bool_t operator()( Double_t first, Double_t second ) const { return TMath::Abs(first) < TMath::Abs(second); }
0265 };
0266 }
0267
0268
0269 #endif