PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // RegressionTree.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: RegressionTree.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 RegressionTree_INC 00045 #define RegressionTree_INC 00046 00047 #include <plearn_learners/generic/PLearner.h> 00048 #include "RegressionTreeRegisters.h" 00049 #include "RegressionTreeLeave.h" 00050 namespace PLearn { 00051 using namespace std; 00052 class RegressionTreeQueue; 00053 class RegressionTreeNode; 00054 00055 class RegressionTree: public PLearner 00056 { 00057 friend class RegressionTreeNode; 00058 typedef PLearner inherited; 00059 00060 private: 00061 00062 /* 00063 Build options: they have to be set before training 00064 */ 00065 00066 bool missing_is_valid; 00067 real loss_function_weight; 00068 int maximum_number_of_nodes; 00069 int compute_train_stats; 00070 real complexity_penalty_factor; 00071 Vec multiclass_outputs; 00072 PP<RegressionTreeLeave> leave_template; 00073 PP<RegressionTreeRegisters> sorted_train_set; 00074 static bool output_confidence_target; //to reload old computer 00075 /* 00076 Learnt options: they are sized and initialized if need be, at stage 0 00077 */ 00078 00079 PP<RegressionTreeNode> root; 00080 PP<RegressionTreeLeave> first_leave; 00081 PP<RegressionTreeQueue> priority_queue; 00082 00083 /* 00084 Work fields: they are sized and initialized if need be, at buid time 00085 */ 00086 00087 int length; 00088 real l2_loss_function_factor; 00089 real l1_loss_function_factor; 00090 TVec<int> split_cols; 00091 Vec split_values; 00092 TVec<PP<RegressionTreeNode> > *nodes; 00093 00094 mutable Vec tmp_vec; 00095 mutable Vec tmp_computeCostsFromOutput; 00096 00097 public: 00098 RegressionTree(); 00099 virtual ~RegressionTree(); 00100 00101 PLEARN_DECLARE_OBJECT(RegressionTree); 00102 00103 static void declareOptions(OptionList& ol); 00104 virtual void makeDeepCopyFromShallowCopy(CopiesMap &copies); 00105 virtual void build(); 00106 virtual void train(); 00107 virtual void finalize(); 00108 virtual void forget(); 00109 virtual int outputsize() const {return leave_template->outputsize();} 00110 virtual TVec<string> getTrainCostNames() const; 00111 virtual TVec<string> getTestCostNames() const; 00112 virtual TVec<string> getOutputNames() const; 00113 PP<RegressionTreeRegisters> getSortedTrainingSet() const; 00114 virtual void computeOutput(const Vec& input, Vec& output) const; 00115 virtual void computeOutputAndCosts(const Vec& input, 00116 const Vec& target, 00117 Vec& output, Vec& costs) const; 00118 virtual void computeOutputAndNodes(const Vec& input, Vec& output, 00119 TVec<PP<RegressionTreeNode> >* nodes=0) const; 00120 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, const Vec& target, Vec& costs) const; 00121 virtual void computeCostsFromOutputsAndNodes(const Vec& input, 00122 const Vec& output, 00123 const Vec& target, 00124 const TVec<PP<RegressionTreeNode> >& nodes, 00125 Vec& costs) const; 00126 private: 00127 void build_(); 00128 void initialiseTree(); 00129 PP<RegressionTreeNode> expandTree(); 00130 void verbose(string msg, int level); 00131 }; 00132 00133 DECLARE_OBJECT_PTR(RegressionTree); 00134 00135 } // end of namespace PLearn 00136 00137 #endif 00138 00139 00140 /* 00141 Local Variables: 00142 mode:c++ 00143 c-basic-offset:4 00144 c-file-style:"stroustrup" 00145 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00146 indent-tabs-mode:nil 00147 fill-column:79 00148 End: 00149 */ 00150 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :