52 #ifndef IClassifierReader__def 53 #define IClassifierReader__def 55 class IClassifierReader {
60 IClassifierReader() : fStatusIsClean(
true ) {}
61 virtual ~IClassifierReader() {}
64 virtual double GetMvaValue(
const std::vector<double>& inputValues )
const = 0;
67 bool IsStatusClean()
const {
return fStatusIsClean; }
76 class ReadLD :
public IClassifierReader {
81 ReadLD( std::vector<std::string>& theInputVars )
82 : IClassifierReader(),
83 fClassName(
"ReadLD" ),
85 fIsNormalised(
false )
88 const char* inputVars[] = {
"var1+var2",
"var1-var2",
"var3",
"var4" };
91 if (theInputVars.size() <= 0) {
92 std::cout <<
"Problem in class \"" << fClassName <<
"\": empty input vector" << std::endl;
93 fStatusIsClean =
false;
96 if (theInputVars.size() != fNvars) {
97 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in number of input values: " 98 << theInputVars.size() <<
" != " << fNvars << std::endl;
99 fStatusIsClean =
false;
103 for (
size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
104 if (theInputVars[ivar] != inputVars[ivar]) {
105 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in input variable names" << std::endl
106 <<
" for variable [" << ivar <<
"]: " << theInputVars[ivar].c_str() <<
" != " << inputVars[ivar] << std::endl;
107 fStatusIsClean =
false;
140 double GetMvaValue(
const std::vector<double>& inputValues )
const;
148 const char* fClassName;
151 size_t GetNvar()
const {
return fNvars; }
155 const bool fIsNormalised;
156 bool IsNormalised()
const {
return fIsNormalised; }
159 double NormVariable(
double x,
double xmin,
double xmax )
const {
161 return 2*(x -
xmin)/(xmax - xmin) - 1.0;
169 double GetMvaValue__(
const std::vector<double>& inputValues )
const;
172 std::vector<double> fLDCoefficients;
177 fLDCoefficients.push_back( -0.0555505264046 );
178 fLDCoefficients.push_back( -0.326327978479 );
179 fLDCoefficients.push_back( -0.0802584320043 );
180 fLDCoefficients.push_back( -0.194835566078 );
181 fLDCoefficients.push_back( 0.757623350937 );
184 if (fLDCoefficients.size() != fNvars+1) {
185 std::cout <<
"Problem in class \"" << fClassName <<
"\"::Initialize: mismatch in number of input values" 186 << fLDCoefficients.size() <<
" != " << fNvars+1 << std::endl;
187 fStatusIsClean =
false;
191 inline double ReadLD::GetMvaValue__(
const std::vector<double>& inputValues )
const 193 double retval = fLDCoefficients[0];
194 for (
size_t ivar = 1; ivar < fNvars+1; ivar++) {
195 retval += fLDCoefficients[ivar]*inputValues[ivar-1];
202 inline void ReadLD::Clear()
205 fLDCoefficients.clear();
207 inline double ReadLD::GetMvaValue(
const std::vector<double>& inputValues )
const 213 if (!IsStatusClean()) {
214 std::cout <<
"Problem in class \"" << fClassName <<
"\": cannot return classifier response" 215 <<
" because status is dirty" << std::endl;
219 if (IsNormalised()) {
221 std::vector<double> iV;
222 iV.reserve(inputValues.size());
224 for (std::vector<double>::const_iterator varIt = inputValues.begin();
225 varIt != inputValues.end(); varIt++, ivar++) {
226 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
228 retval = GetMvaValue__( iV );
231 retval = GetMvaValue__( inputValues );
Type GetType(const std::string &Name)
void Initialize(Bool_t useTMVAStyle=kTRUE)