PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // LinearInductiveTransferClassifier.h 00004 // 00005 // Copyright (C) 2006 Hugo Larochelle 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: .pyskeleton_header 544 2003-09-01 00:05:31Z plearner $ 00037 ******************************************************* */ 00038 00039 // Authors: Hugo Larochelle 00040 00044 #ifndef LinearInductiveTransferClassifier_INC 00045 #define LinearInductiveTransferClassifier_INC 00046 00047 #include <plearn_learners/generic/PLearner.h> 00048 #include <plearn/opt/Optimizer.h> 00049 #include <plearn/var/VarArray.h> 00050 #include <plearn_learners/online/RBMLayer.h> 00051 00052 namespace PLearn { 00053 00058 class LinearInductiveTransferClassifier : public PLearner 00059 { 00060 typedef PLearner inherited; 00061 00062 public: 00063 //##### Public Build Options ############################################ 00064 00066 Mat class_reps; 00068 PP<Optimizer> optimizer; 00070 int batch_size; 00072 real weight_decay; 00074 string penalty_type; 00076 string initialization_method; 00081 string model_type; 00084 bool dont_consider_train_targets; 00086 bool use_bias_in_weights_prediction; 00089 bool multi_target_classifier; 00092 real sigma_min; 00094 int nhidden; 00096 int rbm_nstages; 00098 real rbm_learning_rate; 00100 PP<RBMLayer> visible_layer; 00102 PP<RBMLayer> hidden_layer; 00103 00104 public: 00105 //##### Public Member Functions ######################################### 00106 00108 LinearInductiveTransferClassifier(); 00109 00110 00111 //##### PLearner Member Functions ####################################### 00112 00115 virtual int outputsize() const; 00116 00120 virtual void forget(); 00121 00125 virtual void train(); 00126 00128 virtual void computeOutput(const Vec& input, Vec& output) const; 00129 00131 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00132 const Vec& target, Vec& costs) const; 00133 00136 virtual TVec<std::string> getTestCostNames() const; 00137 00140 virtual TVec<std::string> getTrainCostNames() const; 00141 00142 00143 // *** SUBCLASS WRITING: *** 00144 // While in general not necessary, in case of particular needs 00145 // (efficiency concerns for ex) you may also want to overload 00146 // some of the following methods: 00147 virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const; 00148 // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00149 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const; 00150 // virtual int nTestCosts() const; 00151 // virtual int nTrainCosts() const; 00152 // virtual void resetInternalState(); 00153 // virtual bool isStatefulLearner() const; 00154 00155 00156 //##### PLearn::Object Protocol ######################################### 00157 00158 // Declares other standard object methods. 00159 PLEARN_DECLARE_OBJECT(LinearInductiveTransferClassifier); 00160 00161 // Simply calls inherited::build() then build_() 00162 virtual void build(); 00163 00165 virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies); 00166 00167 protected: 00168 //##### Protected Options ############################################### 00169 00171 int noutputs; 00173 Var input; 00175 Var output; 00177 Var sup_output; 00179 Var new_output; 00181 Var target; 00183 Var sup_target; 00185 Var new_target; 00187 Var sampleweight; 00189 Var A; 00191 Var s; 00193 Var class_reps_var; 00195 VarArray costs; 00197 VarArray new_costs; 00199 VarArray params; 00201 Vec paramsvalues; 00203 VarArray penalties; 00205 Var training_cost; 00207 Var test_costs; 00209 VarArray invars; 00211 Vec seen_targets; 00213 Vec unseen_targets; 00214 00216 mutable Func f; 00218 mutable Func test_costf; 00220 mutable Func output_and_target_to_cost; 00222 mutable Func sup_test_costf; 00224 mutable Func sup_output_and_target_to_cost; 00225 00226 // Neural networks variables 00228 Var W; 00229 // //! Parameters for hidden to output layer weights prediction 00230 // VarArray As; 00231 // //! Parameters for input to hidden layer weights prediction 00232 // VarArray Ws; 00233 // //! Scale parameter for input to hidden layer weights prediction 00234 // VarArray s_hids; 00235 // //! Hidden layer neurons 00236 // VarArray hidden_neurons; 00237 00238 protected: 00239 //##### Protected Member Functions ###################################### 00240 00242 static void declareOptions(OptionList& ol); 00243 00247 Var hiddenLayer(const Var& input, const Var& weights, string transfer_func, Var& before_transfer_function, bool use_cubed_value=false); 00248 00253 void buildOutputFromInput(const Var& the_input, Var& hidden_layer, Var& before_transfer_func); 00254 00256 void buildTargetAndWeight(); 00257 00259 void buildFuncs(const Var& the_input, const Var& the_output, const Var& the_target, const Var& the_sampleweight); 00260 00264 void fillWeights(const Var& weights, bool zero_first_row, 00265 real scale_with_this=-1); 00266 00268 virtual void buildPenalties(); 00269 00270 private: 00271 //##### Private Member Functions ######################################## 00272 00274 void build_(); 00275 00276 private: 00277 //##### Private Data Members ############################################ 00278 00279 // The rest of the private stuff goes here 00280 }; 00281 00282 // Declares a few other classes and functions related to this class 00283 DECLARE_OBJECT_PTR(LinearInductiveTransferClassifier); 00284 00285 } // end of namespace PLearn 00286 00287 #endif 00288 00289 00290 /* 00291 Local Variables: 00292 mode:c++ 00293 c-basic-offset:4 00294 c-file-style:"stroustrup" 00295 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00296 indent-tabs-mode:nil 00297 fill-column:79 00298 End: 00299 */ 00300 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :