00001 // -*- C++ -*- 00002 00003 // TangentLearner.h 00004 // 00005 // Copyright (C) 2004 Martin Monperrus & Yoshua Bengio 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: TangentLearner.h,v 1.10 2004/08/09 23:49:50 yoshua Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Martin Monperrus & Yoshua Bengio 00040 00044 #ifndef TangentLearner_INC 00045 #define TangentLearner_INC 00046 00047 #include <plearn_learners/generic/PLearner.h> 00048 #include <plearn/var/Func.h> 00049 #include <plearn/opt/Optimizer.h> 00050 00051 namespace PLearn { 00052 using namespace std; 00053 00054 class TangentLearner: public PLearner 00055 { 00056 00057 private: 00058 00059 typedef PLearner inherited; 00060 00061 protected: 00062 // NON-OPTION FIELDS 00063 00064 Func cost_of_one_example; 00065 Var b, W, c, V; // explicit view of the parameters (also in parameters field). 00066 Var tangent_targets; // target for the tangent vectors for one example 00067 00068 // ********************* 00069 // * protected options * 00070 // ********************* 00071 00072 // ### declare protected option fields (such as learnt parameters) here 00073 VarArray parameters; 00074 00075 public: 00076 00077 // ************************ 00078 // * public build options * 00079 // ************************ 00080 00081 // ### declare public option fields (such as build options) here 00082 00083 string training_targets; // "local_evectors", "local_neighbors" 00084 bool use_subspace_distance; 00085 bool normalize_by_neighbor_distance; 00086 bool ordered_vectors; 00087 real smart_initialization; 00088 real initialization_regularization; 00089 int n_neighbors; // number of neighbors used in local_pca or number of neighbors to predict 00090 int n_dim; // number of reduced dimensions (number of tangent vectors to compute) 00091 00092 PP<Optimizer> optimizer; // to estimate the function that predicts local tangent vectors given the input 00093 Var embedding; 00094 Func output_f; 00095 Func tangent_predictor; // predicts local tangent vector given the input, and some parameters 00096 Func projection_error_f; // map output to projection error 00097 00098 // manual construction of the tangent_predictor 00099 string architecture_type; // "neural_network" or "linear" or "" or "embedding_neural_nework" or "embedding_quadratic" 00100 string output_type; // "tangent_plane", "embedding", or "tangent_plane+embedding". 00101 int n_hidden_units; 00102 00103 int batch_size; 00104 00105 real norm_penalization; // penalizes sum_i (||f_i||^2-1)^2 00106 real svd_threshold; 00107 real projection_error_regularization; // term to add on linear system diagonal, to solve for subspace fitting 00108 00109 // **************** 00110 // * Constructors * 00111 // **************** 00112 00114 // (Make sure the implementation in the .cc 00115 // initializes all fields to reasonable default values) 00116 TangentLearner(); 00117 00118 00119 // ******************** 00120 // * PLearner methods * 00121 // ******************** 00122 00123 private: 00124 00126 // (Please implement in .cc) 00127 void build_(); 00128 00129 protected: 00130 00132 // (Please implement in .cc) 00133 static void declareOptions(OptionList& ol); 00134 00135 public: 00136 00137 // ************************ 00138 // **** Object methods **** 00139 // ************************ 00140 00142 virtual void build(); 00143 00145 virtual void makeDeepCopyFromShallowCopy(map<const void*, void*>& copies); 00146 00147 // Declares other standard object methods. 00148 // If your class is not instantiatable (it has pure virtual methods) 00149 // you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS. 00150 PLEARN_DECLARE_OBJECT(TangentLearner); 00151 00152 00153 // ************************** 00154 // **** PLearner methods **** 00155 // ************************** 00156 00159 virtual int outputsize() const; 00160 00163 virtual void forget(); 00164 virtual void initializeParams(); 00165 00166 00169 virtual void train(); 00170 00171 00173 // (PLEASE IMPLEMENT IN .cc) 00174 virtual void computeOutput(const Vec& input, Vec& output) const; 00175 00177 // (PLEASE IMPLEMENT IN .cc) 00178 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00179 const Vec& target, Vec& costs) const; 00180 00181 00183 // (PLEASE IMPLEMENT IN .cc) 00184 virtual TVec<string> getTestCostNames() const; 00185 00188 // (PLEASE IMPLEMENT IN .cc) 00189 virtual TVec<string> getTrainCostNames() const; 00190 00191 00192 // *** SUBCLASS WRITING: *** 00193 // While in general not necessary, in case of particular needs 00194 // (efficiency concerns for ex) you may also want to overload 00195 // some of the following methods: 00196 // virtual void computeOutputAndCosts(const Vec& input, const Vec& target, Vec& output, Vec& costs) const; 00197 // virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00198 // virtual void test(VMat testset, PP<VecStatsCollector> test_stats, VMat testoutputs=0, VMat testcosts=0) const; 00199 // virtual int nTestCosts() const; 00200 // virtual int nTrainCosts() const; 00201 00202 }; 00203 00204 // Declares a few other classes and functions related to this class. 00205 DECLARE_OBJECT_PTR(TangentLearner); 00206 00207 } // end of namespace PLearn 00208 00209 #endif