PLearn 0.1
PTester.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PTester.h
00004 // 
00005 // Copyright (C) 2002 Pascal Vincent, Frederic Morin
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: PTester.h 10220 2009-05-27 20:40:20Z tihocan $ 
00037  ******************************************************* */
00038 
00040 #ifndef PTester_INC
00041 #define PTester_INC
00042 
00043 #include <plearn/base/Object.h>
00044 #include <plearn/vmat/Splitter.h>
00045 #include <plearn/vmat/VMat.h>
00046 #include <plearn_learners/generic/PLearner.h>
00047 #include <plearn_learners/testers/PerformanceEvaluator.h>
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00052 class PTester: public Object
00053 {    
00054 
00055 private:
00056 
00057     typedef Object inherited;
00058 
00062     TVec<string> statnames;
00063     bool reloaded;
00064 protected:
00065 
00068     TVec<string> statnames_processed;
00069 
00074     bool need_to_save_test_names;
00075 
00077     PStream::mode_t save_mode_;
00078 
00079 public:
00080 
00081     // ************************
00082     // * public build options *
00083     // ************************
00084   
00085     // See declareOptions method in .cc for the role of these options.
00086 
00088     VMat dataset;
00089     PPath expdir;  
00090     TVec<string> final_commands;
00091     PP<VecStatsCollector> global_template_stats_collector;
00092     PP<PLearner> learner;
00093     string save_mode;
00094 
00095     bool provide_learner_expdir;
00096     bool report_stats;
00097     bool save_data_sets;
00098     bool save_initial_learners;
00099     bool save_initial_tester;
00100     bool save_learners;
00101     bool save_stat_collectors;
00102     bool save_split_stats;
00103     bool save_test_costs;
00104     bool save_test_outputs;
00105     bool save_test_names;
00106 
00107     bool call_forget_in_run;
00108     PP<Splitter> splitter;
00109     TVec<TVec<string> > statmask;
00110     PP<VecStatsCollector> template_stats_collector;
00111     typedef map<string, PP<PerformanceEvaluator> > perf_evaluators_t;
00112     perf_evaluators_t perf_evaluators;
00113 
00117     bool save_test_confidence;
00118   
00120     bool should_train;
00121 
00126     bool should_test;
00127 
00129     bool finalize_learner;
00130 
00141     bool enforce_clean_expdir;
00142      
00143     bool redirect_stdout;
00144     bool redirect_stderr;
00145     
00146     bool parallelize_here;
00147     // ****************
00148     // * Constructors *
00149     // ****************
00150 
00151     // Default constructor
00152     PTester();
00153 
00154 
00155     // ******************
00156     // * Object methods *
00157     // ******************
00158 
00159 private: 
00161     // (Please implement in .cc)
00162     void build_();
00163 
00164 protected: 
00166     static void declareOptions(OptionList& ol);
00167 
00169     static void declareMethods(RemoteMethodMap& rmm);
00170 
00173     void computeConfidence(VMat test_set, VMat confidence);
00174 
00175 public:
00176     // simply calls inherited::build() then build_() 
00177     virtual void build();
00178 
00180     PLEARN_DECLARE_OBJECT(PTester);
00181 
00187     void setExperimentDirectory(const PPath& the_expdir);
00188   
00190     PPath getExperimentDirectory() const { return expdir; }
00191 
00192 
00194     TVec<string> getStatNames();
00195 
00199     void setStatNames(const TVec<string>& the_statnames,
00200                       bool call_build = true);
00201 
00203     virtual void run();
00204 
00218     Vec perform(bool call_forget=true);
00219     Vec perform1Split(int splitnum, bool call_forget=true);
00220 
00222     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00223 };
00224 
00225 DECLARE_OBJECT_PTR(PTester);
00226 
00227 
00229 
00230 class StatSpec
00231 {
00232 public:
00233     string extstat;  
00234     string setname;  
00235     int setnum;      
00236 
00239     string intstatname;  
00240 
00241     StatSpec() : setnum(-1) {}
00242 
00243     void init(const string& statname);
00244 
00245     string statName()
00246     { return extstat + "[" + setname + "." + intstatname + "]"; }
00247 
00248 private:
00249 
00251     void parseStatname(const string& statname);
00252 };
00253 
00254 } // end of namespace PLearn
00255 
00256 #endif
00257 
00258 
00259 /*
00260   Local Variables:
00261   mode:c++
00262   c-basic-offset:4
00263   c-file-style:"stroustrup"
00264   c-file-offsets:((innamespace . 0)(inline-open . 0))
00265   indent-tabs-mode:nil
00266   fill-column:79
00267   End:
00268 */
00269 // 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