26 #ifndef ROOT_TMVA_ModulekNN
27 #define ROOT_TMVA_ModulekNN
56 typedef Float_t VarType;
57 typedef std::vector<VarType> VarVec;
63 Event(
const VarVec &vec, Double_t weight, Short_t type);
64 Event(
const VarVec &vec, Double_t weight, Short_t type,
const VarVec &tvec);
67 Double_t GetWeight()
const;
69 VarType GetVar(UInt_t i)
const;
70 VarType GetTgt(UInt_t i)
const;
72 UInt_t GetNVar()
const;
73 UInt_t GetNTgt()
const;
75 Short_t GetType()
const;
78 VarType GetDist(VarType var, UInt_t ivar)
const;
79 VarType GetDist(
const Event &other)
const;
81 void SetTargets(
const VarVec &tvec);
82 const VarVec& GetTargets()
const;
83 const VarVec& GetVars()
const;
86 void Print(std::ostream& os)
const;
97 typedef std::vector<TMVA::kNN::Event> EventVec;
98 typedef std::pair<const Node<Event> *, VarType> Elem;
99 typedef std::list<Elem> List;
101 std::ostream& operator<<(std::ostream& os,
const Event& event);
107 typedef std::map<int, std::vector<Double_t> > VarMap;
116 void Add(
const Event &event);
118 Bool_t Fill(
const UShort_t odepth, UInt_t ifrac,
const std::string &option =
"");
120 Bool_t Find(Event event, UInt_t nfind = 100,
const std::string &option =
"count")
const;
121 Bool_t Find(UInt_t nfind,
const std::string &option)
const;
123 const EventVec& GetEventVec()
const;
125 const List& GetkNNList()
const;
126 const Event& GetkNNEvent()
const;
128 const VarMap& GetVarMap()
const;
130 const std::map<Int_t, Double_t>& GetMetric()
const;
133 void Print(std::ostream &os)
const;
137 Node<Event>* Optimize(UInt_t optimize_depth);
139 void ComputeMetric(UInt_t ifrac);
141 const Event Scale(
const Event &event)
const;
147 static TRandom3& GetRndmThreadLocal() {TTHREAD_TLS_DECL_ARG(TRandom3,fgRndm,1);
return fgRndm;};
153 std::map<Int_t, Double_t> fVarScale;
155 mutable List fkNNList;
156 mutable Event fkNNEvent;
158 std::map<Short_t, UInt_t> fCount;
163 mutable MsgLogger* fLogger;
164 MsgLogger& Log()
const {
return *fLogger; }
170 inline VarType Event::GetDist(
const VarType var1,
const UInt_t ivar)
const
172 const VarType var2 = GetVar(ivar);
173 return (var1 - var2) * (var1 - var2);
175 inline Double_t Event::GetWeight()
const
179 inline VarType Event::GetVar(
const UInt_t i)
const
183 inline VarType Event::GetTgt(
const UInt_t i)
const
188 inline UInt_t Event::GetNVar()
const
192 inline UInt_t Event::GetNTgt()
const
196 inline Short_t Event::GetType()
const
204 inline const List& ModulekNN::GetkNNList()
const
208 inline const Event& ModulekNN::GetkNNEvent()
const
212 inline const EventVec& ModulekNN::GetEventVec()
const
216 inline const ModulekNN::VarMap& ModulekNN::GetVarMap()
const
220 inline const std::map<Int_t, Double_t>& ModulekNN::GetMetric()
const