PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 00007 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 00038 00039 /* ******************************************************* 00040 * $Id: Gnuplot.h 8230 2007-11-07 20:48:13Z nouiz $ 00041 * AUTHORS: Pascal Vincent & Yoshua Bengio 00042 * This file is part of the PLearn library. 00043 ******************************************************* */ 00044 00045 00048 #ifndef GNUPLOT_INC 00049 #define GNUPLOT_INC 00050 00051 #include <plearn/io/PStream.h> 00052 #include <plearn/math/Mat.h> 00053 #include <plearn/io/TmpFilenames.h> 00054 #include <plearn/base/Array.h> 00055 00056 namespace PLearn { 00057 using namespace std; 00058 00059 00060 class Gnuplot 00061 { 00062 protected: 00063 TmpFilenames tmpfilenames; 00064 FILE* gp_cstream; 00065 PStream tognuplot; 00066 00067 public: 00068 Gnuplot(int max_nb_plot=20); 00069 Gnuplot(const Vec& v1, const string& opt1); 00070 Gnuplot(const Vec& v1, const string& opt1, const Vec& v2, const string& opt2); 00071 Gnuplot(const Vec& v1, const string& opt1, const Vec& v2, const string& opt2, const Vec& v3, const string& opt3); 00072 00073 ~Gnuplot(); 00074 00075 PStream& operator<<(const string& str); 00076 void flush(); 00077 00078 void setxrange(real xmin, real xmax); 00079 void setyrange(real ymin, real ymax); 00080 void setrange(real xmin, real xmax, real ymin, real ymax); 00081 void seteps(const string &filename); 00082 00083 void plot(const Vec& v1, const string& opt1=""); 00084 void plot(const Vec& v1, const string& opt1, const Vec& v2, const string& opt2); 00085 void plot(const Vec& v1, const Vec&v2) { plot(v1,"",v2,""); } 00086 void plot(const Vec& v1, const string& opt1, const Vec& v2, const string& opt2, const Vec& v3, const string& opt3); 00087 void plot(const Vec& v1, const Vec&v2, const Vec& v3) { plot(v1,"",v2,"",v3,""); } 00088 void plot(const Vec& v1, const string& opt1, const Vec& v2, const string& opt2, const Vec& v3, const string& opt3, const Vec& v4, const string& opt4); 00089 void plot(const Vec& v1, const Vec&v2, const Vec& v3, const Vec& v4) { plot(v1,"",v2,"",v3,"",v4,""); } 00090 void plot(const Mat& m1, const string& opt1=""); 00091 void plot(const Mat& m1, const string& opt1, const Mat& m2, const string& opt2); 00092 void plot(const Mat& m1, const string& opt1, const Mat& m2, const string& opt2, const Mat& m3, const string& opt3); 00093 void plot(const Mat& m1, const string& opt1, const Mat& m2, const string& opt2, const Mat& m3, const string& opt3, const Mat& m4, const string& opt4); 00094 void plot(const Mat& m1, const string& opt1, const Mat& m2, const string& opt2, const Mat& m3, const string& opt3, 00095 const Mat& m4, const string& opt4, const Mat& m5, const string& opt5); 00096 void plot(const Mat& m1, const string& opt1, const Mat& m2, const string& opt2, const Mat& m3, const string& opt3, 00097 const Mat& m4, const string& opt4, const Mat& m5, const string& opt5, const Mat& m6, const string& opt6); 00098 00099 // m must have 3 columns, with the 3rd column containing class numbers 00100 // all points (x,y) will be plotted, with a different color and shape for each class 00101 void plotClasses(const Mat& m); 00102 00103 void multiplot(vector<Mat *> &ms, vector <string> &opts); 00104 void plot3d(const Mat &m1, const string &opt1=""); 00105 00106 void plotcdf(Vec feature, const string& title="cdf"); 00107 void plotcdf(const Array<Vec>& vecarray, const Array<string>& titlearray); 00108 void plotdensity(Vec feature, const string& title, int halfwindowsize, string range=""); 00109 void plotdensity(const Array<Vec>& vecarray, const Array<string>& titlearray, int halfwindowsize); 00110 00111 void histoplot(Vec feature, real minval, real maxval, int nbins, bool do_normalize=false, char* title="histogram"); 00112 00113 void histoplot(Vec feature, Vec classnums, real minval, real maxval, int nbins, bool do_normalize=false); 00114 00119 void featureplot(Mat inputs, Vec classnums, char* withwhat="points"); 00120 00121 void featureplot(Mat dataset, char* withwhat="points") 00122 { 00123 featureplot(dataset.subMatColumns(0,dataset.width()-1), 00124 dataset.lastColumn().toVecCopy(), withwhat); 00125 } 00126 00127 // export as postscript file 00128 void export_ps(string psfname, string psoptions="eps color"); 00129 00130 }; 00131 00132 } // end of namespace PLearn 00133 00134 #endif