57 #ifndef IClassifierReader__def 58 #define IClassifierReader__def 60 class IClassifierReader {
65 IClassifierReader() : fStatusIsClean(
true ) {}
66 virtual ~IClassifierReader() {}
69 virtual double GetMvaValue(
const std::vector<double>& inputValues )
const = 0;
72 bool IsStatusClean()
const {
return fStatusIsClean; }
81 class ReadFisher :
public IClassifierReader {
86 ReadFisher( std::vector<std::string>& theInputVars )
87 : IClassifierReader(),
88 fClassName(
"ReadFisher" ),
90 fIsNormalised(
false )
93 const char* inputVars[] = {
"var1",
"var2",
"var3",
"var4" };
96 if (theInputVars.size() <= 0) {
97 std::cout <<
"Problem in class \"" << fClassName <<
"\": empty input vector" << std::endl;
98 fStatusIsClean =
false;
101 if (theInputVars.size() != fNvars) {
102 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in number of input values: " 103 << theInputVars.size() <<
" != " << fNvars << std::endl;
104 fStatusIsClean =
false;
108 for (
size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
109 if (theInputVars[ivar] != inputVars[ivar]) {
110 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in input variable names" << std::endl
111 <<
" for variable [" << ivar <<
"]: " << theInputVars[ivar].c_str() <<
" != " << inputVars[ivar] << std::endl;
112 fStatusIsClean =
false;
138 virtual ~ReadFisher() {
145 double GetMvaValue(
const std::vector<double>& inputValues )
const;
153 const char* fClassName;
156 size_t GetNvar()
const {
return fNvars; }
160 const bool fIsNormalised;
161 bool IsNormalised()
const {
return fIsNormalised; }
164 double NormVariable(
double x,
double xmin,
double xmax )
const {
166 return 2*(x -
xmin)/(xmax - xmin) - 1.0;
174 double GetMvaValue__(
const std::vector<double>& inputValues )
const;
178 std::vector<double> fFisherCoefficients;
183 fFisher0 = -0.0242809098936;
184 fFisherCoefficients.push_back( -0.0589191040706 );
185 fFisherCoefficients.push_back( -0.0071916715741 );
186 fFisherCoefficients.push_back( 0.0968408275092 );
187 fFisherCoefficients.push_back( 0.219092209175 );
190 if (fFisherCoefficients.size() != fNvars) {
191 std::cout <<
"Problem in class \"" << fClassName <<
"\"::Initialize: mismatch in number of input values" 192 << fFisherCoefficients.size() <<
" != " << fNvars << std::endl;
193 fStatusIsClean =
false;
197 inline double ReadFisher::GetMvaValue__(
const std::vector<double>& inputValues )
const 199 double retval = fFisher0;
200 for (
size_t ivar = 0; ivar < fNvars; ivar++) {
201 retval += fFisherCoefficients[ivar]*inputValues[ivar];
208 inline void ReadFisher::Clear()
211 fFisherCoefficients.clear();
213 inline double ReadFisher::GetMvaValue(
const std::vector<double>& inputValues )
const 219 if (!IsStatusClean()) {
220 std::cout <<
"Problem in class \"" << fClassName <<
"\": cannot return classifier response" 221 <<
" because status is dirty" << std::endl;
225 if (IsNormalised()) {
227 std::vector<double> iV;
228 iV.reserve(inputValues.size());
230 for (std::vector<double>::const_iterator varIt = inputValues.begin();
231 varIt != inputValues.end(); varIt++, ivar++) {
232 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
234 retval = GetMvaValue__( iV );
237 retval = GetMvaValue__( inputValues );
Type GetType(const std::string &Name)
void Initialize(Bool_t useTMVAStyle=kTRUE)