#include #include #include #include #include #include #include #ifdef WIN32 extern "C" { #ifdef INTELMKL #include "mkl_cblas.h" #else #include "cblas.h" #endif } #else #include #endif #include "mp_AUResults.h" #include "mp_BHAT.h" #include "mp_MLR.h" std::vector multiplyBhat_X( const double *bhat, const double *X ); void usage() { std::cout << "Usage: mlr " << std::endl; } void printResults( std::vector &results ) { std::cout.precision(6); for( unsigned int i=0; i < results.size(); ++i ) { std::cout << results[i]; if( i < (results.size() - 1) ) std::cout << ", "; } std::cout << std::endl; } int main( int argc, char *argv[] ) { if( 2 != argc ) { usage(); return 1; } std::string filename( argv[1] ); // filename += mp_AUResults::extensionForFiletype( mp_AUResults::xml ); std::ifstream ifs( filename.c_str() ); if( !ifs.good() ) { std::cerr << "Unable to open file: " << filename << std::endl; return -1; } mp_AUResults baseResults; baseResults.restore( ifs ); // std::cout << baseResults; typedef std::pair< std::string, unsigned int > catAUpair; std::string category( "SVMWeights" ); std::map< std::string, mp_AUResults > fakeResults; fakeResults[ category ] = baseResults; inputAUVector inputs; inputs.push_back( catAUpair( category, 0 ) ); inputs.push_back( catAUpair( category, 1 ) ); inputs.push_back( catAUpair( category, 2 ) ); inputs.push_back( catAUpair( category, 3 ) ); inputs.push_back( catAUpair( category, 4 ) ); mp_MLR mlr( "BHAT_1-2.xml", inputs ); double answer = mlr.MLR( fakeResults ); std::cout << answer << std::endl; /* std::vector freqs; std::vector aus; aus.push_back( 1 ); aus.push_back( 2 ); aus.push_back( 4 ); for( unsigned int auIndex = 0; auIndex < aus.size(); ++auIndex ) { std::vector aFreq = baseResults.frequenciesForAUIndex( auIndex ); freqs.insert( freqs.end(), aFreq.begin(), aFreq.end() ); } freqs.push_back(1.0); // printResults( freqs ); // std::cout << "Freqency vector is: " << freqs.size() << std::endl; std::string bhatFile("BHAT.xml"); mp_BHAT bhat( bhatFile ); double *freqAccess = &(freqs[0]); std::vector res = multiplyBhat_X( bhat.getWeights(), freqAccess ); // res[0] = exp( res[0] ); // res[1] = exp( res[1] ); std::transform( res.begin(), res.end(), res.begin(), exp ); // calculate the exponent of each element // double sum = res[0] + res[1]; double sum = std::accumulate( res.begin(), res.end(), 0.0 ); // res[0] = res[0] / sum; // res[1] = res[1] / sum; std::transform( res.begin(), res.end(), res.begin(), std::bind2nd(std::divides(), sum) ); // divide each element by the sum printResults( res ); */ return 0; } std::vector multiplyBhat_X( const double *bhat, const double *X ) { unsigned int count = 2; double tmpYhat[count]; for( unsigned int i=0; i < count; ++i ) { tmpYhat[i] = 0.0; } double alpha = 1.0; double beta = 0.0; int n = count; int m = 217; int lda = n; int incX = 1; // No idea what this is for int incY = 1; // No idea what this is for // see http://www.netlib.org/clapack/cblas/dgemm.c for details cblas_dgemv( CblasRowMajor, CblasTrans, m, n, alpha, bhat, lda, X, incX, beta, tmpYhat, incY); return std::vector( tmpYhat, tmpYhat+count ); }