26 #ifndef ROOT_TMVA_NodekNN
27 #define ROOT_TMVA_NodekNN
98 void Print(std::ostream& os,
const std::string &offset =
"")
const;
186 return fEvent.GetWeight();
233 fVarDis(event.GetVar(mod)),
243 if (fNodeL)
delete fNodeL;
244 if (fNodeR)
delete fNodeR;
255 assert(fMod == depth % event.GetNVar() &&
"Wrong recursive depth in Node<>::Add");
257 const Float_t value =
event.GetVar(fMod);
263 if (value < fVarDis) {
266 return fNodeL->
Add(event, depth + 1);
269 fNodeL =
new Node<T>(
this, event, (depth + 1) % event.GetNVar());
275 return fNodeR->
Add(event, depth + 1);
278 fNodeR =
new Node<T>(
this, event, (depth + 1) % event.GetNVar());
297 os << offset <<
"-----------------------------------------------------------" << std::endl;
298 os << offset <<
"Node: mod " << fMod
300 <<
" with weight: " <<
GetWeight() << std::endl
304 os << offset <<
"Has left node " << std::endl;
307 os << offset <<
"Has right node" << std::endl;
311 os << offset <<
"PrInt_t left node " << std::endl;
312 fNodeL->Print(os, offset +
" ");
315 os << offset <<
"PrInt_t right node" << std::endl;
316 fNodeR->Print(os, offset +
" ");
319 if (!fNodeL && !fNodeR) {
339 if (!node || nfind < 1) {
349 if (!nlist.empty()) {
351 max_dist = nlist.back().second;
353 if (nlist.size() == nfind) {
358 if (value < node->GetVarMin() &&
370 if (nlist.size() < nfind) {
373 else if (nlist.size() == nfind) {
374 if (distance < max_dist) {
380 std::cerr <<
"TMVA::kNN::Find() - logic error in recursive procedure" << std::endl;
387 typename std::list<std::pair<const Node<T> *,
Float_t> >::iterator lit = nlist.begin();
390 for (; lit != nlist.end(); ++lit) {
391 if (distance < lit->second) {
399 nlist.insert(lit, std::pair<
const Node<T> *,
Float_t>(node, distance));
409 if (value < node->GetVarDis()) {
449 if (!node || !(nfind < 0.0)) {
459 if (!nlist.empty()) {
461 max_dist = nlist.back().second;
463 if (!(ncurr < nfind)) {
468 if (value < node->GetVarMin() &&
482 else if (!nlist.empty()) {
483 if (distance < max_dist) {
488 std::cerr <<
"TMVA::kNN::Find() - logic error in recursive procedure" << std::endl;
498 typename std::list<std::pair<const Node<T> *,
Float_t> >::iterator lit = nlist.begin();
501 for (; lit != nlist.end(); ++lit) {
502 if (distance < lit->second) {
509 lit = nlist.insert(lit, std::pair<
const Node<T> *,
Float_t>(node, distance));
511 for (; lit != nlist.end(); ++lit) {
513 if (!(ncurr < nfind)) {
519 if(lit != nlist.end())
521 nlist.erase(lit, nlist.end());
528 if (value < node->GetVarDis()) {
529 count +=
Find(nlist, node->
GetNodeL(), event, nfind, ncurr);
530 count +=
Find(nlist, node->
GetNodeR(), event, nfind, ncurr);
533 count +=
Find(nlist, node->
GetNodeR(), event, nfind, ncurr);
534 count +=
Find(nlist, node->
GetNodeL(), event, nfind, ncurr);
539 count +=
Find(nlist, node->
GetNodeL(), event, nfind, ncurr);
542 count +=
Find(nlist, node->
GetNodeR(), event, nfind, ncurr);
const Node * GetNodeR() const
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
const Node * Add(const T &event, UInt_t depth)
UInt_t Depth(const Node< T > *node)
const Node & operator=(const Node &)
Float_t GetVarMin() const
void SetNodeL(Node *node)
Double_t GetWeight(Double_t x) const
const Node * GetNodeP() const
void Print(std::ostream &os, const OptionType &opt)
const Node * GetNodeL() const
Float_t GetVarMax() const
Double_t GetWeight() const
const T & GetEvent() const
UInt_t Find(std::list< std::pair< const Node< T > *, Float_t > > &nlist, const Node< T > *node, const T &event, UInt_t nfind)
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Abstract ClassifierFactory template that handles arbitrary types.
void SetNodeR(Node *node)
Float_t GetVarDis() const