PLearn 0.1
SequentialModelSelector.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // SequentialModelSelector.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_MODEL_SELECTOR
00039 #define SEQUENTIAL_MODEL_SELECTOR
00040 
00041 #include "SequentialLearner.h"
00042 
00043 namespace PLearn {
00044 using namespace std;
00045 
00049 class SequentialModelSelector: public SequentialLearner
00050 {
00051 private:
00052     // *********************
00053     // * private members   *
00054     // *********************
00055     typedef SequentialLearner inherited;
00056 
00058     void build_();
00059 
00060     void checkModelNames() const;
00061 
00062 protected:
00063 
00064     // *********************
00065     // * protected members *
00066     // *********************
00067   
00069     TMat<int> common_cost_indices;
00070     TVec<int> best_model; // best model selected at time t
00071     Vec sequence_costs;  // the costs of each model on the training set
00072 
00080     bool report_paired_T_tests;
00081 
00082     // *********************
00083     // * protected methods *
00084     // *********************
00085   
00087     static void declareOptions(OptionList& ol);
00088   
00089 public:
00090 
00091     // *********************
00092     // * public options    *
00093     // *********************
00094 
00099     bool stepwise_save;
00100 
00102     TVec< PP<SequentialLearner> > models;  
00103 
00105     mutable TVec< string > model_names;
00106 
00112     TVec<string> common_costs;
00113   
00126     int comparison_type;
00127 
00133     int comparison_window;
00134 
00135     // *********************
00136     // * public methods    *
00137     // *********************
00138 
00140     SequentialModelSelector();
00141 
00143     real sequenceCost(const Vec& sequence_errors);
00144   
00146     real paired_t_test(const int& m1, const int& m2, int cc=0) const;
00147 
00149     virtual void build();
00150 
00152     virtual void setExperimentDirectory(const PPath& _expdir);
00153   
00154     virtual void train();
00155  
00156     virtual void test(VMat testset, PP<VecStatsCollector> test_stats,
00157                       VMat testoutputs=0, VMat testcosts=0) const;
00158 
00159     virtual void computeOutput(const Vec& input, Vec& output) const;
00160   
00161     virtual void computeCostsFromOutputs(const Vec& input, const Vec& output,
00162                                          const Vec& target, Vec& costs) const;
00163   
00164     virtual void computeOutputAndCosts(const Vec& input, const Vec& target,
00165                                        Vec& output, Vec& costs) const;
00166   
00167     virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const;
00168 
00169     virtual void matlabSave(const string& matlab_subdir);
00170 
00172     virtual TVec<string> getTestCostNames() const;
00173   
00176     virtual TVec<string> getTrainCostNames() const;
00177 
00178     virtual void forget();
00179   
00182     PLEARN_DECLARE_OBJECT(SequentialModelSelector);
00183     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00184 };
00185 
00187 DECLARE_OBJECT_PTR(SequentialModelSelector);
00188 
00189 } // end of namespace PLearn
00190 
00191 #endif
00192 
00193 
00194 /*
00195   Local Variables:
00196   mode:c++
00197   c-basic-offset:4
00198   c-file-style:"stroustrup"
00199   c-file-offsets:((innamespace . 0)(inline-open . 0))
00200   indent-tabs-mode:nil
00201   fill-column:79
00202   End:
00203 */
00204 // 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