56 #ifndef IClassifierReader__def 57 #define IClassifierReader__def 59 class IClassifierReader {
64 IClassifierReader() : fStatusIsClean(
true ) {}
65 virtual ~IClassifierReader() {}
68 virtual double GetMvaValue(
const std::vector<double>& inputValues )
const = 0;
71 bool IsStatusClean()
const {
return fStatusIsClean; }
80 class ReadFisher :
public IClassifierReader {
85 ReadFisher( std::vector<std::string>& theInputVars )
86 : IClassifierReader(),
87 fClassName(
"ReadFisher" ),
89 fIsNormalised(
false )
92 const char* inputVars[] = {
"var1",
"var2",
"var3",
"var4" };
95 if (theInputVars.size() <= 0) {
96 std::cout <<
"Problem in class \"" << fClassName <<
"\": empty input vector" << std::endl;
97 fStatusIsClean =
false;
100 if (theInputVars.size() != fNvars) {
101 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in number of input values: " 102 << theInputVars.size() <<
" != " << fNvars << std::endl;
103 fStatusIsClean =
false;
107 for (
size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
108 if (theInputVars[ivar] != inputVars[ivar]) {
109 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in input variable names" << std::endl
110 <<
" for variable [" << ivar <<
"]: " << theInputVars[ivar].c_str() <<
" != " << inputVars[ivar] << std::endl;
111 fStatusIsClean =
false;
137 virtual ~ReadFisher() {
144 double GetMvaValue(
const std::vector<double>& inputValues )
const;
152 const char* fClassName;
155 size_t GetNvar()
const {
return fNvars; }
159 const bool fIsNormalised;
160 bool IsNormalised()
const {
return fIsNormalised; }
163 double NormVariable(
double x,
double xmin,
double xmax )
const {
165 return 2*(x -
xmin)/(xmax - xmin) - 1.0;
173 double GetMvaValue__(
const std::vector<double>& inputValues )
const;
177 std::vector<double> fFisherCoefficients;
182 fFisher0 = -0.024433136605;
183 fFisherCoefficients.push_back( -0.0588850814086 );
184 fFisherCoefficients.push_back( -0.00612727901444 );
185 fFisherCoefficients.push_back( 0.0964243016268 );
186 fFisherCoefficients.push_back( 0.218679158219 );
189 if (fFisherCoefficients.size() != fNvars) {
190 std::cout <<
"Problem in class \"" << fClassName <<
"\"::Initialize: mismatch in number of input values" 191 << fFisherCoefficients.size() <<
" != " << fNvars << std::endl;
192 fStatusIsClean =
false;
196 inline double ReadFisher::GetMvaValue__(
const std::vector<double>& inputValues )
const 198 double retval = fFisher0;
199 for (
size_t ivar = 0; ivar < fNvars; ivar++) {
200 retval += fFisherCoefficients[ivar]*inputValues[ivar];
207 inline void ReadFisher::Clear()
210 fFisherCoefficients.clear();
212 inline double ReadFisher::GetMvaValue(
const std::vector<double>& inputValues )
const 218 if (!IsStatusClean()) {
219 std::cout <<
"Problem in class \"" << fClassName <<
"\": cannot return classifier response" 220 <<
" because status is dirty" << std::endl;
224 if (IsNormalised()) {
226 std::vector<double> iV;
227 iV.reserve(inputValues.size());
229 for (std::vector<double>::const_iterator varIt = inputValues.begin();
230 varIt != inputValues.end(); varIt++, ivar++) {
231 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
233 retval = GetMvaValue__( iV );
236 retval = GetMvaValue__( inputValues );
Type GetType(const std::string &Name)
void Initialize(Bool_t useTMVAStyle=kTRUE)