53 #ifndef IClassifierReader__def 54 #define IClassifierReader__def 56 class IClassifierReader {
61 IClassifierReader() : fStatusIsClean(
true ) {}
62 virtual ~IClassifierReader() {}
65 virtual double GetMvaValue(
const std::vector<double>& inputValues )
const = 0;
68 bool IsStatusClean()
const {
return fStatusIsClean; }
77 class ReadLD :
public IClassifierReader {
82 ReadLD( std::vector<std::string>& theInputVars )
83 : IClassifierReader(),
84 fClassName(
"ReadLD" ),
86 fIsNormalised(
false )
89 const char* inputVars[] = {
"var1+var2",
"var1-var2",
"var3",
"var4" };
92 if (theInputVars.size() <= 0) {
93 std::cout <<
"Problem in class \"" << fClassName <<
"\": empty input vector" << std::endl;
94 fStatusIsClean =
false;
97 if (theInputVars.size() != fNvars) {
98 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in number of input values: " 99 << theInputVars.size() <<
" != " << fNvars << std::endl;
100 fStatusIsClean =
false;
104 for (
size_t ivar = 0; ivar < theInputVars.size(); ivar++) {
105 if (theInputVars[ivar] != inputVars[ivar]) {
106 std::cout <<
"Problem in class \"" << fClassName <<
"\": mismatch in input variable names" << std::endl
107 <<
" for variable [" << ivar <<
"]: " << theInputVars[ivar].c_str() <<
" != " << inputVars[ivar] << std::endl;
108 fStatusIsClean =
false;
141 double GetMvaValue(
const std::vector<double>& inputValues )
const override;
149 const char* fClassName;
152 size_t GetNvar()
const {
return fNvars; }
156 const bool fIsNormalised;
157 bool IsNormalised()
const {
return fIsNormalised; }
160 double NormVariable(
double x,
double xmin,
double xmax )
const {
162 return 2*(x -
xmin)/(xmax - xmin) - 1.0;
170 double GetMvaValue__(
const std::vector<double>& inputValues )
const;
173 std::vector<double> fLDCoefficients;
178 fLDCoefficients.push_back( -0.0555695127335 );
179 fLDCoefficients.push_back( -0.32641367671 );
180 fLDCoefficients.push_back( -0.0803002889612 );
181 fLDCoefficients.push_back( -0.194829607347 );
182 fLDCoefficients.push_back( 0.757665927943 );
185 if (fLDCoefficients.size() != fNvars+1) {
186 std::cout <<
"Problem in class \"" << fClassName <<
"\"::Initialize: mismatch in number of input values" 187 << fLDCoefficients.size() <<
" != " << fNvars+1 << std::endl;
188 fStatusIsClean =
false;
192 inline double ReadLD::GetMvaValue__(
const std::vector<double>& inputValues )
const 194 double retval = fLDCoefficients[0];
195 for (
size_t ivar = 1; ivar < fNvars+1; ivar++) {
196 retval += fLDCoefficients[ivar]*inputValues[ivar-1];
203 inline void ReadLD::Clear()
206 fLDCoefficients.clear();
208 inline double ReadLD::GetMvaValue(
const std::vector<double>& inputValues )
const 214 if (!IsStatusClean()) {
215 std::cout <<
"Problem in class \"" << fClassName <<
"\": cannot return classifier response" 216 <<
" because status is dirty" << std::endl;
220 if (IsNormalised()) {
222 std::vector<double> iV;
223 iV.reserve(inputValues.size());
225 for (std::vector<double>::const_iterator varIt = inputValues.begin();
226 varIt != inputValues.end(); varIt++, ivar++) {
227 iV.push_back(NormVariable( *varIt, fVmin[ivar], fVmax[ivar] ));
229 retval = GetMvaValue__( iV );
232 retval = GetMvaValue__( inputValues );
Type GetType(const std::string &Name)
void Initialize(Bool_t useTMVAStyle=kTRUE)