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 #ifndef ROOT_TMVA_MethodKNN
00027 #define ROOT_TMVA_MethodKNN
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <vector>
00038 #include <map>
00039
00040
00041 #ifndef ROOT_TMVA_MethodBase
00042 #include "TMVA/MethodBase.h"
00043 #endif
00044 #ifndef ROOT_TMVA_ModulekNN
00045 #include "TMVA/ModulekNN.h"
00046 #endif
00047
00048
00049 #ifndef ROOT_TMVA_LDA
00050 #include "TMVA/LDA.h"
00051 #endif
00052
00053 namespace TMVA
00054 {
00055 namespace kNN
00056 {
00057 class ModulekNN;
00058 }
00059
00060 class MethodKNN : public MethodBase
00061 {
00062 public:
00063
00064 MethodKNN(const TString& jobName,
00065 const TString& methodTitle,
00066 DataSetInfo& theData,
00067 const TString& theOption = "KNN",
00068 TDirectory* theTargetDir = NULL);
00069
00070 MethodKNN(DataSetInfo& theData,
00071 const TString& theWeightFile,
00072 TDirectory* theTargetDir = NULL);
00073
00074 virtual ~MethodKNN( void );
00075
00076 virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
00077
00078 void Train( void );
00079
00080 Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
00081 const std::vector<Float_t>& GetRegressionValues();
00082
00083 using MethodBase::ReadWeightsFromStream;
00084
00085 void WriteWeightsToStream(TFile& rf) const;
00086 void AddWeightsXMLTo( void* parent ) const;
00087 void ReadWeightsFromXML( void* wghtnode );
00088
00089 void ReadWeightsFromStream(std::istream& istr);
00090 void ReadWeightsFromStream(TFile &rf);
00091
00092 const Ranking* CreateRanking();
00093
00094 protected:
00095
00096
00097 void MakeClassSpecific( std::ostream&, const TString& ) const;
00098
00099
00100 void GetHelpMessage() const;
00101
00102 private:
00103
00104
00105 void DeclareOptions();
00106 void ProcessOptions();
00107 void DeclareCompatibilityOptions();
00108
00109
00110 void Init( void );
00111
00112
00113 void MakeKNN( void );
00114
00115
00116 Double_t PolnKernel(Double_t value) const;
00117 Double_t GausKernel(const kNN::Event &event_knn, const kNN::Event &event, const std::vector<Double_t> &svec) const;
00118
00119 Double_t getKernelRadius(const kNN::List &rlist) const;
00120 const std::vector<Double_t> getRMS(const kNN::List &rlist, const kNN::Event &event_knn) const;
00121
00122 double getLDAValue(const kNN::List &rlist, const kNN::Event &event_knn);
00123
00124 private:
00125
00126
00127 Double_t fSumOfWeightsS;
00128 Double_t fSumOfWeightsB;
00129
00130 kNN::ModulekNN *fModule;
00131
00132 Int_t fnkNN;
00133 Int_t fBalanceDepth;
00134
00135 Float_t fScaleFrac;
00136 Float_t fSigmaFact;
00137
00138 TString fKernel;
00139
00140 Bool_t fTrim;
00141 Bool_t fUseKernel;
00142 Bool_t fUseWeight;
00143 Bool_t fUseLDA;
00144
00145 kNN::EventVec fEvent;
00146
00147 LDA fLDA;
00148
00149
00150 Int_t fTreeOptDepth;
00151
00152 ClassDef(MethodKNN,0)
00153 };
00154
00155 }
00156
00157 #endif // MethodKNN