#include #include #include #include #include #include "linear_svm.h" namespace mpt { linear_svm::linear_svm( const std::string &w2_path ) { load_w2( w2_path ); } linear_svm::~linear_svm() { } // h=histogram representation [1xFEATURE_VECTOR_LENGTH] double linear_svm::decision( const std::vector &histogram ) { double y = 0.0; if( feature_vector_length != histogram.size() ) { std::cerr << "Bad histogram length. Should be: " << feature_vector_length << ". Is: " << histogram.size() << std::endl; return 0.0; } for( unsigned int i = 0; i < feature_vector_length; ++i ) { y += histogram[i] * w2[i]; } return y; } void linear_svm::load_w2( const std::string &path ) { std::ifstream ifs( path.c_str() ); w2.clear(); while( ifs.good() && !ifs.eof() ) { double val; if( ifs >> val ) { w2.push_back( val ); } } if( w2.size() != feature_vector_length ) { // throw an exception std::cerr << "Vector w2 is not the right size: " << w2.size() << std::endl; } } } // end namespace mpt