PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // VPLProcessor.h 00004 // 00005 // Copyright (C) 2005, 2006 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: VPLProcessor.h 5480 2006-05-03 18:57:39Z plearner $ 00037 ******************************************************* */ 00038 00039 // Authors: Pascal Vincent 00040 00044 #ifndef VPLProcessor_INC 00045 #define VPLProcessor_INC 00046 00047 #include <plearn_learners/generic/PLearner.h> 00048 #include <plearn/vmat/VMatLanguage.h> 00049 00050 namespace PLearn { 00051 00052 class VPLProcessor: public PLearner 00053 { 00054 00055 private: 00056 00057 typedef PLearner inherited; 00058 00059 protected: 00060 00061 VMatLanguage input_prg_; 00062 00063 TVec<string> input_prg_fieldnames; 00064 00065 mutable Vec processed_input; 00066 00067 // ********************* 00068 // * protected options * 00069 // ********************* 00070 00071 TVec<string> orig_fieldnames; // fieldnames of training set 00072 int orig_inputsize; // inputsize of training set 00073 int orig_targetsize; // targetsize of training set 00074 00075 bool use_filtering_prg_for_repeat; 00076 string repeat_id_field_name; // 0, 1, ..., n-1; "" means no field is added 00077 string repeat_count_field_name; // n; "" means no field is added 00078 00079 public: 00080 00081 // ************************ 00082 // * public build options * 00083 // ************************ 00084 00085 00086 string filtering_prg; 00087 00088 string input_prg; 00089 string target_prg; 00090 string weight_prg; 00091 string extra_prg; 00092 00093 // **************** 00094 // * Constructors * 00095 // **************** 00096 00098 // (Make sure the implementation in the .cc 00099 // initializes all fields to reasonable default values) 00100 VPLProcessor(); 00101 00102 00103 // ******************** 00104 // * PLearner methods * 00105 // ******************** 00106 00107 private: 00108 00110 void build_(); 00111 00112 void initializeInputPrograms(); 00113 00114 00115 protected: 00116 00118 // (Please implement in .cc) 00119 static void declareOptions(OptionList& ol); 00120 00121 public: 00122 00123 // ************************ 00124 // **** Object methods **** 00125 // ************************ 00126 00128 virtual void build(); 00129 00131 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00132 00133 // Declares other standard object methods. 00134 // If your class is not instantiatable (it has pure virtual methods) 00135 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT. 00136 PLEARN_DECLARE_OBJECT(VPLProcessor); 00137 00138 00139 // ************************** 00140 // **** PLearner methods **** 00141 // ************************** 00142 00143 virtual int outputsize() const; 00144 00145 00147 virtual void forget(); 00148 00149 virtual void setTrainingSet(VMat training_set, bool call_forget=true); 00150 00151 virtual void computeOutput(const Vec& input, Vec& output) const; 00152 00153 virtual void computeOutputAndCosts(const Vec& input, const Vec& target, 00154 Vec& output, Vec& costs) const; 00155 00156 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00157 const Vec& target, Vec& costs) const; 00158 00161 virtual TVec<string> getOutputNames() const; 00162 00163 00164 virtual VMat processDataSet(VMat dataset) const; 00165 00166 00167 00168 virtual void train(); 00169 virtual TVec<std::string> getTestCostNames() const; 00170 virtual TVec<string> getTrainCostNames() const; 00171 00172 00173 00174 }; 00175 00176 // Declares a few other classes and functions related to this class. 00177 DECLARE_OBJECT_PTR(VPLProcessor); 00178 00179 } // end of namespace PLearn 00180 00181 #endif 00182 00183 00184 /* 00185 Local Variables: 00186 mode:c++ 00187 c-basic-offset:4 00188 c-file-style:"stroustrup" 00189 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00190 indent-tabs-mode:nil 00191 fill-column:79 00192 End: 00193 */ 00194 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :