/* * main.cpp * * Matlab interface for writing SVMWeights to an XML file * Input: array (9216x8), ni, mu * Output: nothing to Matlab, creates/overwrites an XML file: SVMWeights_ni_mu.xml * * Created by Andrew Salamon on Tue May 9 2006. * * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * Please read the license information at the end of this file. */ #include #include #include #include #include //#include //#include //#include #include #include using namespace std; void writeOneArray( const mxArray *array, int ni, int mu, int prec ); void writeOneArrayBinary( const mxArray *array, int ni, int mu, int prec ); /** A mex file for creating SVM weights files for use by CERT. * This function takes three arguments: * -# mxArray: A Matlab array (9216x8). One slice of the full SVMWeights data * -# int: ni * -# int: mu */ void mexFunction(int nlhs,mxArray*plhs[],int nrhs, const mxArray*prhs[]) { // check number of input/output variables if (nlhs != 0 ) mexErrMsgTxt("SVMExport has no outputs"); if (nrhs < 3) mexErrMsgTxt("SVMExport: requires three inputs: 9216x8 array, ni, mu. Plus an optional precision"); int ni = static_cast(mxGetScalar(prhs[1])); int mu = static_cast(mxGetScalar(prhs[2])); int prec = 6; if( nrhs > 3 ) prec = static_cast(mxGetScalar(prhs[3])); writeOneArray( prhs[0], ni, mu, prec ); // writeOneArrayBinary( prhs[0], ni, mu, prec ); } void writeOneArray( const mxArray *array, int ni, int mu, int prec ) { double *realArray = mxGetPr(array); int rowmax = static_cast(mxGetM(array)); int colmax = static_cast(mxGetN(array)); strstream fNameStream; fNameStream << "SVMWeights_" << ni << "_" << mu << ".xml" << ends(fNameStream); string fName( fNameStream.str() ); ofstream file( fName.c_str(), ios::out); file << "" << endl; file << "" << endl; file << setprecision(prec); for( int row=0; row"; for( int col=0; col" << endl; } file << "" << endl; } void writeOneArrayBinary( const mxArray *array, int ni, int mu, int prec ) { double *realArray = mxGetPr(array); int rowmax = static_cast(mxGetM(array)); int colmax = static_cast(mxGetN(array)); strstream fNameStream; fNameStream << "SVMWeights_" << ni << "_" << mu << ".svm" << ends(fNameStream); string fName( fNameStream.str() ); ofstream file( fName.c_str(), ios::out | ios::binary | ios::trunc ); file << "SVMWeights ni=" << ni << " mu=" << mu << " colcount=" << colmax << " rowcount=" << rowmax << endl; for( int row=0; row