PLearn 0.1
VPLPreprocessedLearner.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // VPLPreprocessedLearner.h
00004 //
00005 // Copyright (C) 2005 Pascal Vincent 
00006 // 
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 // 
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 // 
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 // 
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 // 
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 /* *******************************************************      
00036  * $Id: VPLPreprocessedLearner.h 7042 2007-05-09 23:44:20Z saintmlx $ 
00037  ******************************************************* */
00038 
00039 // Authors: Pascal Vincent
00040 
00044 #ifndef VPLPreprocessedLearner_INC
00045 #define VPLPreprocessedLearner_INC
00046 
00047 #include <plearn_learners/generic/PLearner.h>
00048 #include <plearn/vmat/VMatLanguage.h>
00049 
00050 namespace PLearn {
00051 
00052 class VPLPreprocessedLearner: public PLearner
00053 {
00054 
00055 private:
00056 
00057     typedef PLearner inherited;
00058   
00059 protected:
00060 
00061     // *********************
00062     // * protected options *
00063     // *********************
00064 
00065     // ### declare protected option fields (such as learnt parameters) here
00066     PP<VMatLanguage> row_prg;
00067     PP<VMatLanguage> input_prg;
00068     PP<VMatLanguage> output_prg;
00069     PP<VMatLanguage> costs_prg;
00070 
00071     TVec<string> row_prg_fieldnames; 
00072     TVec<string> input_prg_fieldnames;
00073     TVec<string> output_prg_fieldnames;
00074     TVec<string> costs_prg_fieldnames;
00075 
00076     mutable Vec row;
00077     mutable Vec processed_row;
00078     mutable Vec processed_input;
00079     mutable Vec pre_output;
00080     mutable Vec pre_costs;
00081     
00082 public:
00083 
00084     // ************************
00085     // * public build options *
00086     // ************************
00087 
00089     PP<PLearner> learner_;
00090 
00091     string trainset_preproc; // program string in VPL language to be applied to each row of the training set
00092     int newtargetsize;
00093     int newweightsize;
00094     int newextrasize;
00095 
00096     string input_preproc; // program string in VPL language to be applied to an input 
00097     string output_postproc;
00098     string costs_postproc;
00099   
00100     // ****************
00101     // * Constructors *
00102     // ****************
00103 
00105     // (Make sure the implementation in the .cc
00106     // initializes all fields to reasonable default values)
00107     VPLPreprocessedLearner();
00108 
00109 
00110     // ********************
00111     // * PLearner methods *
00112     // ********************
00113 
00114 private: 
00115 
00117     // (Please implement in .cc)
00118     void build_();
00119 
00120 protected: 
00121   
00123     // (Please implement in .cc)
00124     static void declareOptions(OptionList& ol);
00125 
00126 public:
00127 
00128     // ************************
00129     // **** Object methods ****
00130     // ************************
00131 
00133     virtual void build();
00134 
00136     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00137 
00138     // Declares other standard object methods.
00139     // If your class is not instantiatable (it has pure virtual methods)
00140     // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT.
00141     PLEARN_DECLARE_OBJECT(VPLPreprocessedLearner);
00142 
00143 
00144     // **************************
00145     // **** PLearner methods ****
00146     // **************************
00147 
00148     virtual int outputsize() const;
00149 
00150     
00152     virtual void setValidationSet(VMat validset);
00153 
00155     virtual void setTrainStatsCollector(PP<VecStatsCollector> statscol);
00156 
00158     virtual void setExperimentDirectory(const PPath& the_expdir);
00159  
00161     virtual void forget();
00162 
00163     virtual void setTrainingSet(VMat training_set, bool call_forget=true);
00164 
00165     virtual void train();
00166 
00167     virtual void computeOutput(const Vec& input, Vec& output) const;
00168 
00169     virtual void computeOutputAndCosts(const Vec& input, const Vec& target, 
00170                                        Vec& output, Vec& costs) const;
00171 
00172     virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 
00173                                          const Vec& target, Vec& costs) const;
00174 
00175     virtual
00176     bool computeConfidenceFromOutput(const Vec& input, const Vec& output,
00177                                      real probability,
00178                                      TVec< pair<real,real> >& intervals) const;
00179 
00182     virtual TVec<string> getOutputNames() const;
00183 
00184     virtual TVec<std::string> getTestCostNames() const;
00185 
00187     virtual TVec<string> getTrainCostNames() const;
00188 
00190     virtual void resetInternalState();
00191 
00193     virtual bool isStatefulLearner() const;
00194 };
00195 
00196 // Declares a few other classes and functions related to this class.
00197 DECLARE_OBJECT_PTR(VPLPreprocessedLearner);
00198   
00199 } // end of namespace PLearn
00200 
00201 #endif
00202 
00203 
00204 /*
00205   Local Variables:
00206   mode:c++
00207   c-basic-offset:4
00208   c-file-style:"stroustrup"
00209   c-file-offsets:((innamespace . 0)(inline-open . 0))
00210   indent-tabs-mode:nil
00211   fill-column:79
00212   End:
00213 */
00214 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines