#ifdef NICE_USELIB_MEX /** * @file GPHIKClassifierMex.cpp * @author Alexander Freytag * @date 07-01-2014 (dd-mm-yyyy) * @brief Matlab-Interface of our GPHIKClassifier, allowing for training, classification, optimization, variance prediction, incremental learning, and storing/re-storing. */ // STL includes #include #include #include // NICE-core includes #include #include #include "vislearning/cbaselib/Example.h" // Interface for conversion between Matlab and C objects #include "gp-hik-core/matlab/classHandleMtoC.h" #include "gp-hik-core/matlab/ConverterMatlabToNICE.h" #include "gp-hik-core/matlab/ConverterNICEToMatlab.h" using namespace std; //C basics using namespace NICE; // nice-core // MAIN MATLAB FUNCTION void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // get the command string specifying what to do if (nrhs < 1) mexErrMsgTxt("No commands and options passed... Aborting!"); if( !mxIsChar( prhs[0] ) ) mexErrMsgTxt("First argument needs to be the command, ie.e, the unit test method to call... Aborting!"); std::string cmd = MatlabConversion::convertMatlabToString( prhs[0] ); // in all other cases, there should be a second input, // which the be the class instance handle if (nrhs < 2) { mexErrMsgTxt("Second input should be some kind of matrix variable"); return; } if (nlhs < 1) { mexErrMsgTxt("No return value defined, possible loss of data... Aborting!"); } //////////////////////////////////////// // Check which method to call // //////////////////////////////////////// if ( !strcmp("convertDoubleMatrixToExamples", cmd.c_str() ) ) { if (nrhs != 3) { mexErrMsgTxt("needs 2 matrix inputs, first the training features, second the sample labels"); return; } const mxArray *t_pArrTrainData = prhs[1]; const mxArray *t_pArrTrainLabels = prhs[2]; NICE::Vector t_vecLabelsTrain = MatlabConversion::convertDoubleVectorToNice( t_pArrTrainLabels ); NICE::Matrix t_matDataTrain = MatlabConversion::convertDoubleMatrixToNice( t_pArrTrainData ); OBJREC::Examples t_ExamplesTrain; bool bConversionSuccess = OBJREC::Examples::wrapExamplesAroundFeatureMatrix( t_matDataTrain, t_vecLabelsTrain, t_ExamplesTrain ); //wrapExamplesAroundFeatureMatrix std::cerr << "Examples size: " << t_ExamplesTrain.size() << std::endl; for(int i=0; i< t_ExamplesTrain.size(); i++) { int iClass = t_ExamplesTrain[i].first; OBJREC::Example &t_Example = t_ExamplesTrain[i].second ; std::cerr << "Example["<