00001 // -*- C++ -*- 00002 00003 // AddCostToLearner.h 00004 // 00005 // Copyright (C) 2004 Olivier Delalleau 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: AddCostToLearner.h,v 1.6 2004/07/21 20:25:38 tihocan Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00043 #ifndef AddCostToLearner_INC 00044 #define AddCostToLearner_INC 00045 00046 #include "PLearner.h" 00047 #include <plearn/var/Var.h> 00048 00049 namespace PLearn { 00050 using namespace std; 00051 00052 class AddCostToLearner: public PLearner 00053 { 00054 00055 private: 00056 00057 typedef PLearner inherited; 00058 00060 mutable Vec combined_output; 00061 00062 protected: 00063 00064 // ********************* 00065 // * protected options * 00066 // ********************* 00067 00068 // Fields below are not options. 00069 00071 mutable Mat bag_outputs; 00072 00074 mutable int bag_size; 00075 00077 mutable VarArray cross_entropy_prop; 00078 00080 Var cross_entropy_var; 00081 00083 Vec desired_target; 00084 00086 real fac; 00087 00089 real output_max; 00090 real output_min; 00091 00093 Var output_var; 00094 00096 Vec sub_learner_output; 00097 00100 mutable Vec sub_input; 00101 00103 Var target_var; 00104 00105 public: 00106 00107 // ************************ 00108 // * public build options * 00109 // ************************ 00110 00111 bool check_output_consistency; 00112 int combine_bag_outputs_method; 00113 bool compute_costs_on_bags; 00114 TVec<string> costs; 00115 bool force_output_to_target_interval; 00116 real from_max; 00117 real from_min; 00118 bool rescale_output; 00119 bool rescale_target; 00120 PP<PLearner> sub_learner; 00121 real to_max; 00122 real to_min; 00123 00124 // **************** 00125 // * Constructors * 00126 // **************** 00127 00128 AddCostToLearner(); 00129 00130 // ****************** 00131 // * PLearner methods * 00132 // ****************** 00133 00134 private: 00135 00137 void build_(); 00138 00139 protected: 00140 00142 static void declareOptions(OptionList& ol); 00143 00144 public: 00145 00146 // ************************ 00147 // **** Object methods **** 00148 // ************************ 00149 00151 virtual void build(); 00152 00154 virtual void makeDeepCopyFromShallowCopy(map<const void*, void*>& copies); 00155 00156 // Declares other standard object methods. 00157 PLEARN_DECLARE_OBJECT(AddCostToLearner); 00158 00159 00160 // ************************** 00161 // **** PLearner methods **** 00162 // ************************** 00163 00166 virtual int outputsize() const; 00167 00170 virtual void forget(); 00171 00174 virtual void train(); 00175 00177 virtual void computeOutput(const Vec& input, Vec& output) const; 00178 00180 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00181 const Vec& target, Vec& costs) const; 00182 00184 virtual TVec<string> getTestCostNames() const; 00185 00188 virtual TVec<string> getTrainCostNames() const; 00189 00191 virtual void setExperimentDirectory(const string& the_expdir) { 00192 sub_learner->setExperimentDirectory(the_expdir); 00193 } 00194 virtual void setTrainingSet(VMat training_set, bool call_forget=true); 00195 virtual void setTrainStatsCollector(PP<VecStatsCollector> statscol) { 00196 sub_learner->setTrainStatsCollector(statscol); 00197 } 00198 00199 }; 00200 00201 // Declares a few other classes and functions related to this class. 00202 DECLARE_OBJECT_PTR(AddCostToLearner); 00203 00204 } // end of namespace PLearn 00205 00206 #endif