ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ModulekNN.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Rustem Ospanov
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : ModulekNN *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation *
12  * *
13  * Author: *
14  * Rustem Ospanov <rustem@fnal.gov> - U. of Texas at Austin, USA *
15  * *
16  * Copyright (c) 2007: *
17  * CERN, Switzerland *
18  * MPI-K Heidelberg, Germany *
19  * U. of Texas at Austin, USA *
20  * *
21  * Redistribution and use in source and binary forms, with or without *
22  * modification, are permitted according to the terms listed in LICENSE *
23  * (http://tmva.sourceforge.net/LICENSE) *
24  **********************************************************************************/
25 
26 #include "TMVA/ModulekNN.h"
27 
28 // C++
29 #include <assert.h>
30 #include <iomanip>
31 #include <iostream>
32 #include <sstream>
33 #include <algorithm>
34 
35 #include "TMath.h"
36 #include "TRandom3.h"
37 
38 // TMVA
39 #include "TMVA/MsgLogger.h"
40 #include "TMVA/Types.h"
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// default constructor
44 
46  :fVar(),
47  fWeight(-1.0),
48  fType(-1)
49 {
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// constructor
54 
55 TMVA::kNN::Event::Event(const VarVec &var, const Double_t weight, const Short_t type)
56  :fVar(var),
57  fWeight(weight),
58  fType(type)
59 {
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// constructor
64 
65 TMVA::kNN::Event::Event(const VarVec &var, const Double_t weight, const Short_t type, const VarVec &tvec)
66  :fVar(var),
67  fTgt(tvec),
68  fWeight(weight),
69  fType(type)
70 {
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// destructor
75 
77 {
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// compute distance
82 
84 {
85  const UInt_t nvar = GetNVar();
86 
87  if (nvar != other.GetNVar()) {
88  std::cerr << "Distance: two events have different dimensions" << std::endl;
89  return -1.0;
90  }
91 
92  VarType sum = 0.0;
93  for (UInt_t ivar = 0; ivar < nvar; ++ivar) {
94  sum += GetDist(other.GetVar(ivar), ivar);
95  }
96 
97  return sum;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 
103 {
104  fTgt = tvec;
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 
110 {
111  return fTgt;
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 
117 {
118  return fVar;
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// print
123 
125 {
126  Print(std::cout);
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// print
131 
132 void TMVA::kNN::Event::Print(std::ostream& os) const
133 {
134  Int_t dp = os.precision();
135  os << "Event: ";
136  for (UInt_t ivar = 0; ivar != GetNVar(); ++ivar) {
137  if (ivar == 0) {
138  os << "(";
139  }
140  else {
141  os << ", ";
142  }
143 
144  os << std::setfill(' ') << std::setw(5) << std::setprecision(3) << GetVar(ivar);
145  }
146 
147  if (GetNVar() > 0) {
148  os << ")";
149  }
150  else {
151  os << " no variables";
152  }
153  os << std::setprecision(dp);
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// streamer
158 
159 std::ostream& TMVA::kNN::operator<<(std::ostream& os, const TMVA::kNN::Event& event)
160 {
161  event.Print(os);
162  return os;
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// default constructor
167 
169  :fDimn(0),
170  fTree(0),
171  fLogger( new MsgLogger("ModulekNN") )
172 {
173 }
174 
175 ////////////////////////////////////////////////////////////////////////////////
176 /// destructor
177 
179 {
180  if (fTree) {
181  delete fTree; fTree = 0;
182  }
183  delete fLogger;
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// clean up
188 
190 {
191  fDimn = 0;
192 
193  if (fTree) {
194  delete fTree;
195  fTree = 0;
196  }
197 
198  fVarScale.clear();
199  fCount.clear();
200  fEvent.clear();
201  fVar.clear();
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// add an event to tree
206 
208 {
209  if (fTree) {
210  Log() << kFATAL << "<Add> Cannot add event: tree is already built" << Endl;
211  return;
212  }
213 
214  if (fDimn < 1) {
215  fDimn = event.GetNVar();
216  }
217  else if (fDimn != event.GetNVar()) {
218  Log() << kFATAL << "ModulekNN::Add() - number of dimension does not match previous events" << Endl;
219  return;
220  }
221 
222  fEvent.push_back(event);
223 
224  for (UInt_t ivar = 0; ivar < fDimn; ++ivar) {
225  fVar[ivar].push_back(event.GetVar(ivar));
226  }
227 
228  std::map<Short_t, UInt_t>::iterator cit = fCount.find(event.GetType());
229  if (cit == fCount.end()) {
230  fCount[event.GetType()] = 1;
231  }
232  else {
233  ++(cit->second);
234  }
235 }
236 
237 ////////////////////////////////////////////////////////////////////////////////
238 /// fill the tree
239 
240 Bool_t TMVA::kNN::ModulekNN::Fill(const UShort_t odepth, const UInt_t ifrac, const std::string &option)
241 {
242  if (fTree) {
243  Log() << kFATAL << "ModulekNN::Fill - tree has already been created" << Endl;
244  return kFALSE;
245  }
246 
247  // If trim option is set then find class with lowest number of events
248  // and set that as maximum number of events for all other classes.
249  UInt_t min = 0;
250  if (option.find("trim") != std::string::npos) {
251  for (std::map<Short_t, UInt_t>::const_iterator it = fCount.begin(); it != fCount.end(); ++it) {
252  if (min == 0 || min > it->second) {
253  min = it->second;
254  }
255  }
256 
257  Log() << kINFO << "<Fill> Will trim all event types to " << min << " events" << Endl;
258 
259  fCount.clear();
260  fVar.clear();
261 
262  EventVec evec;
263 
264  for (EventVec::const_iterator event = fEvent.begin(); event != fEvent.end(); ++event) {
265  std::map<Short_t, UInt_t>::iterator cit = fCount.find(event->GetType());
266  if (cit == fCount.end()) {
267  fCount[event->GetType()] = 1;
268  }
269  else if (cit->second < min) {
270  ++(cit->second);
271  }
272  else {
273  continue;
274  }
275 
276  for (UInt_t d = 0; d < fDimn; ++d) {
277  fVar[d].push_back(event->GetVar(d));
278  }
279 
280  evec.push_back(*event);
281  }
282 
283  Log() << kINFO << "<Fill> Erased " << fEvent.size() - evec.size() << " events" << Endl;
284 
285  fEvent = evec;
286  }
287 
288  // clear event count
289  fCount.clear();
290 
291  // sort each variable for all events - needs this before Optimize() and ComputeMetric()
292  for (VarMap::iterator it = fVar.begin(); it != fVar.end(); ++it) {
293  std::sort((it->second).begin(), (it->second).end());
294  }
295 
296  if (option.find("metric") != std::string::npos && ifrac > 0) {
297  ComputeMetric(ifrac);
298 
299  // sort again each variable for all events - needs this before Optimize()
300  // rescaling has changed variable values
301  for (VarMap::iterator it = fVar.begin(); it != fVar.end(); ++it) {
302  std::sort((it->second).begin(), (it->second).end());
303  }
304  }
305 
306  // If odepth > 0 then fill first odepth levels
307  // with empty nodes that split separating variable in half for
308  // all child nodes. If odepth = 0 then split variable 0
309  // at the median (in half) and return it as root node
310  fTree = Optimize(odepth);
311 
312  if (!fTree) {
313  Log() << kFATAL << "ModulekNN::Fill() - failed to create tree" << Endl;
314  return kFALSE;
315  }
316 
317  for (EventVec::const_iterator event = fEvent.begin(); event != fEvent.end(); ++event) {
318  fTree->Add(*event, 0);
319 
320  std::map<Short_t, UInt_t>::iterator cit = fCount.find(event->GetType());
321  if (cit == fCount.end()) {
322  fCount[event->GetType()] = 1;
323  }
324  else {
325  ++(cit->second);
326  }
327  }
328 
329  for (std::map<Short_t, UInt_t>::const_iterator it = fCount.begin(); it != fCount.end(); ++it) {
330  Log() << kINFO << "<Fill> Class " << it->first << " has " << std::setw(8)
331  << it->second << " events" << Endl;
332  }
333 
334  return kTRUE;
335 }
336 
337 ////////////////////////////////////////////////////////////////////////////////
338 /// find in tree
339 /// if tree has been filled then search for nfind closest events
340 /// if metic (fVarScale map) is computed then rescale event variables
341 /// using previsouly computed width of variable distribution
342 
343 Bool_t TMVA::kNN::ModulekNN::Find(Event event, const UInt_t nfind, const std::string &option) const
344 {
345  if (!fTree) {
346  Log() << kFATAL << "ModulekNN::Find() - tree has not been filled" << Endl;
347  return kFALSE;
348  }
349  if (fDimn != event.GetNVar()) {
350  Log() << kFATAL << "ModulekNN::Find() - number of dimension does not match training events" << Endl;
351  return kFALSE;
352  }
353  if (nfind < 1) {
354  Log() << kFATAL << "ModulekNN::Find() - requested 0 nearest neighbors" << Endl;
355  return kFALSE;
356  }
357 
358  // if variable widths are computed then rescale variable in this event
359  // to same widths as events in stored kd-tree
360  if (!fVarScale.empty()) {
361  event = Scale(event);
362  }
363 
364  // latest event for k-nearest neighbor search
365  fkNNEvent = event;
366  fkNNList.clear();
367 
368  if(option.find("weight") != std::string::npos)
369  {
370  // recursive kd-tree search for nfind-nearest neighbors
371  // use event weight to find all nearest events
372  // that have sum of weights >= nfind
373  kNN::Find<kNN::Event>(fkNNList, fTree, event, Double_t(nfind), 0.0);
374  }
375  else
376  {
377  // recursive kd-tree search for nfind-nearest neighbors
378  // count nodes and do not use event weight
379  kNN::Find<kNN::Event>(fkNNList, fTree, event, nfind);
380  }
381 
382  return kTRUE;
383 }
384 
385 ////////////////////////////////////////////////////////////////////////////////
386 /// find in tree
387 
388 Bool_t TMVA::kNN::ModulekNN::Find(const UInt_t nfind, const std::string &option) const
389 {
390  if (fCount.empty() || !fTree) {
391  return kFALSE;
392  }
393  typedef std::map<Short_t, UInt_t>::const_iterator const_iterator;
394  TTHREAD_TLS_DECL_ARG(const_iterator,cit,fCount.end());
395 
396  if (cit == fCount.end()) {
397  cit = fCount.begin();
398  }
399 
400  const Short_t etype = (cit++)->first;
401 
402  if (option == "flat") {
403  VarVec dvec;
404  for (UInt_t d = 0; d < fDimn; ++d) {
405  VarMap::const_iterator vit = fVar.find(d);
406  if (vit == fVar.end()) {
407  return kFALSE;
408  }
409 
410  const std::vector<Double_t> &vvec = vit->second;
411 
412  if (vvec.empty()) {
413  return kFALSE;
414  }
415 
416  // assume that vector elements of fVar are sorted
417  const VarType min = vvec.front();
418  const VarType max = vvec.back();
419  const VarType width = max - min;
420 
421  if (width < 0.0 || width > 0.0) {
422  dvec.push_back(min + width*GetRndmThreadLocal().Rndm());
423  }
424  else {
425  return kFALSE;
426  }
427  }
428 
429  const Event event(dvec, 1.0, etype);
430 
431  Find(event, nfind);
432 
433  return kTRUE;
434  }
435 
436  return kFALSE;
437 }
438 
439 ////////////////////////////////////////////////////////////////////////////////
440 /// Optimize() balances binary tree for first odepth levels
441 /// for each depth we split sorted depth % dimension variables
442 /// into 2^odepth parts
443 
445 {
446  if (fVar.empty() || fDimn != fVar.size()) {
447  Log() << kWARNING << "<Optimize> Cannot build a tree" << Endl;
448  return 0;
449  }
450 
451  const UInt_t size = (fVar.begin()->second).size();
452  if (size < 1) {
453  Log() << kWARNING << "<Optimize> Cannot build a tree without events" << Endl;
454  return 0;
455  }
456 
457  VarMap::const_iterator it = fVar.begin();
458  for (; it != fVar.end(); ++it) {
459  if ((it->second).size() != size) {
460  Log() << kWARNING << "<Optimize> # of variables doesn't match between dimensions" << Endl;
461  return 0;
462  }
463  }
464 
465  if (double(fDimn*size) < TMath::Power(2.0, double(odepth))) {
466  Log() << kWARNING << "<Optimize> Optimization depth exceeds number of events" << Endl;
467  return 0;
468  }
469 
470  Log() << kINFO << "Optimizing tree for " << fDimn << " variables with " << size << " values" << Endl;
471 
472  std::vector<Node<Event> *> pvec, cvec;
473 
474  it = fVar.find(0);
475  if (it == fVar.end() || (it->second).size() < 2) {
476  Log() << kWARNING << "<Optimize> Missing 0 variable" << Endl;
477  return 0;
478  }
479 
480  const Event pevent(VarVec(fDimn, (it->second)[size/2]), -1.0, -1);
481 
482  Node<Event> *tree = new Node<Event>(0, pevent, 0);
483 
484  pvec.push_back(tree);
485 
486  for (UInt_t depth = 1; depth < odepth; ++depth) {
487  const UInt_t mod = depth % fDimn;
488 
489  VarMap::const_iterator vit = fVar.find(mod);
490  if (vit == fVar.end()) {
491  Log() << kFATAL << "Missing " << mod << " variable" << Endl;
492  return 0;
493  }
494  const std::vector<Double_t> &dvec = vit->second;
495 
496  if (dvec.size() < 2) {
497  Log() << kFATAL << "Missing " << mod << " variable" << Endl;
498  return 0;
499  }
500 
501  UInt_t ichild = 1;
502  for (std::vector<Node<Event> *>::iterator pit = pvec.begin(); pit != pvec.end(); ++pit) {
503  Node<Event> *parent = *pit;
504 
505  const VarType lmedian = dvec[size*ichild/(2*pvec.size() + 1)];
506  ++ichild;
507 
508  const VarType rmedian = dvec[size*ichild/(2*pvec.size() + 1)];
509  ++ichild;
510 
511  const Event levent(VarVec(fDimn, lmedian), -1.0, -1);
512  const Event revent(VarVec(fDimn, rmedian), -1.0, -1);
513 
514  Node<Event> *lchild = new Node<Event>(parent, levent, mod);
515  Node<Event> *rchild = new Node<Event>(parent, revent, mod);
516 
517  parent->SetNodeL(lchild);
518  parent->SetNodeR(rchild);
519 
520  cvec.push_back(lchild);
521  cvec.push_back(rchild);
522  }
523 
524  pvec = cvec;
525  cvec.clear();
526  }
527 
528  return tree;
529 }
530 
531 ////////////////////////////////////////////////////////////////////////////////
532 /// compute scale factor for each variable (dimension) so that
533 /// distance is computed uniformely along each dimension
534 /// compute width of interval that includes (100 - 2*ifrac)% of events
535 /// below, assume that in fVar each vector of values is sorted
536 
538 {
539  if (ifrac == 0) {
540  return;
541  }
542  if (ifrac > 100) {
543  Log() << kFATAL << "ModulekNN::ComputeMetric - fraction can not exceed 100%" << Endl;
544  return;
545  }
546  if (!fVarScale.empty()) {
547  Log() << kFATAL << "ModulekNN::ComputeMetric - metric is already computed" << Endl;
548  return;
549  }
550  if (fEvent.size() < 100) {
551  Log() << kFATAL << "ModulekNN::ComputeMetric - number of events is too small" << Endl;
552  return;
553  }
554 
555  const UInt_t lfrac = (100 - ifrac)/2;
556  const UInt_t rfrac = 100 - (100 - ifrac)/2;
557 
558  Log() << kINFO << "Computing scale factor for 1d distributions: "
559  << "(ifrac, bottom, top) = (" << ifrac << "%, " << lfrac << "%, " << rfrac << "%)" << Endl;
560 
561  fVarScale.clear();
562 
563  for (VarMap::const_iterator vit = fVar.begin(); vit != fVar.end(); ++vit) {
564  const std::vector<Double_t> &dvec = vit->second;
565 
566  std::vector<Double_t>::const_iterator beg_it = dvec.end();
567  std::vector<Double_t>::const_iterator end_it = dvec.end();
568 
569  Int_t dist = 0;
570  for (std::vector<Double_t>::const_iterator dit = dvec.begin(); dit != dvec.end(); ++dit, ++dist) {
571 
572  if ((100*dist)/dvec.size() == lfrac && beg_it == dvec.end()) {
573  beg_it = dit;
574  }
575 
576  if ((100*dist)/dvec.size() == rfrac && end_it == dvec.end()) {
577  end_it = dit;
578  }
579  }
580 
581  if (beg_it == dvec.end() || end_it == dvec.end()) {
582  beg_it = dvec.begin();
583  end_it = dvec.end();
584 
585  assert(beg_it != end_it && "Empty vector");
586 
587  --end_it;
588  }
589 
590  const Double_t lpos = *beg_it;
591  const Double_t rpos = *end_it;
592 
593  if (!(lpos < rpos)) {
594  Log() << kFATAL << "ModulekNN::ComputeMetric() - min value is greater than max value" << Endl;
595  continue;
596  }
597 
598  // Rustem: please find a solution that does not use distance (it does not exist on solaris)
599  // Log() << kINFO << "Variable " << vit->first
600  // << " included " << distance(beg_it, end_it) + 1
601  // << " events: width = " << std::setfill(' ') << std::setw(5) << std::setprecision(3) << rpos - lpos
602  // << ", (min, max) = (" << std::setfill(' ') << std::setw(5) << std::setprecision(3) << lpos
603  // << ", " << std::setfill(' ') << std::setw(5) << std::setprecision(3) << rpos << ")" << Endl;
604 
605  fVarScale[vit->first] = rpos - lpos;
606  }
607 
608  fVar.clear();
609 
610  for (UInt_t ievent = 0; ievent < fEvent.size(); ++ievent) {
611  fEvent[ievent] = Scale(fEvent[ievent]);
612 
613  for (UInt_t ivar = 0; ivar < fDimn; ++ivar) {
614  fVar[ivar].push_back(fEvent[ievent].GetVar(ivar));
615  }
616  }
617 }
618 
619 ////////////////////////////////////////////////////////////////////////////////
620 /// scale each event variable so that rms of variables is approximately 1.0
621 /// this allows comparisons of variables with distinct scales and units
622 
624 {
625  if (fVarScale.empty()) {
626  return event;
627  }
628 
629  if (event.GetNVar() != fVarScale.size()) {
630  Log() << kFATAL << "ModulekNN::Scale() - mismatched metric and event size" << Endl;
631  return event;
632  }
633 
634  VarVec vvec(event.GetNVar(), 0.0);
635 
636  for (UInt_t ivar = 0; ivar < event.GetNVar(); ++ivar) {
637  std::map<int, Double_t>::const_iterator fit = fVarScale.find(ivar);
638  if (fit == fVarScale.end()) {
639  Log() << kFATAL << "ModulekNN::Scale() - failed to find scale for " << ivar << Endl;
640  continue;
641  }
642 
643  if (fit->second > 0.0) {
644  vvec[ivar] = event.GetVar(ivar)/fit->second;
645  }
646  else {
647  Log() << kFATAL << "Variable " << ivar << " has zero width" << Endl;
648  }
649  }
650 
651  return Event(vvec, event.GetWeight(), event.GetType(), event.GetTargets());
652 }
653 
654 ////////////////////////////////////////////////////////////////////////////////
655 /// print
656 
658 {
659  Print(std::cout);
660 }
661 
662 ////////////////////////////////////////////////////////////////////////////////
663 /// print
664 
665 void TMVA::kNN::ModulekNN::Print(std::ostream &os) const
666 {
667  os << "----------------------------------------------------------------------"<< std::endl;
668  os << "Printing knn result" << std::endl;
669  os << fkNNEvent << std::endl;
670 
671  UInt_t count = 0;
672 
673  std::map<Short_t, Double_t> min, max;
674 
675  os << "Printing " << fkNNList.size() << " nearest neighbors" << std::endl;
676  for (List::const_iterator it = fkNNList.begin(); it != fkNNList.end(); ++it) {
677  os << ++count << ": " << it->second << ": " << it->first->GetEvent() << std::endl;
678 
679  const Event &event = it->first->GetEvent();
680  for (UShort_t ivar = 0; ivar < event.GetNVar(); ++ivar) {
681  if (min.find(ivar) == min.end()) {
682  min[ivar] = event.GetVar(ivar);
683  }
684  else if (min[ivar] > event.GetVar(ivar)) {
685  min[ivar] = event.GetVar(ivar);
686  }
687 
688  if (max.find(ivar) == max.end()) {
689  max[ivar] = event.GetVar(ivar);
690  }
691  else if (max[ivar] < event.GetVar(ivar)) {
692  max[ivar] = event.GetVar(ivar);
693  }
694  }
695  }
696 
697  if (min.size() == max.size()) {
698  for (std::map<Short_t, Double_t>::const_iterator mit = min.begin(); mit != min.end(); ++mit) {
699  const Short_t i = mit->first;
700  Log() << kINFO << "(var, min, max) = (" << i << "," << min[i] << ", " << max[i] << ")" << Endl;
701  }
702  }
703 
704  os << "----------------------------------------------------------------------" << std::endl;
705 }
~ModulekNN()
destructor
Definition: ModulekNN.cxx:178
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
RooCmdArg Optimize(Int_t flag=2)
UInt_t GetNVar() const
Definition: ModulekNN.h:196
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
ModulekNN()
default constructor
Definition: ModulekNN.cxx:168
const Event Scale(const Event &event) const
scale each event variable so that rms of variables is approximately 1.0 this allows comparisons of va...
Definition: ModulekNN.cxx:623
#define assert(cond)
Definition: unittest.h:542
unsigned short UShort_t
Definition: RtypesCore.h:36
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
std::ostream & operator<<(std::ostream &os, const Event &event)
streamer
Definition: ModulekNN.cxx:159
void Print() const
print
Definition: ModulekNN.cxx:657
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:501
int d
Definition: tornado.py:11
std::vector< TMVA::kNN::Event > EventVec
Definition: ModulekNN.h:105
Bool_t Fill(const UShort_t odepth, UInt_t ifrac, const std::string &option="")
fill the tree
Definition: ModulekNN.cxx:240
void SetNodeL(Node *node)
Definition: NodekNN.h:149
VarType GetVar(UInt_t i) const
Definition: ModulekNN.h:187
Float_t VarType
Definition: ModulekNN.h:64
~Event()
destructor
Definition: ModulekNN.cxx:76
unsigned int UInt_t
Definition: RtypesCore.h:42
bool first
Definition: line3Dfit.C:48
short Short_t
Definition: RtypesCore.h:35
void Add(const Event &event)
add an event to tree
Definition: ModulekNN.cxx:207
Bool_t Find(Event event, UInt_t nfind=100, const std::string &option="count") const
find in tree if tree has been filled then search for nfind closest events if metic (fVarScale map) is...
Definition: ModulekNN.cxx:343
void SetTargets(const VarVec &tvec)
Definition: ModulekNN.cxx:102
Event()
default constructor
Definition: ModulekNN.cxx:45
PyObject * fType
VarType GetDist(VarType var, UInt_t ivar) const
Definition: ModulekNN.h:178
tuple tree
Definition: tree.py:24
void Print(std::ostream &os, const OptionType &opt)
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
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)
Definition: vector.h:440
const VarVec & GetTargets() const
Definition: ModulekNN.cxx:109
Double_t GetWeight() const
Definition: ModulekNN.h:183
Node< Event > * Optimize(UInt_t optimize_depth)
Optimize() balances binary tree for first odepth levels for each depth we split sorted depth % dimens...
Definition: ModulekNN.cxx:444
void Clear()
clean up
Definition: ModulekNN.cxx:189
void SetNodeR(Node *node)
Definition: NodekNN.h:155
void Print() const
print
Definition: ModulekNN.cxx:124
const Bool_t kTRUE
Definition: Rtypes.h:91
std::vector< VarType > VarVec
Definition: ModulekNN.h:65
Short_t GetType() const
Definition: ModulekNN.h:204
const VarVec & GetVars() const
Definition: ModulekNN.cxx:116
Definition: math.cpp:60
void ComputeMetric(UInt_t ifrac)
compute scale factor for each variable (dimension) so that distance is computed uniformely along each...
Definition: ModulekNN.cxx:537