PLearn 0.1
|
00001 // PLearn (A C++ Machine Learning Library) 00002 // Copyright (C) 1998 Pascal Vincent 00003 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00004 // 00005 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // 00009 // 1. Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // 00012 // 2. Redistributions in binary form must reproduce the above copyright 00013 // notice, this list of conditions and the following disclaimer in the 00014 // documentation and/or other materials provided with the distribution. 00015 // 00016 // 3. The name of the authors may not be used to endorse or promote 00017 // products derived from this software without specific prior written 00018 // permission. 00019 // 00020 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00021 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00022 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00023 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00025 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 // 00031 // This file is part of the PLearn library. For more information on the PLearn 00032 // library, go to the PLearn Web site at www.plearn.org 00033 00034 00035 00036 00037 /* ******************************************************* 00038 * $Id: MatlabInterface.h 8241 2007-11-09 20:12:36Z nouiz $ 00039 * AUTHORS: Christian Jauvin 00040 * This file is part of the PLearn library. 00041 ******************************************************* */ 00042 00043 00046 #ifndef MATLAB_INTERFACE_INC 00047 #define MATLAB_INTERFACE_INC 00048 00049 //#include <stdlib.h> 00050 //#include "stringutils.h" 00051 #include <plearn/sys/Popen.h> 00052 #include <plearn/math/RowMapSparseMatrix.h> 00053 #include <nspr/prenv.h> 00054 00055 namespace PLearn { 00056 using namespace std; 00057 00136 class MatlabInterface 00137 { 00138 00139 public: 00140 00143 static string path() 00144 { 00145 const char* plearndir = PR_GetEnv("PLEARNDIR"); 00146 if(!plearndir) 00147 PLERROR("PLEARNDIR environment variable not defined"); 00148 return string(plearndir)+"/Contrib/matlab/"; 00149 } 00150 00180 MatlabInterface(string matlab_file_header, string matlab_file = "", string id = "", 00181 bool launch_in_background = false, bool erase_tmp_files = true); 00182 00183 MatlabInterface(vector<string> matlab_file_header, string 00184 matlab_file = "", string id = "", 00185 bool launch_in_background = false, bool erase_tmp_files = true); 00186 00203 Popen* launch(); 00204 00211 bool launchAndWaitFor(string matlab_end_answer); 00212 00214 Popen* matlab; 00215 00217 string matlab_file; 00218 00221 string matlab_file_header; 00222 00223 //eigs_r11 routine (see below). 00224 static void eigs_r11(RowMapSparseMatrix<real>& A, 00225 Mat& evectors, 00226 int d, 00227 string which_eigenvalues, 00228 bool erase_tmp_files = true); 00229 00230 static void eigs_r11(RowMapSparseMatrix<real>& A, 00231 Vec& evalues, 00232 int d, 00233 string which_eigenvalues, 00234 bool erase_tmp_files = true); 00235 00236 static void eigs_r11(RowMapSparseMatrix<real>& A, 00237 Mat& evectors, 00238 Vec& evalues, 00239 int d, 00240 string which_eigenvalues, 00241 bool erase_tmp_files = true); 00242 00243 protected: 00244 00246 string id; 00247 00249 bool launch_in_background; 00250 00251 bool erase_tmp_files; 00252 00253 }; 00254 00274 void matlabR11eigs(RowMapSparseMatrix<double>& A, Mat eigen_vectors, 00275 Vec eigen_values, string which_eigenvalues="LM"); 00276 00277 00278 } // end of namespace PLearn 00279 00280 #endif