PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // TorchLearner.h 00004 // 00005 // Copyright (C) 2005 Olivier Delalleau 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: TorchLearner.h 3994 2005-08-25 13:35:03Z chapados $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00044 #ifndef TorchLearner_INC 00045 #define TorchLearner_INC 00046 00047 #include <plearn_learners/generic/PLearner.h> 00048 #include <torch/Machine.h> 00049 #include <torch/Trainer.h> 00050 00051 namespace PLearn { 00052 00053 // Forward declarations. 00054 class TDataSet; 00055 class TMachine; 00056 class TTorchDataSetFromVMat; 00057 class TTrainer; 00058 00059 class TorchLearner: public PLearner { 00060 00061 private: 00062 00063 typedef PLearner inherited; 00064 00065 protected: 00066 00067 // ********************* 00068 // * protected options * 00069 // ********************* 00070 00071 int outputsize_; 00072 00073 // Fields below are not options. 00074 00076 Torch::Allocator* allocator; 00077 00079 Torch::Sequence* inputs; 00080 00082 PP<TTorchDataSetFromVMat> torch_train_set; 00083 00084 public: 00085 00086 // ************************ 00087 // * public build options * 00088 // ************************ 00089 00090 PP<TMachine> machine; 00091 PP<TTrainer> trainer; 00092 00093 // **************** 00094 // * Constructors * 00095 // **************** 00096 00098 TorchLearner(); 00099 00100 // ******************** 00101 // * PLearner methods * 00102 // ******************** 00103 00104 private: 00105 00107 void build_(); 00108 00109 protected: 00110 00112 static void declareOptions(OptionList& ol); 00113 00114 public: 00115 00116 // ************************ 00117 // **** Object methods **** 00118 // ************************ 00119 00121 virtual void build(); 00122 00124 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00125 00126 // Declares other standard object methods. 00127 PLEARN_DECLARE_OBJECT(TorchLearner); 00128 00129 // ************************** 00130 // **** PLearner methods **** 00131 // ************************** 00132 00135 virtual int outputsize() const; 00136 00139 virtual void forget(); 00140 00143 virtual void train(); 00144 00146 virtual void computeOutput(const Vec& input, Vec& output) const; 00147 00149 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00150 const Vec& target, Vec& costs) const; 00151 00153 virtual TVec<std::string> getTestCostNames() const; 00154 00157 virtual TVec<std::string> getTrainCostNames() const; 00158 00160 virtual void setTrainingSet(VMat training_set, bool call_forget = true); 00161 00163 virtual ~TorchLearner(); 00164 00165 // *** SUBCLASS WRITING: *** 00166 // While in general not necessary, in case of particular needs 00167 // (efficiency concerns for ex) you may also want to overload 00168 // some of the following methods: 00169 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const; 00170 // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00171 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const; 00172 // virtual int nTestCosts() const; 00173 // virtual int nTrainCosts() const; 00174 // virtual void resetInternalState(); 00175 // virtual bool isStatefulLearner() const; 00176 00177 }; 00178 00179 // Declares a few other classes and functions related to this class. 00180 DECLARE_OBJECT_PTR(TorchLearner); 00181 00182 } // end of namespace PLearn 00183 00184 #endif 00185 00186 00187 /* 00188 Local Variables: 00189 mode:c++ 00190 c-basic-offset:4 00191 c-file-style:"stroustrup" 00192 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00193 indent-tabs-mode:nil 00194 fill-column:79 00195 End: 00196 */ 00197 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :