PLearn 0.1
SequentialValidation.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // SequentialValidation.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_VALIDATION
00039 #define SEQUENTIAL_VALIDATION
00040 
00041 #include <plearn/base/PP.h>
00042 #include <plearn/base/Object.h>
00043 #include <plearn/vmat/VMat.h>
00044 #include <plearn/math/VecStatsCollector.h>
00045 #include <plearn/io/PPath.h>
00046 #include <plearn_learners/testers/PTester.h>  // for using class StatSpec
00047 #include <plearn_learners/generic/StatefulLearner.h>
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00052 
00053 class SequentialValidation: public Object
00054 {
00055     typedef Object inherited;
00056 
00057 protected:
00058     //#####  Data members required for simulation  ############################
00059 
00061     PP<VecStatsCollector> train_stats;
00062 
00064     PP<VecStatsCollector> accessory_train_stats;
00065   
00067     PP<VecStatsCollector> test_stats;
00068 
00070     PP<VecStatsCollector> sequence_stats;
00071 
00073     PP<VecStatsCollector> timewise_stats;
00074   
00075     // Contains pointers to train_stats and test_stats
00076     TVec< PP<VecStatsCollector> > stcol;
00077 
00079     TVec<StatSpec> statspecs;
00080 
00082     TVec<StatSpec> timewise_statspecs;
00083   
00085     VMat global_stats_vm;
00086 
00088     VMat split_stats_vm;
00089 
00091     VMat timewise_stats_vm; 
00092 
00094     Vec input, target;
00095     Vec dummy_output;                          
00096     Vec dummy_costs;                           
00097     Vec output;
00098     Vec costs;
00099   
00100 public:
00101   
00102     // *********************
00103     // * public options    *
00104     // *********************
00105     
00107     int init_train_size;
00108 
00118     int warmup_size;
00119     
00122     int train_step;
00123   
00125     int last_test_time;
00126   
00128     VMat dataset;
00129 
00131     PP<StatefulLearner> learner;
00132 
00136     TVec< PP<StatefulLearner> > accessory_learners;
00137   
00139     TVec<string> statnames;
00140 
00142     TVec<string> timewise_statnames;
00143 
00145     PPath expdir;
00146   
00147     bool report_stats;
00148     bool save_final_model;
00149     bool save_initial_model;
00150     bool save_initial_seqval;
00151     bool save_data_sets;
00152     bool save_test_outputs;
00153     bool save_test_costs;
00154     bool save_stat_collectors;
00155     bool provide_learner_expdir; /* =true */
00156 
00160     bool save_sequence_stats;
00161 
00167     bool report_memory_usage;
00168 
00178     TVec< pair<string,string> > measure_after_train;
00179 
00182     TVec< pair<string,string> > measure_after_test;
00183   
00184 private:
00185 
00187     void build_();
00188 
00189 protected:
00190 
00192     static void declareOptions(OptionList& ol);
00193 
00195     virtual void reportStats(const Vec& global_result);
00196 
00198     virtual void reportMemoryUsage(int t);
00199 
00203     virtual bool shouldTrain(int t);
00204   
00207     virtual VMat trainVMat(int t);
00208 
00211     virtual VMat testVMat(int t);
00212 
00214     virtual int maxTimeStep() const;
00215 
00218     virtual void measureOptions(const TVec< pair<string,string> >& options,
00219                                 PPath where_to_save);
00220   
00221 public:
00222 
00224     SequentialValidation();
00225   
00227     virtual void build();
00228   
00229     virtual void setExperimentDirectory(const PPath& _expdir);
00230 
00232     virtual void run();
00233 
00235     virtual void warmupModel(int warmup_size);
00236 
00239     virtual void setTestStartTime(int test_start_time, bool call_build = true);
00240 
00242     virtual void createStatCollectors();
00243 
00245     virtual void createStatSpecs();
00246   
00248     virtual void createStatVMats();
00249 
00251     virtual void trainLearners(VMat training_set);
00252 
00255     virtual void testLearners(VMat test_set);
00256   
00259     void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00260   
00261     PLEARN_DECLARE_OBJECT(SequentialValidation);
00262 };
00263   
00265 DECLARE_OBJECT_PTR(SequentialValidation);
00266 
00267 } // end of namespace PLearn
00268 
00269 #endif
00270 
00271 
00272 /*
00273   Local Variables:
00274   mode:c++
00275   c-basic-offset:4
00276   c-file-style:"stroustrup"
00277   c-file-offsets:((innamespace . 0)(inline-open . 0))
00278   indent-tabs-mode:nil
00279   fill-column:79
00280   End:
00281 */
00282 // 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