PLearn 0.1
BaseRegressorWrapper.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // BaseRegressorWrapper.h
00004 // Copyright (c) 1998-2002 Pascal Vincent
00005 // Copyright (C) 1999-2002 Yoshua Bengio and University of Montreal
00006 // Copyright (c) 2002 Jean-Sebastien Senecal, Xavier Saint-Mleux, Rejean Ducharme
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  * $Id: BaseRegressorWrapper.h, v 1.0 2004/07/19 10:00:00 Bengio/Kegl/Godbout   *
00039  * This file is part of the PLearn library.                                     *
00040  ******************************************************************************** */
00041 
00044 #ifndef BaseRegressorWrapper_INC
00045 #define BaseRegressorWrapper_INC
00046 
00047 #include <plearn_learners/generic/PLearner.h>
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 class RegressionTree;
00052 class BaseRegressorConfidence;
00053 class RegressionTreeRegisters;
00054 
00055 class BaseRegressorWrapper: public PLearner
00056 {
00057     typedef PLearner inherited;
00058   
00059 private:
00060 
00061 /*
00062   Build options: they have to be set before training
00063 */
00064 
00065     real loss_function_weight;                                // the hyper parameter to balance the error and the confidence factor
00066     int  mean_imputation;                                     // if set to 1, the algorithm will perform mean imputation based on the training set
00067     int regression_tree;                                      // indicator to use the tree_regressor_template is set to 1, and the base_regressor_template otherwise
00068     int use_confidence_function;                              // indicator to use the confidence_function_template to build a confidence estimate
00069     int use_base_regressor_confidence;                        // indicator to use the confidence computed as the second output of the base regressor
00070     PP<PLearner> base_regressor_template;                     // template for a generic regressor as the base learner to be boosted 
00071     PP<RegressionTree> tree_regressor_template;               // template for a tree regressor to be boosted as the base regressor
00072     PP<BaseRegressorConfidence> confidence_function_template; // template for the confidence function to be learnt from the train set 
00073     PP<RegressionTreeRegisters> sorted_train_set;             // a sorted train set when using a regression tree
00074   
00075 /*
00076   Learnt options: they are sized and initialized if need be, at stage 0
00077 */
00078 
00079 
00080     PP<PLearner> base_regressor;                              // base regressors built at each boosting stage 
00081     PP<RegressionTree> tree_regressor;                        // base regressors built at each boosting stage 
00082     PP<BaseRegressorConfidence> confidence_function;          // confidence function learnt from the train set
00083     VMat base_regressor_train_set;                            // a train set with the chosen missing value strategies applied for the base regressor
00084     TVec<real> variable_means;                                // the vector of variable means when doing mean imputation
00085  
00086 /*
00087   Work fields: they are sized and initialized if need be, at buid time
00088 */ 
00089  
00090    
00091   
00092 public:
00093     BaseRegressorWrapper();
00094     virtual              ~BaseRegressorWrapper();
00095     
00096     PLEARN_DECLARE_OBJECT(BaseRegressorWrapper);
00097 
00098     static  void         declareOptions(OptionList& ol);
00099     virtual void         makeDeepCopyFromShallowCopy(CopiesMap &copies);
00100     virtual void         build();
00101     virtual void         train();
00102     virtual void         forget();
00103     virtual int          outputsize() const;
00104     virtual TVec<string> getTrainCostNames() const;
00105     virtual TVec<string> getTestCostNames() const;
00106     virtual void         computeOutput(const Vec& input, Vec& output) const;
00107     virtual void         computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const;
00108     virtual void         computeCostsFromOutputs(const Vec& input, const Vec& output, const Vec& target, Vec& costs) const;
00109     void         setSortedTrainSet(PP<RegressionTreeRegisters> the_sorted_train_set);
00110   
00111 private:
00112     void         build_();
00113     void         verbose(string msg, int level);
00114 };
00115 
00116 DECLARE_OBJECT_PTR(BaseRegressorWrapper);
00117 
00118 } // end of namespace PLearn
00119 
00120 #endif
00121 
00122 
00123 /*
00124   Local Variables:
00125   mode:c++
00126   c-basic-offset:4
00127   c-file-style:"stroustrup"
00128   c-file-offsets:((innamespace . 0)(inline-open . 0))
00129   indent-tabs-mode:nil
00130   fill-column:79
00131   End:
00132 */
00133 // 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