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 // Copyright (C) 2004 ApSTAT Technologies Inc. 00007 // 00008 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are met: 00011 // 00012 // 1. Redistributions of source code must retain the above copyright 00013 // notice, this list of conditions and the following disclaimer. 00014 // 00015 // 2. Redistributions in binary form must reproduce the above copyright 00016 // notice, this list of conditions and the following disclaimer in the 00017 // documentation and/or other materials provided with the distribution. 00018 // 00019 // 3. The name of the authors may not be used to endorse or promote 00020 // products derived from this software without specific prior written 00021 // permission. 00022 // 00023 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00024 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00025 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00026 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00028 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00029 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00030 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00031 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00032 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 // 00034 // This file is part of the PLearn library. For more information on the PLearn 00035 // library, go to the PLearn Web site at www.plearn.org 00036 00037 00038 00039 00040 /* ******************************************************* 00041 * $Id: DisplayUtils.h 8230 2007-11-07 20:48:13Z nouiz $ 00042 * AUTHORS: Pascal Vincent & Yoshua Bengio 00043 * This file is part of the PLearn library. 00044 ******************************************************* */ 00045 00046 00049 #ifndef DISPLAYUTILS_INC 00050 #define DISPLAYUTILS_INC 00051 00052 #include <plearn_learners/generic/PLearner.h> 00053 #include "GhostScript.h" 00054 #include <plearn/math/Mat.h> 00055 #include "Gnuplot.h" 00056 #include <plearn/var/Func.h> 00057 00058 namespace PLearn { 00059 using namespace std; 00060 00061 00062 00069 void scores_to_winners(Mat scores, Mat& winners); 00070 00071 void color_luminance_to_rgb(int colornum, real luminance, real& r, real& g, real& b); 00072 00073 real color_luminance_to_rgbreal(int colornum, real luminance); 00074 00075 void color_luminance_to_rgbreal(Vec colornum, Vec luminance, Vec& rgbreal); 00076 00077 void transform_perclass_values_into_luminance(Vec classnums, const Vec& values, int ndiscretevals); 00078 00079 void regulargrid_x_y_rgbreal_to_bitmap(Mat& regulargrid_x_y_rgbreal, 00080 Mat& bm, real& xlow, real& xhigh, real& ylow, real& yhigh); 00081 00082 void regulargrid_x_y_outputs_to_bitmap(Mat regulargrid_x_y_outputs, bool output_margin, int ndiscretevals, 00083 Mat& bm, real& xlow, real& xhigh, real& ylow, real& yhigh); 00084 00085 00086 00098 void displayHistogram(Gnuplot& gs, Mat dataColumn, 00099 int n_bins=0, Vec* bins=0, 00100 bool regular_bins=false, 00101 bool normalized=false, string extra_args=""); 00102 00103 00106 void displayVarGraph(const VarArray& outputs, bool display_values=false, real boxwidth=100, const char* the_filename=0, bool must_wait=true, VarArray display0_only_these=VarArray()); 00107 void displayFunction(Func f, bool display_values=false, bool display_differentiation=false, real boxwidth=100, const char* the_filename=0, bool must_wait=true); 00108 00109 00110 00111 /* This will return a length*width matrix containing the computed outputs 00112 for a learner which has 2 dimensional input, where the inputs are 00113 taken on a regular grid ranging [min_x,max_x]x[min_y,max_y]. The 00114 mapping to the matrix m is m(i,j) = 00115 f(min_x+i*(max_x-min_x)/(length-1), min_y+j*(max_y-min_y)/(width-1)) 00116 If the output is of length 1: (class depends on which side of the threshold we are) 00117 the result put in m is output[0] - singleoutput_threshold 00118 If the output is of length 2: (score for each class) 00119 the result put in m is output[0]-output[1] 00120 */ 00121 Mat compute2dGridOutputs(PP<PLearner> learner, real min_x=-1, real max_x=+1, real min_y=-1, real max_y=+1, 00122 int length=200, int width=200, real singleoutput_threshold=0.); 00123 00124 00125 00127 void displayPoints(GhostScript& gs, Mat data, real radius, bool color=false); 00128 00134 void displayDecisionSurface(GhostScript& gs, real destx, real desty, real destwidth, real destheight, 00135 PP<PLearner> learner, Mat trainset, 00136 Vec svindexes=Vec(), Vec outlierindexes=Vec(), int nextsvindex=-1, 00137 real min_x=-1, real max_x=+1, real min_y=-1, real max_y=+1, 00138 real radius=0.05, 00139 int nx=200, int ny=200); 00140 00141 } // end of namespace PLearn 00142 00143 #endif 00144