PLearn 0.1
|
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 10134 2009-04-20 21:32:40Z nouiz $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00043 #ifndef AddCostToLearner_INC 00044 #define AddCostToLearner_INC 00045 00046 #include "EmbeddedLearner.h" 00047 #include "PLearner.h" 00048 #include <plearn/var/VarArray.h> 00049 #include <plearn/var/Var.h> 00050 00051 namespace PLearn { 00052 using namespace std; 00053 00054 class AddCostToLearner: public EmbeddedLearner 00055 { 00056 00057 private: 00058 00059 typedef EmbeddedLearner inherited; 00060 00062 mutable Vec combined_output; 00063 00064 protected: 00065 00066 // ********************* 00067 // * protected options * 00068 // ********************* 00069 00070 // Fields below are not options. 00071 00073 mutable Mat bag_outputs; 00074 00076 mutable int bag_size; 00077 00079 mutable VarArray cross_entropy_prop; 00080 00082 Var cross_entropy_var; 00083 00085 mutable Vec desired_target; 00086 00088 real fac; 00089 00091 real output_max; 00092 real output_min; 00093 00095 Var output_var; 00096 00098 Vec sub_learner_output; 00099 00102 mutable Vec sub_input; 00103 00105 Var target_var; 00106 00108 Vec class_threshold; 00109 00111 real train_time; 00113 real total_train_time; 00114 00116 real test_time; 00118 real total_test_time; 00119 00120 bool train_time_b; 00121 bool test_time_b; 00122 00123 public: 00124 00125 // ************************ 00126 // * public build options * 00127 // ************************ 00128 00129 bool check_output_consistency; 00130 int combine_bag_outputs_method; 00131 bool compute_costs_on_bags; 00132 TVec<string> costs; 00133 bool force_output_to_target_interval; 00134 real from_max; 00135 real from_min; 00136 bool rescale_output; 00137 bool rescale_target; 00138 real to_max; 00139 real to_min; 00140 int n_classes; 00141 int confusion_matrix_target; 00142 bool find_class_threshold; 00143 00144 // **************** 00145 // * Constructors * 00146 // **************** 00147 00148 AddCostToLearner(); 00149 00150 // ****************** 00151 // * PLearner methods * 00152 // ****************** 00153 00154 private: 00155 00157 void build_(); 00158 00159 protected: 00160 00162 static void declareOptions(OptionList& ol); 00163 00164 public: 00165 00166 // ************************ 00167 // **** Object methods **** 00168 // ************************ 00169 00171 virtual void build(); 00172 00174 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00175 00176 // Declares other standard object methods. 00177 PLEARN_DECLARE_OBJECT(AddCostToLearner); 00178 00179 // ************************** 00180 // **** PLearner methods **** 00181 // ************************** 00182 00183 virtual void train(); 00184 00185 virtual void test(VMat testset, PP<VecStatsCollector> test_stats, 00186 VMat testoutputs=0, VMat testcosts=0) const; 00187 00190 virtual void forget(); 00191 00197 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00198 const Vec& target, Vec& costs, 00199 bool add_sub_learner_costs) const; 00200 00202 void computeCostsFromOutputs(const Vec& input, const Vec& output, 00203 const Vec& target, Vec& costs) const{ 00204 computeCostsFromOutputs(input,output,target,costs,true); 00205 } 00206 00208 virtual void computeOutputAndCosts(const Vec& input, const Vec& target, 00209 Vec& output, Vec& costs) const; 00210 00212 virtual void computeOutputsAndCosts(const Mat& input, const Mat& target, 00213 Mat& output, Mat& costs) const; 00214 00216 virtual TVec<string> getTestCostNames() const; 00217 00220 virtual TVec<string> getTrainCostNames() const; 00221 00223 virtual void setTrainingSet(VMat training_set, bool call_forget=true); 00224 00225 }; 00226 00227 // Declares a few other classes and functions related to this class. 00228 DECLARE_OBJECT_PTR(AddCostToLearner); 00229 00230 } // end of namespace PLearn 00231 00232 #endif 00233 00234 00235 /* 00236 Local Variables: 00237 mode:c++ 00238 c-basic-offset:4 00239 c-file-style:"stroustrup" 00240 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00241 indent-tabs-mode:nil 00242 fill-column:79 00243 End: 00244 */ 00245 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :