Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MethodKNN.h
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 : MethodKNN *
8 * *
9 * *
10 * Description: *
11 * Analysis of k-nearest neighbor *
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 * (see tmva/doc/LICENSE) *
24 **********************************************************************************/
25
26#ifndef ROOT_TMVA_MethodKNN
27#define ROOT_TMVA_MethodKNN
28
29//////////////////////////////////////////////////////////////////////////
30// //
31// MethodKNN //
32// //
33// Analysis of k-nearest neighbor //
34// //
35//////////////////////////////////////////////////////////////////////////
36
37#include <vector>
38
39// Local
40#include "TMVA/MethodBase.h"
41#include "TMVA/ModulekNN.h"
42
43// SVD and linear discriminant code
44#include "TMVA/LDA.h"
45
46namespace TMVA
47{
48 namespace kNN
49 {
50 class ModulekNN;
51 }
52
53 class MethodKNN : public MethodBase
54 {
55 public:
56
57 MethodKNN(const TString& jobName,
58 const TString& methodTitle,
59 DataSetInfo& theData,
60 const TString& theOption = "KNN");
61
62 MethodKNN(DataSetInfo& theData,
63 const TString& theWeightFile);
64
65 virtual ~MethodKNN( void );
66
67 virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
68
69 void Train( void );
70
71 Double_t GetMvaValue( Double_t* err = nullptr, Double_t* errUpper = nullptr );
72 const std::vector<Float_t>& GetRegressionValues();
73
75
76 void WriteWeightsToStream(TFile& rf) const;
77 void AddWeightsXMLTo( void* parent ) const;
78 void ReadWeightsFromXML( void* wghtnode );
79
80 void ReadWeightsFromStream(std::istream& istr);
82
83 const Ranking* CreateRanking();
84
85 protected:
86
87 // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
88 void MakeClassSpecific( std::ostream&, const TString& ) const;
89
90 // get help message text
91 void GetHelpMessage() const;
92
93 private:
94
95 // the option handling methods
96 void DeclareOptions();
97 void ProcessOptions();
99
100 // default initialisation called by all constructors
101 void Init( void );
102
103 // create kd-tree (binary tree) structure
104 void MakeKNN( void );
105
106 // polynomial and Gaussian kernel weight function
108 Double_t GausKernel(const kNN::Event &event_knn, const kNN::Event &event, const std::vector<Double_t> &svec) const;
109
110 Double_t getKernelRadius(const kNN::List &rlist) const;
111 const std::vector<Double_t> getRMS(const kNN::List &rlist, const kNN::Event &event_knn) const;
112
113 double getLDAValue(const kNN::List &rlist, const kNN::Event &event_knn);
114
115 private:
116
117 // number of events (sumOfWeights)
118 Double_t fSumOfWeightsS; ///< sum-of-weights for signal training events
119 Double_t fSumOfWeightsB; ///< sum-of-weights for background training events
120
121 kNN::ModulekNN *fModule; ///<! module where all work is done
122
123 Int_t fnkNN; ///< number of k-nearest neighbors
124 Int_t fBalanceDepth; ///< number of binary tree levels used for balancing tree
125
126 Float_t fScaleFrac; ///< fraction of events used to compute variable width
127 Float_t fSigmaFact; ///< scale factor for Gaussian sigma in Gaus. kernel
128
129 TString fKernel; ///< ="Gaus","Poln" - kernel type for smoothing
130
131 Bool_t fTrim; ///< set equal number of signal and background events
132 Bool_t fUseKernel; ///< use polynomial kernel weight function
133 Bool_t fUseWeight; ///< use weights to count kNN
134 Bool_t fUseLDA; ///< use local linear discriminant analysis to compute MVA
135
136 kNN::EventVec fEvent; ///<! (untouched) events used for learning
137
138 LDA fLDA; ///<! Experimental feature for local knn analysis
139
140 // for backward compatibility
141 Int_t fTreeOptDepth; ///< number of binary tree levels used for optimization
142
143 ClassDef(MethodKNN,0); // k Nearest Neighbour classifier
144 };
145
146} // namespace TMVA
147
148#endif // MethodKNN
float Float_t
Definition RtypesCore.h:57
#define ClassDef(name, id)
Definition Rtypes.h:337
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
Class that contains all the data information.
Definition DataSetInfo.h:62
Virtual base Class for all MVA method.
Definition MethodBase.h:111
virtual void ReadWeightsFromStream(std::istream &)=0
Analysis of k-nearest neighbor.
Definition MethodKNN.h:54
void Init(void)
Initialization.
Int_t fBalanceDepth
number of binary tree levels used for balancing tree
Definition MethodKNN.h:124
void MakeKNN(void)
create kNN
TString fKernel
="Gaus","Poln" - kernel type for smoothing
Definition MethodKNN.h:129
Float_t fScaleFrac
fraction of events used to compute variable width
Definition MethodKNN.h:126
virtual ~MethodKNN(void)
destructor
virtual Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets)
FDA can handle classification with 2 classes and regression with one regression-target.
const std::vector< Double_t > getRMS(const kNN::List &rlist, const kNN::Event &event_knn) const
Get polynomial kernel radius.
const Ranking * CreateRanking()
no ranking available
Int_t fTreeOptDepth
number of binary tree levels used for optimization
Definition MethodKNN.h:141
Double_t fSumOfWeightsS
sum-of-weights for signal training events
Definition MethodKNN.h:118
void MakeClassSpecific(std::ostream &, const TString &) const
write specific classifier response
void DeclareCompatibilityOptions()
options that are used ONLY for the READER to ensure backward compatibility
Double_t getKernelRadius(const kNN::List &rlist) const
Get polynomial kernel radius.
void GetHelpMessage() const
get help message text
const std::vector< Float_t > & GetRegressionValues()
Return vector of averages for target values of k-nearest neighbors.
Double_t fSumOfWeightsB
sum-of-weights for background training events
Definition MethodKNN.h:119
kNN::EventVec fEvent
! (untouched) events used for learning
Definition MethodKNN.h:136
void Train(void)
kNN training
void ReadWeightsFromStream(std::istream &istr)
read the weights
double getLDAValue(const kNN::List &rlist, const kNN::Event &event_knn)
Double_t PolnKernel(Double_t value) const
polynomial kernel
void ProcessOptions()
process the options specified by the user
void ReadWeightsFromXML(void *wghtnode)
void AddWeightsXMLTo(void *parent) const
write weights to XML
kNN::ModulekNN * fModule
! module where all work is done
Definition MethodKNN.h:121
Bool_t fUseLDA
use local linear discriminant analysis to compute MVA
Definition MethodKNN.h:134
Float_t fSigmaFact
scale factor for Gaussian sigma in Gaus. kernel
Definition MethodKNN.h:127
Bool_t fTrim
set equal number of signal and background events
Definition MethodKNN.h:131
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr)
Compute classifier response.
Bool_t fUseWeight
use weights to count kNN
Definition MethodKNN.h:133
Bool_t fUseKernel
use polynomial kernel weight function
Definition MethodKNN.h:132
void DeclareOptions()
MethodKNN options.
void WriteWeightsToStream(TFile &rf) const
save weights to ROOT file
LDA fLDA
! Experimental feature for local knn analysis
Definition MethodKNN.h:138
Double_t GausKernel(const kNN::Event &event_knn, const kNN::Event &event, const std::vector< Double_t > &svec) const
Gaussian kernel.
Int_t fnkNN
number of k-nearest neighbors
Definition MethodKNN.h:123
Ranking for variables in method (implementation)
Definition Ranking.h:48
kNN::Event describes point in input variable vector-space, with additional functionality like distanc...
std::list< Elem > List
Definition ModulekNN.h:99
std::vector< TMVA::kNN::Event > EventVec
Definition ModulekNN.h:97
Basic string class.
Definition TString.h:139
create variable transformations