GPHIKRegressionMex.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. #ifdef NICE_USELIB_MEX
  2. /**
  3. * @file GPHIKRegressionMex.cpp
  4. * @author Alexander Freytag
  5. * @date 17-01-2014 (dd-mm-yyyy)
  6. * @brief Matlab-Interface of our GPHIKRegression, allowing for training, regression, optimization, variance prediction, incremental learning, and storing/re-storing.
  7. */
  8. // STL includes
  9. #include <math.h>
  10. #include <matrix.h>
  11. #include <mex.h>
  12. // NICE-core includes
  13. #include <core/basics/Config.h>
  14. #include <core/basics/Timer.h>
  15. #include <core/vector/MatrixT.h>
  16. #include <core/vector/VectorT.h>
  17. // gp-hik-core includes
  18. #include "gp-hik-core/GPHIKRegression.h"
  19. // Interface for conversion between Matlab and C objects
  20. #include "gp-hik-core/matlab/classHandleMtoC.h"
  21. #include "gp-hik-core/matlab/ConverterMatlabToNICE.h"
  22. #include "gp-hik-core/matlab/ConverterNICEToMatlab.h"
  23. using namespace std; //C basics
  24. using namespace NICE; // nice-core
  25. NICE::Config parseParametersGPHIKRegression(const mxArray *prhs[], int nrhs)
  26. {
  27. NICE::Config conf;
  28. // if first argument is the filename of an existing config file,
  29. // read the config accordingly
  30. int i_start ( 0 );
  31. std::string variable = MatlabConversion::convertMatlabToString(prhs[i_start]);
  32. if(variable == "conf")
  33. {
  34. conf = NICE::Config ( MatlabConversion::convertMatlabToString( prhs[i_start+1] ) );
  35. i_start = i_start+2;
  36. }
  37. // now run over all given parameter specifications
  38. // and add them to the config
  39. for( int i=i_start; i < nrhs; i+=2 )
  40. {
  41. std::string variable = MatlabConversion::convertMatlabToString(prhs[i]);
  42. /////////////////////////////////////////
  43. // READ STANDARD BOOLEAN VARIABLES
  44. /////////////////////////////////////////
  45. if( (variable == "verboseTime") ||
  46. (variable == "verbose") ||
  47. (variable == "optimize_noise") ||
  48. (variable == "uncertaintyPredictionForRegression") ||
  49. (variable == "use_quantization") ||
  50. (variable == "ils_verbose")
  51. )
  52. {
  53. if ( mxIsChar( prhs[i+1] ) )
  54. {
  55. string value = MatlabConversion::convertMatlabToString( prhs[i+1] );
  56. if ( (value != "true") && (value != "false") )
  57. {
  58. std::string errorMsg = "Unexpected parameter value for \'" + variable + "\'. In string modus, \'true\' or \'false\' expected.";
  59. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  60. }
  61. if( value == "true" )
  62. conf.sB("GPHIKRegression", variable, true);
  63. else
  64. conf.sB("GPHIKRegression", variable, false);
  65. }
  66. else if ( mxIsLogical( prhs[i+1] ) )
  67. {
  68. bool value = MatlabConversion::convertMatlabToBool( prhs[i+1] );
  69. conf.sB("GPHIKRegression", variable, value);
  70. }
  71. else
  72. {
  73. std::string errorMsg = "Unexpected parameter value for \'" + variable + "\'. \'true\', \'false\', or logical expected.";
  74. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  75. }
  76. }
  77. /////////////////////////////////////////
  78. // READ STANDARD INT VARIABLES
  79. /////////////////////////////////////////
  80. if ( (variable == "nrOfEigenvaluesToConsiderForVarApprox")
  81. )
  82. {
  83. if ( mxIsDouble( prhs[i+1] ) )
  84. {
  85. double value = MatlabConversion::convertMatlabToDouble(prhs[i+1]);
  86. conf.sI("GPHIKRegression", variable, (int) value);
  87. }
  88. else if ( mxIsInt32( prhs[i+1] ) )
  89. {
  90. int value = MatlabConversion::convertMatlabToInt32(prhs[i+1]);
  91. conf.sI("GPHIKRegression", variable, value);
  92. }
  93. else
  94. {
  95. std::string errorMsg = "Unexpected parameter value for \'" + variable + "\'. Int32 or Double expected.";
  96. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  97. }
  98. }
  99. /////////////////////////////////////////
  100. // READ STRICT POSITIVE INT VARIABLES
  101. /////////////////////////////////////////
  102. if ( (variable == "num_bins") ||
  103. (variable == "ils_max_iterations")
  104. )
  105. {
  106. if ( mxIsDouble( prhs[i+1] ) )
  107. {
  108. double value = MatlabConversion::convertMatlabToDouble(prhs[i+1]);
  109. if( value < 1 )
  110. {
  111. std::string errorMsg = "Expected parameter value larger than 0 for \'" + variable + "\'.";
  112. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  113. }
  114. conf.sI("GPHIKRegression", variable, (int) value);
  115. }
  116. else if ( mxIsInt32( prhs[i+1] ) )
  117. {
  118. int value = MatlabConversion::convertMatlabToInt32(prhs[i+1]);
  119. if( value < 1 )
  120. {
  121. std::string errorMsg = "Expected parameter value larger than 0 for \'" + variable + "\'.";
  122. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  123. }
  124. conf.sI("GPHIKRegression", variable, value);
  125. }
  126. else
  127. {
  128. std::string errorMsg = "Unexpected parameter value for \'" + variable + "\'. Int32 or Double expected.";
  129. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  130. }
  131. }
  132. /////////////////////////////////////////
  133. // READ STANDARD DOUBLE VARIABLES
  134. /////////////////////////////////////////
  135. if ( (variable == "parameter_upper_bound") ||
  136. (variable == "parameter_lower_bound")
  137. )
  138. {
  139. if ( mxIsDouble( prhs[i+1] ) )
  140. {
  141. double value = MatlabConversion::convertMatlabToDouble(prhs[i+1]);
  142. conf.sD("GPHIKRegression", variable, value);
  143. }
  144. else
  145. {
  146. std::string errorMsg = "Unexpected parameter value for \'" + variable + "\'. Double expected.";
  147. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  148. }
  149. }
  150. /////////////////////////////////////////
  151. // READ POSITIVE DOUBLE VARIABLES
  152. /////////////////////////////////////////
  153. if ( (variable == "ils_min_delta") ||
  154. (variable == "ils_min_residual") ||
  155. (variable == "noise")
  156. )
  157. {
  158. if ( mxIsDouble( prhs[i+1] ) )
  159. {
  160. double value = MatlabConversion::convertMatlabToDouble(prhs[i+1]);
  161. if( value < 0.0 )
  162. {
  163. std::string errorMsg = "Expected parameter value larger than 0 for \'" + variable + "\'.";
  164. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  165. }
  166. conf.sD("GPHIKRegression", variable, value);
  167. }
  168. else
  169. {
  170. std::string errorMsg = "Unexpected parameter value for \'" + variable + "\'. Double expected.";
  171. mexErrMsgIdAndTxt( "mexnice:error", errorMsg.c_str() );
  172. }
  173. }
  174. /////////////////////////////////////////
  175. // READ REMAINING SPECIFIC VARIABLES
  176. /////////////////////////////////////////
  177. if(variable == "ils_method")
  178. {
  179. string value = MatlabConversion::convertMatlabToString(prhs[i+1]);
  180. if(value != "CG" && value != "CGL" && value != "SYMMLQ" && value != "MINRES")
  181. mexErrMsgIdAndTxt("mexnice:error","Unexpected parameter value for \'ils_method\'. \'CG\', \'CGL\', \'SYMMLQ\' or \'MINRES\' expected.");
  182. conf.sS("GPHIKRegression", variable, value);
  183. }
  184. if(variable == "optimization_method")
  185. {
  186. string value = MatlabConversion::convertMatlabToString(prhs[i+1]);
  187. if(value != "greedy" && value != "downhillsimplex" && value != "none")
  188. mexErrMsgIdAndTxt("mexnice:error","Unexpected parameter value for \'optimization_method\'. \'greedy\', \'downhillsimplex\' or \'none\' expected.");
  189. conf.sS("GPHIKRegression", variable, value);
  190. }
  191. if(variable == "transform")
  192. {
  193. string value = MatlabConversion::convertMatlabToString( prhs[i+1] );
  194. if( value != "identity" && value != "absexp" && value != "exp" && value != "MKL" && value != "WeightedDim")
  195. mexErrMsgIdAndTxt("mexnice:error","Unexpected parameter value for \'transform\'. \'identity\', \'absexp\', \'exp\' , \'MKL\' or \'WeightedDim\' expected.");
  196. conf.sS("GPHIKRegression", variable, value);
  197. }
  198. if(variable == "varianceApproximation")
  199. {
  200. string value = MatlabConversion::convertMatlabToString(prhs[i+1]);
  201. if(value != "approximate_fine" && value != "approximate_rough" && value != "exact" && value != "none")
  202. mexErrMsgIdAndTxt("mexnice:error","Unexpected parameter value for \'varianceApproximation\'. \'approximate_fine\', \'approximate_rough\', \'none\' or \'exact\' expected.");
  203. conf.sS("GPHIKRegression", variable, value);
  204. }
  205. }
  206. return conf;
  207. }
  208. // MAIN MATLAB FUNCTION
  209. void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
  210. {
  211. // get the command string specifying what to do
  212. if (nrhs < 1)
  213. mexErrMsgTxt("No commands and options passed... Aborting!");
  214. if( !mxIsChar( prhs[0] ) )
  215. mexErrMsgTxt("First argument needs to be the command, ie.e, the class method to call... Aborting!");
  216. std::string cmd = MatlabConversion::convertMatlabToString( prhs[0] );
  217. // create object
  218. if ( !strcmp("new", cmd.c_str() ) )
  219. {
  220. // check output variable
  221. if (nlhs != 1)
  222. mexErrMsgTxt("New: One output expected.");
  223. // read config settings
  224. NICE::Config conf = parseParametersGPHIKRegression(prhs+1,nrhs-1);
  225. // create class instance
  226. NICE::GPHIKRegression * regressor = new NICE::GPHIKRegression ( &conf, "GPHIKRegression" /*sectionName in config*/ );
  227. // handle to the C++ instance
  228. plhs[0] = MatlabConversion::convertPtr2Mat<NICE::GPHIKRegression>( regressor );
  229. return;
  230. }
  231. // in all other cases, there should be a second input,
  232. // which the be the class instance handle
  233. if (nrhs < 2)
  234. mexErrMsgTxt("Second input should be a class instance handle.");
  235. // delete object
  236. if ( !strcmp("delete", cmd.c_str() ) )
  237. {
  238. // Destroy the C++ object
  239. MatlabConversion::destroyObject<NICE::GPHIKRegression>(prhs[1]);
  240. return;
  241. }
  242. // get the class instance pointer from the second input
  243. // every following function needs the regressor object
  244. NICE::GPHIKRegression * regressor = MatlabConversion::convertMat2Ptr<NICE::GPHIKRegression>(prhs[1]);
  245. ////////////////////////////////////////
  246. // Check which class method to call //
  247. ////////////////////////////////////////
  248. // standard train - assumes initialized object
  249. if (!strcmp("train", cmd.c_str() ))
  250. {
  251. // Check parameters
  252. if (nlhs < 0 || nrhs < 4)
  253. {
  254. mexErrMsgTxt("Train: Unexpected arguments.");
  255. }
  256. //------------- read the data --------------
  257. std::vector< const NICE::SparseVector *> examplesTrain;
  258. NICE::Vector yValuesTrain;
  259. if ( mxIsSparse( prhs[2] ) )
  260. {
  261. examplesTrain = MatlabConversion::convertSparseMatrixToNice( prhs[2] );
  262. }
  263. else
  264. {
  265. NICE::Matrix dataTrain;
  266. dataTrain = MatlabConversion::convertDoubleMatrixToNice(prhs[2]);
  267. //----------------- convert data to sparse data structures ---------
  268. examplesTrain.resize( dataTrain.rows() );
  269. std::vector< const NICE::SparseVector *>::iterator exTrainIt = examplesTrain.begin();
  270. for (int i = 0; i < (int)dataTrain.rows(); i++, exTrainIt++)
  271. {
  272. *exTrainIt = new NICE::SparseVector( dataTrain.getRow(i) );
  273. }
  274. }
  275. yValuesTrain = MatlabConversion::convertDoubleVectorToNice(prhs[3]);
  276. //----------------- train our regressor -------------
  277. regressor->train ( examplesTrain , yValuesTrain );
  278. //----------------- clean up -------------
  279. for(int i=0;i<examplesTrain.size();i++)
  280. delete examplesTrain[i];
  281. return;
  282. }
  283. // perform regression
  284. if ( !strcmp("estimate", cmd.c_str() ) )
  285. {
  286. // Check parameters
  287. if ( (nlhs < 0) || (nrhs < 2) )
  288. {
  289. mexErrMsgTxt("Test: Unexpected arguments.");
  290. }
  291. //------------- read the data --------------
  292. double result;
  293. double uncertainty;
  294. if ( mxIsSparse( prhs[2] ) )
  295. {
  296. NICE::SparseVector * example;
  297. example = new NICE::SparseVector ( MatlabConversion::convertSparseVectorToNice( prhs[2] ) );
  298. regressor->estimate ( example, result, uncertainty );
  299. //----------------- clean up -------------
  300. delete example;
  301. }
  302. else
  303. {
  304. NICE::Vector * example;
  305. example = new NICE::Vector ( MatlabConversion::convertDoubleVectorToNice(prhs[2]) );
  306. regressor->estimate ( example, result, uncertainty );
  307. //----------------- clean up -------------
  308. delete example;
  309. }
  310. // output
  311. plhs[0] = mxCreateDoubleScalar( result );
  312. if(nlhs >= 2)
  313. {
  314. plhs[1] = mxCreateDoubleScalar( uncertainty );
  315. }
  316. return;
  317. }
  318. // Uncertainty prediction
  319. if ( !strcmp("uncertainty", cmd.c_str() ) )
  320. {
  321. // Check parameters
  322. if ( (nlhs < 0) || (nrhs < 2) )
  323. {
  324. mexErrMsgTxt("Test: Unexpected arguments.");
  325. }
  326. double uncertainty;
  327. //------------- read the data --------------
  328. if ( mxIsSparse( prhs[2] ) )
  329. {
  330. NICE::SparseVector * example;
  331. example = new NICE::SparseVector ( MatlabConversion::convertSparseVectorToNice( prhs[2] ) );
  332. regressor->predictUncertainty( example, uncertainty );
  333. //----------------- clean up -------------
  334. delete example;
  335. }
  336. else
  337. {
  338. NICE::Vector * example;
  339. example = new NICE::Vector ( MatlabConversion::convertDoubleVectorToNice(prhs[2]) );
  340. regressor->predictUncertainty( example, uncertainty );
  341. //----------------- clean up -------------
  342. delete example;
  343. }
  344. // output
  345. plhs[0] = mxCreateDoubleScalar( uncertainty );
  346. return;
  347. }
  348. // Test - evaluate regressor on whole test set
  349. if ( !strcmp("testL2loss", cmd.c_str() ) )
  350. {
  351. // Check parameters
  352. if (nlhs < 0 || nrhs < 3)
  353. mexErrMsgTxt("Test: Unexpected arguments.");
  354. //------------- read the data --------------
  355. bool dataIsSparse ( mxIsSparse( prhs[2] ) );
  356. std::vector< const NICE::SparseVector *> dataTest_sparse;
  357. NICE::Matrix dataTest_dense;
  358. if ( dataIsSparse )
  359. {
  360. dataTest_sparse = MatlabConversion::convertSparseMatrixToNice( prhs[2] );
  361. }
  362. else
  363. {
  364. dataTest_dense = MatlabConversion::convertDoubleMatrixToNice(prhs[2]);
  365. }
  366. NICE::Vector yValuesTest;
  367. yValuesTest = MatlabConversion::convertDoubleVectorToNice(prhs[3]);
  368. int i_numTestSamples ( yValuesTest.size() );
  369. double l2loss ( 0.0 );
  370. NICE::Vector scores;
  371. NICE::Vector::iterator itScores;
  372. if ( nlhs >= 2 )
  373. {
  374. scores.resize( i_numTestSamples );
  375. itScores = scores.begin();
  376. }
  377. // ------------------------------------------
  378. // ------------- REGRESSION --------------
  379. // ------------------------------------------
  380. NICE::Timer t;
  381. double testTime (0.0);
  382. for (int i = 0; i < i_numTestSamples; i++)
  383. {
  384. //----------------- convert data to sparse data structures ---------
  385. double result;
  386. if ( dataIsSparse )
  387. {
  388. // and perform regression
  389. t.start();
  390. regressor->estimate( dataTest_sparse[ i ], result);
  391. t.stop();
  392. testTime += t.getLast();
  393. }
  394. else
  395. {
  396. NICE::Vector example ( dataTest_dense.getRow(i) );
  397. // and perform regression
  398. t.start();
  399. regressor->estimate( &example, result );
  400. t.stop();
  401. testTime += t.getLast();
  402. }
  403. l2loss += pow ( yValuesTest[i] - result, 2);
  404. if ( nlhs >= 2 )
  405. {
  406. *itScores = result;
  407. itScores++;
  408. }
  409. }
  410. std::cerr << "Time for testing: " << testTime << std::endl;
  411. // clean up
  412. if ( dataIsSparse )
  413. {
  414. for ( std::vector<const NICE::SparseVector *>::iterator it = dataTest_sparse.begin(); it != dataTest_sparse.end(); it++)
  415. delete *it;
  416. }
  417. plhs[0] = mxCreateDoubleScalar( l2loss );
  418. if(nlhs >= 2)
  419. plhs[1] = MatlabConversion::convertVectorFromNice(scores);
  420. return;
  421. }
  422. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  423. // interface specific methods for incremental extensions
  424. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  425. // addExample
  426. if ( !strcmp("addExample", cmd.c_str() ) )
  427. {
  428. // Check parameters
  429. if ( (nlhs < 0) || (nrhs < 4) )
  430. {
  431. mexErrMsgTxt("Test: Unexpected arguments.");
  432. }
  433. //------------- read the data --------------
  434. NICE::SparseVector * newExample;
  435. double newLabel;
  436. if ( mxIsSparse( prhs[2] ) )
  437. {
  438. newExample = new NICE::SparseVector ( MatlabConversion::convertSparseVectorToNice( prhs[2] ) );
  439. }
  440. else
  441. {
  442. NICE::Vector * example;
  443. example = new NICE::Vector ( MatlabConversion::convertDoubleVectorToNice(prhs[2]) );
  444. newExample = new NICE::SparseVector ( *example );
  445. //----------------- clean up -------------
  446. delete example;
  447. }
  448. newLabel = MatlabConversion::convertMatlabToDouble( prhs[3] );
  449. // setting performOptimizationAfterIncrement is optional
  450. if ( nrhs > 4 )
  451. {
  452. bool performOptimizationAfterIncrement;
  453. performOptimizationAfterIncrement = MatlabConversion::convertMatlabToBool( prhs[4] );
  454. regressor->addExample ( newExample, newLabel, performOptimizationAfterIncrement );
  455. }
  456. else
  457. {
  458. regressor->addExample ( newExample, newLabel );
  459. }
  460. //----------------- clean up -------------
  461. delete newExample;
  462. return;
  463. }
  464. // addMultipleExamples
  465. if ( !strcmp("addMultipleExamples", cmd.c_str() ) )
  466. {
  467. // Check parameters
  468. if ( (nlhs < 0) || (nrhs < 4) )
  469. {
  470. mexErrMsgTxt("Test: Unexpected arguments.");
  471. }
  472. //------------- read the data --------------
  473. std::vector< const NICE::SparseVector *> newExamples;
  474. NICE::Vector newLabels;
  475. if ( mxIsSparse( prhs[2] ) )
  476. {
  477. newExamples = MatlabConversion::convertSparseMatrixToNice( prhs[2] );
  478. }
  479. else
  480. {
  481. NICE::Matrix newData;
  482. newData = MatlabConversion::convertDoubleMatrixToNice(prhs[2]);
  483. //----------------- convert data to sparse data structures ---------
  484. newExamples.resize( newData.rows() );
  485. std::vector< const NICE::SparseVector *>::iterator exTrainIt = newExamples.begin();
  486. for (int i = 0; i < (int)newData.rows(); i++, exTrainIt++)
  487. {
  488. *exTrainIt = new NICE::SparseVector( newData.getRow(i) );
  489. }
  490. }
  491. newLabels = MatlabConversion::convertDoubleVectorToNice(prhs[3]);
  492. // setting performOptimizationAfterIncrement is optional
  493. if ( nrhs > 4 )
  494. {
  495. bool performOptimizationAfterIncrement;
  496. performOptimizationAfterIncrement = MatlabConversion::convertMatlabToBool( prhs[4] );
  497. regressor->addMultipleExamples ( newExamples, newLabels, performOptimizationAfterIncrement );
  498. }
  499. else
  500. {
  501. regressor->addMultipleExamples ( newExamples, newLabels );
  502. }
  503. //----------------- clean up -------------
  504. for ( std::vector< const NICE::SparseVector *>::iterator exIt = newExamples.begin();
  505. exIt != newExamples.end(); exIt++
  506. )
  507. {
  508. delete *exIt;
  509. }
  510. return;
  511. }
  512. ///////////////////// INTERFACE PERSISTENT /////////////////////
  513. // interface specific methods for store and restore
  514. ///////////////////// INTERFACE PERSISTENT /////////////////////
  515. // store the regressor to an external file
  516. if ( !strcmp("store", cmd.c_str() ) || !strcmp("save", cmd.c_str() ) )
  517. {
  518. // Check parameters
  519. if ( nrhs < 3 )
  520. mexErrMsgTxt("store: no destination given.");
  521. std::string s_destination = MatlabConversion::convertMatlabToString( prhs[2] );
  522. std::filebuf fb;
  523. fb.open ( s_destination.c_str(), ios::out );
  524. std::ostream os(&fb);
  525. //
  526. regressor->store( os );
  527. //
  528. fb.close();
  529. return;
  530. }
  531. // load regressor from external file
  532. if ( !strcmp("restore", cmd.c_str() ) || !strcmp("load", cmd.c_str() ) )
  533. {
  534. // Check parameters
  535. if ( nrhs < 3 )
  536. mexErrMsgTxt("restore: no destination given.");
  537. std::string s_destination = MatlabConversion::convertMatlabToString( prhs[2] );
  538. std::cerr << " aim at restoring the regressor from " << s_destination << std::endl;
  539. std::filebuf fbIn;
  540. fbIn.open ( s_destination.c_str(), ios::in );
  541. std::istream is (&fbIn);
  542. //
  543. regressor->restore( is );
  544. //
  545. fbIn.close();
  546. return;
  547. }
  548. // Got here, so command not recognized
  549. std::string errorMsg (cmd.c_str() );
  550. errorMsg += " -- command not recognized.";
  551. mexErrMsgTxt( errorMsg.c_str() );
  552. }
  553. #endif