// Class: ReadKNN // Automatically generated by MethodBase::MakeClass // /* configuration options ===================================================== #GEN -*-*-*-*-*-*-*-*-*-*-*- general info -*-*-*-*-*-*-*-*-*-*-*- Method : KNN::KNN TMVA Release : 4.1.4 [262404] ROOT Release : 5.34/05 [336389] Creator : karavdina Date : Wed Mar 27 10:31:01 2013 Host : Linux pool253.a1.kph 3.7.9-205.fc18.x86_64 #1 SMP Sun Feb 24 20:10:02 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux Dir : /panda/karavdina/BkgSeparation Training events: 10413 Analysis type : [Classification] #OPT -*-*-*-*-*-*-*-*-*-*-*-*- options -*-*-*-*-*-*-*-*-*-*-*-*- # Set by User: H: "True" [Print method-specific help message] CreateMVAPdfs: "True" [Create PDFs for classifier outputs (signal and background)] nkNN: "30" [Number of k-nearest neighbors] ScaleFrac: "8.000000e-01" [Fraction of events used to compute variable width] SigmaFact: "1.000000e+00" [Scale factor for sigma in Gaussian kernel] Kernel: "Gaus" [Use polynomial (=Poln) or Gaussian (=Gaus) kernel] Trim: "False" [Use equal number of signal and background events] UseKernel: "False" [Use polynomial kernel weight] UseWeight: "True" [Use weight to count kNN events] # Default: V: "False" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)] VerbosityLevel: "Default" [Verbosity level] VarTransform: "None" [List of variable transformations performed before training, e.g., "D_Background,P_Signal,G,N_AllClasses" for: "Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)"] IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)] BalanceDepth: "6" [Binary tree balance depth] UseLDA: "False" [Use local linear discriminant - experimental feature] ## #VAR -*-*-*-*-*-*-*-*-*-*-*-* variables *-*-*-*-*-*-*-*-*-*-*-*- NVar 9 x x x x 'D' [-19.8703174591,19.7482700348] y y y y 'D' [-17.0589866638,16.8706817627] z z z z 'D' [-0.0387658625841,0.514511883259] p p p p 'D' [14.9999980927,21.2431297302] theta theta theta theta 'D' [0.000339014193742,0.0198132172227] phi phi phi phi 'D' [-3.14069318771,3.14107322693] px px px px 'D' [-0.222319915891,0.326948046684] py py py py 'D' [-0.234180748463,0.166489973664] pz pz pz pz 'D' [14.9989938736,21.2421226501] NSpec 0 ============================================================================ */ #include #include #include #include #ifndef IClassifierReader__def #define IClassifierReader__def class IClassifierReader { public: // constructor IClassifierReader() : fStatusIsClean( true ) {} virtual ~IClassifierReader() {} // return classifier response virtual double GetMvaValue( const std::vector& inputValues ) const = 0; // returns classifier status bool IsStatusClean() const { return fStatusIsClean; } protected: bool fStatusIsClean; }; #endif class ReadKNN : public IClassifierReader { public: // constructor ReadKNN( std::vector& theInputVars ) : IClassifierReader(), fClassName( "ReadKNN" ), fNvars( 9 ), fIsNormalised( false ) { // the training input variables const char* inputVars[] = { "x", "y", "z", "p", "theta", "phi", "px", "py", "pz" }; // sanity checks if (theInputVars.size() <= 0) { std::cout << "Problem in class \"" << fClassName << "\": empty input vector" << std::endl; fStatusIsClean = false; } if (theInputVars.size() != fNvars) { std::cout << "Problem in class \"" << fClassName << "\": mismatch in number of input values: " << theInputVars.size() << " != " << fNvars << std::endl; fStatusIsClean = false; } // validate input variables for (size_t ivar = 0; ivar < theInputVars.size(); ivar++) { if (theInputVars[ivar] != inputVars[ivar]) { std::cout << "Problem in class \"" << fClassName << "\": mismatch in input variable names" << std::endl << " for variable [" << ivar << "]: " << theInputVars[ivar].c_str() << " != " << inputVars[ivar] << std::endl; fStatusIsClean = false; } } // initialize min and max vectors (for normalisation) fVmin[0] = -19.8703174591064; fVmax[0] = 19.74827003479; fVmin[1] = -17.0589866638184; fVmax[1] = 16.8706817626953; fVmin[2] = -0.0387658625841141; fVmax[2] = 0.51451188325882; fVmin[3] = 14.9999980926514; fVmax[3] = 21.2431297302246; fVmin[4] = 0.000339014193741605; fVmax[4] = 0.0198132172226906; fVmin[5] = -3.14069318771362; fVmax[5] = 3.14107322692871; fVmin[6] = -0.222319915890694; fVmax[6] = 0.326948046684265; fVmin[7] = -0.234180748462677; fVmax[7] = 0.166489973664284; fVmin[8] = 14.9989938735962; fVmax[8] = 21.2421226501465; // initialize input variable types fType[0] = 'D'; fType[1] = 'D'; fType[2] = 'D'; fType[3] = 'D'; fType[4] = 'D'; fType[5] = 'D'; fType[6] = 'D'; fType[7] = 'D'; fType[8] = 'D'; // initialize constants Initialize(); } // destructor virtual ~ReadKNN() { Clear(); // method-specific } // the classifier response // "inputValues" is a vector of input values in the same order as the // variables given to the constructor double GetMvaValue( const std::vector& inputValues ) const; private: // method-specific destructor void Clear(); // common member variables const char* fClassName; const size_t fNvars; size_t GetNvar() const { return fNvars; } char GetType( int ivar ) const { return fType[ivar]; } // normalisation of input variables const bool fIsNormalised; bool IsNormalised() const { return fIsNormalised; } double fVmin[9]; double fVmax[9]; double NormVariable( double x, double xmin, double xmax ) const { // normalise to output range: [-1, 1] return 2*(x - xmin)/(xmax - xmin) - 1.0; } // type of input variable: 'F' or 'I' char fType[9]; // initialize internal variables void Initialize(); double GetMvaValue__( const std::vector& inputValues ) const; // private members (method specific) // not implemented for class: "ReadKNN" }; inline double ReadKNN::GetMvaValue( const std::vector& inputValues ) const { // classifier response value double retval = 0; // classifier response, sanity check first if (!IsStatusClean()) { std::cout << "Problem in class \"" << fClassName << "\": cannot return classifier response" << " because status is dirty" << std::endl; retval = 0; } else { if (IsNormalised()) { // normalise variables std::vector iV; int ivar = 0; for (std::vector::const_iterator varIt = inputValues.begin(); varIt != inputValues.end(); varIt++, ivar++) { iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] )); } retval = GetMvaValue__( iV ); } else { retval = GetMvaValue__( inputValues ); } } return retval; }