PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // EntropyContrastLearner.h 00004 // 00005 // Copyright (C) 2004 Marius Muja 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: EntropyContrastLearner.h 6863 2007-04-09 20:15:52Z saintmlx $ 00037 ******************************************************* */ 00038 00039 // Authors: Marius Muja 00040 00044 #ifndef EntropyContrastLearner_INC 00045 #define EntropyContrastLearner_INC 00046 00047 #include <plearn_learners/generic/PLearner.h> 00048 #include <plearn/opt/Optimizer.h> 00049 #include "plearn/var/Var_all.h" 00050 00051 namespace PLearn { 00052 using namespace std; 00053 00054 class EntropyContrastLearner: public PLearner 00055 { 00056 private: 00057 00058 typedef PLearner inherited; 00059 00060 protected: 00061 00062 // ********************* 00063 // * protected options * 00064 // ********************* 00065 00066 Var x; 00067 Var x_hat; 00068 VarArray V; 00069 VarArray W; 00070 VarArray V_b; 00071 VarArray W_b; 00072 00073 Vec V_save; 00074 Vec V_b_save; 00075 Vec W_save; 00076 Vec W_b_save; 00077 00078 VarArray g; 00079 Var mu, sigma; 00080 Var mu_hat, sigma_hat; 00081 Var training_cost; 00082 VarArray costs; 00083 Var f; 00084 Var f_hat; 00085 00086 VarArray params; 00087 00088 Func f_output; 00089 00090 public: 00091 00092 // ************************ 00093 // * public build options * 00094 // ************************ 00095 00096 string distribution; 00097 int nconstraints; 00098 int nhidden; 00099 PP<Optimizer> optimizer; // the optimizer to use (no default) 00100 real weight_real; 00101 real weight_generated; 00102 real weight_extra; 00103 real weight_decay_hidden; 00104 real weight_decay_output; 00105 bool normalize_constraints; 00106 bool save_best_params; 00107 real sigma_generated; 00108 real sigma_min_threshold; 00109 real eps; 00110 Vec gradient_scaling; 00111 bool save_x_hat; 00112 string gen_method; 00113 bool use_sigma_min_threshold; 00114 00115 // **************** 00116 // * Constructors * 00117 // **************** 00118 00120 // (Make sure the implementation in the .cc 00121 // initializes all fields to reasonable default values) 00122 EntropyContrastLearner(); 00123 00124 00125 // ******************** 00126 // * PLearner methods * 00127 // ******************** 00128 00129 private: 00130 00132 // (Please implement in .cc) 00133 void build_(); 00134 00135 protected: 00136 00138 // (Please implement in .cc) 00139 static void declareOptions(OptionList& ol); 00140 00141 public: 00142 00143 // ************************ 00144 // **** Object methods **** 00145 // ************************ 00146 00148 virtual void build(); 00149 00151 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00152 00153 // Declares other standard object methods. 00154 // If your class is not instantiatable (it has pure virtual methods) 00155 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT. 00156 PLEARN_DECLARE_OBJECT(EntropyContrastLearner); 00157 00158 00159 // ************************** 00160 // **** PLearner methods **** 00161 // ************************** 00162 00163 00164 virtual void initializeParams(); 00165 00168 // (PLEASE IMPLEMENT IN .cc) 00169 virtual int outputsize() const; 00170 00173 // (PLEASE IMPLEMENT IN .cc) 00174 virtual void forget(); 00175 00176 00179 // (PLEASE IMPLEMENT IN .cc) 00180 virtual void train(); 00181 00182 00184 // (PLEASE IMPLEMENT IN .cc) 00185 virtual void computeOutput(const Vec& input, Vec& output) const; 00186 00188 // (PLEASE IMPLEMENT IN .cc) 00189 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00190 const Vec& target, Vec& costs) const; 00191 00192 00194 // (PLEASE IMPLEMENT IN .cc) 00195 virtual TVec<string> getTestCostNames() const; 00196 00199 // (PLEASE IMPLEMENT IN .cc) 00200 virtual TVec<string> getTrainCostNames() const; 00201 00202 00203 // *** SUBCLASS WRITING: *** 00204 // While in general not necessary, in case of particular needs 00205 // (efficiency concerns for ex) you may also want to overload 00206 // some of the following methods: 00207 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const; 00208 // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00209 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const; 00210 // virtual int nTestCosts() const; 00211 // virtual int nTrainCosts() const; 00212 // virtual void resetInternalState(); 00213 // virtual bool isStatefulLearner() const; 00214 00215 }; 00216 00217 // Declares a few other classes and functions related to this class. 00218 DECLARE_OBJECT_PTR(EntropyContrastLearner); 00219 00220 } // end of namespace PLearn 00221 00222 #endif 00223 00224 00225 /* 00226 Local Variables: 00227 mode:c++ 00228 c-basic-offset:4 00229 c-file-style:"stroustrup" 00230 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00231 indent-tabs-mode:nil 00232 fill-column:79 00233 End: 00234 */ 00235 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :