Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

SequentialLearner.h

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // SequentialLearner.h 00004 // 00005 // Copyright (C) 2003 Rejean Ducharme, Yoshua Bengio 00006 // Copyright (C) 2003 Pascal Vincent 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 #ifndef SEQUENTIAL_LEARNER 00039 #define SEQUENTIAL_LEARNER 00040 00041 #include <plearn_learners/generic/PLearner.h> 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00057 class SequentialLearner: public PLearner 00058 { 00059 public: 00060 typedef PLearner inherited; 00061 00062 protected: 00063 int last_train_t; 00064 int last_call_train_t; 00065 mutable int last_test_t; 00066 00067 public: 00068 int get_last_train_t(){ return last_train_t; } 00069 int get_last_call_train_t(){ return last_call_train_t; } 00070 int get_last_test_t(){ return last_test_t; } 00071 00072 public: 00073 00078 int init_train_size; 00079 int max_seq_len; 00080 int max_train_len; 00081 int train_step; 00082 int horizon; 00083 int outputsize_; 00084 00087 Mat predictions; 00088 00089 Mat errors; 00090 00091 private: 00093 void build_(); 00094 00095 protected: 00097 static void declareOptions(OptionList& ol); 00098 00099 public: 00100 00102 SequentialLearner(); 00103 00105 virtual void build(); 00106 00108 virtual int outputsize() const; 00109 00110 virtual int nTestCosts() const; 00111 00112 virtual void setTrainingSet(VMat training_set, bool call_forget=true); 00113 00123 virtual void train() =0; 00124 00131 virtual void test(VMat testset, PP<VecStatsCollector> test_stats, 00132 VMat testoutputs=0, VMat testcosts=0) const =0; 00133 00134 virtual void computeOutputAndCosts(const Vec& input, const Vec& target, 00135 Vec& output, Vec& costs) const; 00136 00137 virtual void computeCostsOnly(const Vec& input, const Vec& target, 00138 Vec& costs) const; 00139 00140 virtual void computeOutput(const Vec& input, Vec& output) const; 00141 00142 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00143 const Vec& target, Vec& costs) const; 00144 00151 int sequenceStart() const { return init_train_size; } 00152 int sequenceLength() const { return last_test_t - init_train_size + 1; } 00153 Vec getCostSequence(int cost_index) const 00154 { return errors.subMat(sequenceStart(), cost_index, sequenceLength(), 1).toVecCopy(); } 00155 Vec getCostSequence(string cname) const 00156 { return getCostSequence(getTestCostIndex(cname)); } 00157 00163 virtual void matlabSave(const string& matlab_subdir); 00164 00165 virtual void forget(); 00166 00169 PLEARN_DECLARE_ABSTRACT_OBJECT(SequentialLearner); 00170 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00171 }; 00172 00174 DECLARE_OBJECT_PTR(SequentialLearner); 00175 00176 } // end of namespace PLearn 00177 00178 #endif

Generated on Tue Aug 17 16:05:16 2004 for PLearn by doxygen 1.3.7