26#ifndef ROOT_TMVA_NodekNN
27#define ROOT_TMVA_NodekNN
95 void Print(std::ostream& os,
const std::string &
offset =
"")
const;
183 return fEvent.GetWeight();
230 fVarDis(event.GetVar(mod)),
240 if (fNodeL)
delete fNodeL;
241 if (fNodeR)
delete fNodeR;
253 assert(fMod == depth % event.GetNVar() &&
"Wrong recursive depth in Node<>::Add");
257 fVarMin = std::min(fVarMin,
value);
258 fVarMax = std::max(fVarMax,
value);
261 if (
value < fVarDis) {
264 return fNodeL->
Add(event, depth + 1);
267 fNodeL =
new Node<T>(
this, event, (depth + 1) % event.GetNVar());
273 return fNodeR->
Add(event, depth + 1);
276 fNodeR =
new Node<T>(
this, event, (depth + 1) % event.GetNVar());
295 os <<
offset <<
"-----------------------------------------------------------" << std::endl;
296 os <<
offset <<
"Node: mod " << fMod
298 <<
" with weight: " << GetWeight() << std::endl
302 os <<
offset <<
"Has left node " << std::endl;
305 os <<
offset <<
"Has right node" << std::endl;
309 os <<
offset <<
"PrInt_t left node " << std::endl;
310 fNodeL->Print(os,
offset +
" ");
313 os <<
offset <<
"PrInt_t right node" << std::endl;
314 fNodeR->Print(os,
offset +
" ");
317 if (!fNodeL && !fNodeR) {
336 if (!node || nfind < 1) {
346 if (!nlist.empty()) {
348 max_dist = nlist.back().second;
350 if (nlist.size() == nfind) {
355 if (value < node->GetVarMin() &&
367 if (nlist.size() < nfind) {
370 else if (nlist.size() == nfind) {
371 if (distance < max_dist) {
377 std::cerr <<
"TMVA::kNN::Find() - logic error in recursive procedure" << std::endl;
384 typename std::list<std::pair<const Node<T> *,
Float_t> >::iterator lit = nlist.begin();
387 for (; lit != nlist.end(); ++lit) {
388 if (distance < lit->second) {
396 nlist.insert(lit, std::pair<
const Node<T> *,
Float_t>(node, distance));
406 if (value < node->GetVarDis()) {
445 if (!node || !(nfind < 0.0)) {
455 if (!nlist.empty()) {
457 max_dist = nlist.back().second;
459 if (!(ncurr < nfind)) {
464 if (value < node->GetVarMin() &&
478 else if (!nlist.empty()) {
479 if (distance < max_dist) {
484 std::cerr <<
"TMVA::kNN::Find() - logic error in recursive procedure" << std::endl;
494 typename std::list<std::pair<const Node<T> *,
Float_t> >::iterator lit = nlist.begin();
497 for (; lit != nlist.end(); ++lit) {
498 if (distance < lit->second) {
502 ncurr += lit -> first -> GetWeight();
505 lit = nlist.insert(lit, std::pair<
const Node<T> *,
Float_t>(node, distance));
507 for (; lit != nlist.end(); ++lit) {
508 ncurr += lit -> first -> GetWeight();
509 if (!(ncurr < nfind)) {
515 if(lit != nlist.end())
517 nlist.erase(lit, nlist.end());
524 if (value < node->GetVarDis()) {
525 count +=
Find(nlist, node->
GetNodeL(), event, nfind, ncurr);
526 count +=
Find(nlist, node->
GetNodeR(), event, nfind, ncurr);
529 count +=
Find(nlist, node->
GetNodeR(), event, nfind, ncurr);
530 count +=
Find(nlist, node->
GetNodeL(), event, nfind, ncurr);
535 count +=
Find(nlist, node->
GetNodeL(), event, nfind, ncurr);
538 count +=
Find(nlist, node->
GetNodeR(), event, nfind, ncurr);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
void Print(GNN_Data &d, std::string txt="")
This file contains binary tree and global function template that searches tree for k-nearest neigbors...
Float_t GetVarMin() const
void SetNodeL(Node *node)
void SetNodeR(Node *node)
Double_t GetWeight() const
Float_t GetVarDis() const
Float_t GetVarMax() const
void Print(std::ostream &os, const std::string &offset="") const
const Node * GetNodeL() const
Node(const Node *parent, const T &event, Int_t mod)
const Node * GetNodeP() const
const Node & operator=(const Node &)
const Node * GetNodeR() const
const Node * Add(const T &event, UInt_t depth)
This is Node member function that adds a new node to a binary tree.
const T & GetEvent() const
kNN::Event describes point in input variable vector-space, with additional functionality like distanc...
UInt_t Find(std::list< std::pair< const Node< T > *, Float_t > > &nlist, const Node< T > *node, const T &event, UInt_t nfind)
UInt_t Depth(const Node< T > *node)
create variable transformations