/* *************************************** * LVQ Classifier * * Author: M.Babai@rug.nl * * Edited: E.A.Dijck@student.rug.nl * * LICENSE: * * Version: 0.1 beta1. * * License: * * *************************************** */ #include "PndLVQClassify.h" using namespace std; /** * Constructor: * @param inputFile: Input file name (Weights). * @param classNames: class names. * @param varNames: variable names of the features. */ PndLVQClassify::PndLVQClassify(const string& inputFile, const vector& classNames, const vector& varNames) : PndGpidClassifier(inputFile, classNames, varNames) {} /** * Destructor */ PndLVQClassify::~PndLVQClassify() {} /** * Given a feature vector describing the pattern. Classifies the pattern. *@param EvtData Input vector describing the pattern. *@return The name of the class to which the current pattern is assigned. */ const std::string& PndLVQClassify::Classify(std::vector EvtData)const { EvtData.clear(); std::string* re = new std::string(); std::cout << "Not implemented Yet" << std::endl; return *re; } /** * @param eventData: Event data to be classified. * @param result: Classification results. Currently the shortest * distance for each class is stored in result. */ void PndLVQClassify::GetMvaValues(vector eventData, map& result) { // Holds the number of available examples per class const vector& vars = m_dataSets.GetVars(); const vector& classes = m_dataSets.GetClasses(); const vector*> >& ProtoList = m_dataSets.GetData(); // Initialize results result.clear(); for(size_t id = 0; id < classes.size(); id++) { result.insert(make_pair(classes[id].Name, numeric_limits::max())); } // Normalize current Event for(size_t k = 0; k < vars.size(); k++) { assert(vars[k].NormFactor != 0); eventData[k] -= vars[k].Mean; eventData[k] /= vars[k].NormFactor; } // Loop trough the prototypes list and compute the distances float dist = 0.0; for(size_t i = 0; i < ProtoList.size(); i++) { string clsName = ProtoList[i].first; vector* ev = ProtoList[i].second; dist = ComputeDist(*ev, eventData); if( dist < result[clsName] ){ result[clsName] = dist; } } // Normalize Resul map float Sum = 0.0; for(size_t i = 0; i < classes.size(); i++) { string clsName = classes[i].Name; Sum += result[clsName]; } for(size_t i = 0; i < classes.size(); i++) { string clsName = classes[i].Name; result[clsName] /= Sum; // result[clsName] = 1.0 - result[clsName]; // Do we need this? } }